diff options
author | jonmv <venstad@gmail.com> | 2022-11-07 15:20:12 +0100 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2022-11-07 15:20:12 +0100 |
commit | 4a6f833f3265a955c1a9d793fdb2ebb9eb8e0dd0 (patch) | |
tree | 231cc7ea990f1b003ccd523ab4202917a66e4954 /hosted-api | |
parent | 54eb99038030a5eee2cbc16fbda76c0375bcc52c (diff) |
Revert "Merge pull request #24781 from vespa-engine/revert-24777-jonmv/reapply-app-streams"
This reverts commit adc1c1fa16945d9f29778706f5bf8161434c2361, reversing
changes made to a0e9b51aaf01a425dbd6cdd1fbc8fd5ce066a9bb.
Diffstat (limited to 'hosted-api')
-rw-r--r-- | hosted-api/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/hosted-api/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java b/hosted-api/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java index f1cbc027e17..b3862b76296 100644 --- a/hosted-api/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java +++ b/hosted-api/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java @@ -15,6 +15,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; +import java.util.Enumeration; import java.util.List; import java.util.UUID; import java.util.function.Supplier; @@ -89,10 +90,12 @@ public class MultiPartStreamer { /** Returns an input stream which is an aggregate of all current parts in this, plus an end marker. */ public InputStream data() { - InputStream aggregate = new SequenceInputStream(Collections.enumeration(Stream.concat(streams.stream().map(Supplier::get), - Stream.of(end())) - .collect(Collectors.toList()))); - + InputStream aggregate = new SequenceInputStream(new Enumeration<>() { + final int j = streams.size(); + int i = -1; + @Override public boolean hasMoreElements() { return i < j; } + @Override public InputStream nextElement() { return ++i < j ? streams.get(i).get() : i == j ? end() : null; } + }); try { if (aggregate.skip(2) != 2)// This should never happen, as the first stream is a ByteArrayInputStream. throw new IllegalStateException("Failed skipping extraneous bytes."); @@ -113,17 +116,6 @@ public class MultiPartStreamer { return asStream(disposition(name) + (filename == null ? "" : "; filename=\"" + filename + "\"") + type(contentType)); } - /** Returns the separator to put between one part and the next, when this is a file. */ - private InputStream separator(String name, Path path) { - try { - String contentType = Files.probeContentType(path); - return separator(name, path.getFileName().toString(), contentType != null ? contentType : "application/octet-stream"); - } - catch (IOException e) { - throw new UncheckedIOException(e); - } - } - /** Returns the end delimiter of the request, with line breaks prepended. */ private InputStream end() { return asStream("\r\n--" + boundary + "--"); @@ -140,7 +132,7 @@ public class MultiPartStreamer { return "\r\nContent-Type: " + contentType + "\r\n\r\n"; } - /** Returns the a ByteArrayInputStream over the given string, UTF-8 encoded. */ + /** Returns a ByteArrayInputStream over the given string, UTF-8 encoded. */ private static InputStream asStream(String string) { return new ByteArrayInputStream(string.getBytes(StandardCharsets.UTF_8)); } |