private void fetch() throws IOException { if (getAttachmentUrl() != null && (!getAttachmentUrl().isEmpty())) { InputStream input = null; ByteArrayOutputStream output = null; try { URL url = new URL(getAttachmentUrl()); input = url.openStream(); output = new ByteArrayOutputStream(); int i; while ((i = input.read()) != -1) { output.write(i); } this.data = output.toByteArray(); } finally { if (input != null) { input.close(); } if (output != null) { output.close(); } } } } }
public void testAttachmentSerialization() { convertBackAndForth("<image attachment=\"id\"></image>"); convertBackAndForth("<image attachment=\"id\"><caption>caption</caption></image>"); Element element = createApiElementFromXml( "<image attachment=\"id\"><gadge>something</gadge>" + "<caption>caption</caption><fake>fake</fake></image>", createWavelet("id")); assertTrue(element instanceof Attachment); assertEquals("caption", ((Attachment) element).getCaption()); assertEquals("id", ((Attachment) element).getAttachmentId()); assertEquals(ATTACHMENT_MIMETYPE, ((Attachment) element).getMimeType()); assertEquals(ATTACHMENT_URL, ((Attachment) element).getAttachmentUrl()); }
public void testAttachmentSerialization() { convertBackAndForth("<image attachment=\"id\"></image>"); convertBackAndForth("<image attachment=\"id\"><caption>caption</caption></image>"); Element element = createApiElementFromXml( "<image attachment=\"id\"><gadge>something</gadge>" + "<caption>caption</caption><fake>fake</fake></image>", createWavelet("id")); assertTrue(element instanceof Attachment); assertEquals("caption", ((Attachment) element).getCaption()); assertEquals("id", ((Attachment) element).getAttachmentId()); assertEquals(ATTACHMENT_MIMETYPE, ((Attachment) element).getMimeType()); assertEquals(ATTACHMENT_URL, ((Attachment) element).getAttachmentUrl()); }