public Object getTransferData(DataFlavor df, DataSource ds) throws UnsupportedFlavorException, IOException { for (DataFlavor f : FLAVORS) { if (f.equals(df)) { return getContent(ds); } } return null; }
public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException { if (obj instanceof Image) { Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(mimeType); if (writers.hasNext()) { ImageWriter writer = writers.next(); BufferedImage bimg = convertToBufferedImage((Image)obj); ImageOutputStream out = ImageIO.createImageOutputStream(os); writer.setOutput(out); writer.write(bimg); writer.dispose(); out.flush(); out.close(); return; } } else if (obj instanceof byte[]) { os.write((byte[])obj); } else if (obj instanceof InputStream) { IOUtils.copyAndCloseInput((InputStream)obj, os); } else if (obj instanceof File) { InputStream file = Files.newInputStream(((File)obj).toPath()); IOUtils.copyAndCloseInput(file, os); } else { throw new IOException("Attachment type not spported " + obj.getClass()); } } private static BufferedImage convertToBufferedImage(Image image) throws IOException {
public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException { if (obj instanceof Image) { Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(mimeType); if (writers.hasNext()) { ImageWriter writer = writers.next(); BufferedImage bimg = convertToBufferedImage((Image)obj); ImageOutputStream out = ImageIO.createImageOutputStream(os); writer.setOutput(out); writer.write(bimg); writer.dispose(); out.flush(); out.close(); return; } } else if (obj instanceof byte[]) { os.write((byte[])obj); } else if (obj instanceof InputStream) { IOUtils.copyAndCloseInput((InputStream)obj, os); } else if (obj instanceof File) { InputStream file = Files.newInputStream(((File)obj).toPath()); IOUtils.copyAndCloseInput(file, os); } else { throw new IOException("Attachment type not spported " + obj.getClass()); } } private static BufferedImage convertToBufferedImage(Image image) throws IOException {
public Object getTransferData(DataFlavor df, DataSource ds) throws UnsupportedFlavorException, IOException { for (DataFlavor f : FLAVORS) { if (f.equals(df)) { return getContent(ds); } } return null; }
public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException { if (obj instanceof Image) { Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(mimeType); if (writers.hasNext()) { ImageWriter writer = writers.next(); BufferedImage bimg = convertToBufferedImage((Image)obj); ImageOutputStream out = ImageIO.createImageOutputStream(os); writer.setOutput(out); writer.write(bimg); writer.dispose(); out.flush(); out.close(); return; } } else if (obj instanceof byte[]) { os.write((byte[])obj); } else if (obj instanceof InputStream) { IOUtils.copyAndCloseInput((InputStream)obj, os); } else if (obj instanceof File) { FileInputStream file = new FileInputStream((File)obj); IOUtils.copyAndCloseInput(file, os); } else { throw new IOException("Attachment type not spported " + obj.getClass()); } } private static BufferedImage convertToBufferedImage(Image image) throws IOException {
public Object getTransferData(DataFlavor df, DataSource ds) throws UnsupportedFlavorException, IOException { for (DataFlavor f : FLAVORS) { if (f.equals(df)) { return getContent(ds); } } return null; }
public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException { if (obj instanceof Image) { Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(mimeType); if (writers.hasNext()) { ImageWriter writer = writers.next(); BufferedImage bimg = convertToBufferedImage((Image)obj); ImageOutputStream out = ImageIO.createImageOutputStream(os); writer.setOutput(out); writer.write(bimg); writer.dispose(); out.flush(); out.close(); return; } } else if (obj instanceof byte[]) { os.write((byte[])obj); } else if (obj instanceof InputStream) { IOUtils.copyAndCloseInput((InputStream)obj, os); } else if (obj instanceof File) { FileInputStream file = new FileInputStream((File)obj); IOUtils.copyAndCloseInput(file, os); } else { throw new IOException("Attachment type not spported " + obj.getClass()); } } private static BufferedImage convertToBufferedImage(Image image) throws IOException {
public Object getTransferData(DataFlavor df, DataSource ds) throws UnsupportedFlavorException, IOException { for (DataFlavor f : FLAVORS) { if (f.equals(df)) { return getContent(ds); } } return null; }