Use pattern matching switch cases

This commit is contained in:
AsamK 2023-10-17 19:52:35 +02:00
parent 80c1a6d2af
commit 8d55dfb66b
27 changed files with 395 additions and 380 deletions

View file

@ -42,10 +42,9 @@ public class GetAttachmentCommand implements JsonRpcLocalCommand {
try (InputStream attachment = m.retrieveAttachment(id)) {
final var bytes = attachment.readAllBytes();
final var base64 = Base64.getEncoder().encodeToString(bytes);
if (outputWriter instanceof PlainTextWriter writer) {
writer.println(base64);
} else if (outputWriter instanceof JsonWriter writer) {
writer.write(new JsonAttachmentData(base64));
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);