@Override
public void attachToSubparser(final Subparser subparser) {
+ subparser.help("Retrieve an already downloaded attachment base64 encoded.");
subparser.addArgument("--id").required(true).help("The ID of the attachment file.");
var mut = subparser.addMutuallyExclusiveGroup().required(true);
mut.addArgument("--recipient").help("Sender of the attachment");
@Override
public void handleCommand(
- final Namespace ns, final Manager m, final OutputWriter outputWriter
+ final Namespace ns,
+ final Manager m,
+ final OutputWriter outputWriter
) throws CommandException {
final var id = ns.getString("id");
try (InputStream attachment = m.retrieveAttachment(id)) {
- 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));
+ final var bytes = attachment.readAllBytes();
+ final var base64 = Base64.getEncoder().encodeToString(bytes);
+ switch (outputWriter) {
+ case PlainTextWriter writer -> writer.println(base64);
+ case JsonWriter writer -> writer.write(new JsonAttachmentData(base64));
}
} catch (FileNotFoundException ex) {
throw new UserErrorException("Could not find attachment with ID: " + id, ex);