diff options
author | Jon Marius Venstad <jonmv@users.noreply.github.com> | 2022-05-02 21:08:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-02 21:08:17 +0200 |
commit | 6058f5f8d2ed19ca3c0461e7080680a093834823 (patch) | |
tree | 3e09032c623789406abfa2d42ea74b7064cb7087 /hosted-api | |
parent | 04898b34190a3e3bb9d3053e11eb892bc48ff842 (diff) |
Revert "Jonmv/remove last controller jersey client [run-systemtest]"
Diffstat (limited to 'hosted-api')
-rw-r--r-- | hosted-api/src/main/java/ai/vespa/hosted/api/MultiPartStreamer.java | 29 |
1 files changed, 14 insertions, 15 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 8c858437ad7..f155cbbce07 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 @@ -1,8 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package ai.vespa.hosted.api; -import com.yahoo.yolean.Exceptions; - import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -53,26 +51,26 @@ public class MultiPartStreamer { /** Adds the given data as a named part in this, using the given content type. */ public MultiPartStreamer addData(String name, String type, String data) { - return addData(name, type, null, () -> asStream(data)); + streams.add(() -> separator(name, type)); + streams.add(() -> asStream(data)); + + return this; } /** Adds the given data as a named part in this, using the {@code "application/octet-stream" content type}. */ public MultiPartStreamer addBytes(String name, byte[] bytes) { - return addData(name, "application/octet-stream", null, () -> new ByteArrayInputStream(bytes)); - } - - /** Adds the given data as a named part in this, using the given content type. */ - public MultiPartStreamer addData(String name, String type, String filename, Supplier<InputStream> data) { - streams.add(() -> separator(name, filename, type)); - streams.add(data); + streams.add(() -> separator(name, "application/octet-stream")); + streams.add(() -> new ByteArrayInputStream(bytes)); return this; } /** Adds the contents of the file at the given path as a named part in this. */ public MultiPartStreamer addFile(String name, Path path) { - String type = Exceptions.uncheck(() -> Files.probeContentType(path)); - return addData(name, type != null ? type : "application/octet-stream", path.getFileName().toString(), () -> asStream(path)); + streams.add(() -> separator(name, path)); + streams.add(() -> asStream(path)); + + return this; } /** @@ -109,15 +107,16 @@ public class MultiPartStreamer { } /** Returns the separator to put between one part and the next, when this is a string. */ - private InputStream separator(String name, String filename, String contentType) { - return asStream(disposition(name) + (filename == null ? "" : "; filename=\"" + filename + "\"") + type(contentType)); + private InputStream separator(String name, String contentType) { + return asStream(disposition(name) + 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"); + return asStream(disposition(name) + "; filename=\"" + path.getFileName() + "\"" + + type(contentType != null ? contentType : "application/octet-stream")); } catch (IOException e) { throw new UncheckedIOException(e); |