From: AsamK Date: Thu, 10 Dec 2015 20:42:44 +0000 (+0100) Subject: Extract getTextSecureAttachments method X-Git-Tag: v0.2.0~16 X-Git-Url: https://git.nmode.ca/signal-cli/commitdiff_plain/4b5bfcba8001d23768ad1131b76eaf6325d260d4?hp=c1abc12907167618c58282daf5315c5c694a8136 Extract getTextSecureAttachments method --- diff --git a/src/main/java/cli/Main.java b/src/main/java/cli/Main.java index 43535749..08c7b935 100644 --- a/src/main/java/cli/Main.java +++ b/src/main/java/cli/Main.java @@ -119,19 +119,13 @@ public class Main { if (ns.getBoolean("endsession")) { sendEndSessionMessage(m, recipients); } else { - final List attachments = ns.getList("attachment"); List textSecureAttachments = null; - if (attachments != null) { - textSecureAttachments = new ArrayList<>(attachments.size()); - for (String attachment : attachments) { - try { - textSecureAttachments.add(createAttachment(attachment)); - } catch (IOException e) { - System.err.println("Failed to add attachment \"" + attachment + "\": " + e.getMessage()); - System.err.println("Aborting sending."); - System.exit(1); - } - } + try { + textSecureAttachments = getTextSecureAttachments(ns.getList("attachment")); + } catch (IOException e) { + System.err.println("Failed to add attachment: " + e.getMessage()); + System.err.println("Aborting sending."); + System.exit(1); } String messageText = ns.getString("message"); @@ -270,6 +264,18 @@ public class Main { System.exit(0); } + private static List getTextSecureAttachments(List attachments) { + private static List getTextSecureAttachments(List attachments) throws IOException { + List textSecureAttachments = null; + if (attachments != null) { + textSecureAttachments = new ArrayList<>(attachments.size()); + for (String attachment : attachments) { + textSecureAttachments.add(createAttachment(attachment)); + } + } + return textSecureAttachments; + } + private static TextSecureAttachmentStream createAttachment(String attachment) throws IOException { File attachmentFile = new File(attachment); InputStream attachmentStream = new FileInputStream(attachmentFile);