diff --git a/src/main/java/org/asamk/signal/commands/GetAttachmentCommand.java b/src/main/java/org/asamk/signal/commands/GetAttachmentCommand.java index 6deed90a..f2f0450c 100644 --- a/src/main/java/org/asamk/signal/commands/GetAttachmentCommand.java +++ b/src/main/java/org/asamk/signal/commands/GetAttachmentCommand.java @@ -40,12 +40,12 @@ public class GetAttachmentCommand implements JsonRpcLocalCommand { final var id = ns.getString("id"); try (InputStream attachment = m.retrieveAttachment(id)) { + final var bytes = attachment.readAllBytes(); + final var base64 = Base64.getEncoder().encodeToString(bytes); if (outputWriter instanceof PlainTextWriter writer) { - final var bytes = attachment.readAllBytes(); - final var base64 = Base64.getEncoder().encodeToString(bytes); writer.println(base64); } else if (outputWriter instanceof JsonWriter writer) { - writer.write(new JsonAttachmentData(attachment)); + writer.write(new JsonAttachmentData(base64)); } } catch (FileNotFoundException ex) { throw new UserErrorException("Could not find attachment with ID: " + id, ex); diff --git a/src/main/java/org/asamk/signal/json/JsonAttachmentData.java b/src/main/java/org/asamk/signal/json/JsonAttachmentData.java index fd759674..05a90c21 100644 --- a/src/main/java/org/asamk/signal/json/JsonAttachmentData.java +++ b/src/main/java/org/asamk/signal/json/JsonAttachmentData.java @@ -1,9 +1,5 @@ package org.asamk.signal.json; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -import java.io.InputStream; - public record JsonAttachmentData( - @JsonSerialize(using = JsonStreamSerializer.class) InputStream data + String data ) {} diff --git a/src/main/java/org/asamk/signal/json/JsonStreamSerializer.java b/src/main/java/org/asamk/signal/json/JsonStreamSerializer.java deleted file mode 100644 index 4cd2797e..00000000 --- a/src/main/java/org/asamk/signal/json/JsonStreamSerializer.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.asamk.signal.json; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; - -import java.io.IOException; -import java.io.InputStream; - -public class JsonStreamSerializer extends JsonSerializer { - - @Override - public void serialize( - final InputStream value, final JsonGenerator jsonGenerator, final SerializerProvider serializers - ) throws IOException { - jsonGenerator.writeBinary(value, -1); - } -}