public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { final ActivationDataFlavor dataFlavor = (ActivationDataFlavor)source; final String mimeType = dataFlavor.getMimeType(); if (mimeType != null) { writer.startNode("mimeType"); writer.setValue(mimeType); writer.endNode(); } final String name = dataFlavor.getHumanPresentableName(); if (name != null) { writer.startNode("humanRepresentableName"); writer.setValue(name); writer.endNode(); } final Class representationClass = dataFlavor.getRepresentationClass(); if (representationClass != null) { writer.startNode("representationClass"); context.convertAnother(representationClass); writer.endNode(); } }
/** * Write the object to the output stream, using the specified MIME type. */ public void writeTo(Object obj, String type, OutputStream os) throws IOException { if (!(obj instanceof Image)) throw new IOException("\"" + getDataFlavors()[0].getMimeType() + "\" DataContentHandler requires Image object, " + "was given object of type " + obj.getClass().toString()); throw new IOException(getDataFlavors()[0].getMimeType() + " encoding not supported"); } }
/** * Write the object to the output stream, using the specified MIME type. */ @Override public void writeTo(Object obj, String type, OutputStream os) throws IOException { if (!(obj instanceof Image)) throw new IOException("\"" + getDataFlavors()[0].getMimeType() + "\" DataContentHandler requires Image object, " + "was given object of type " + obj.getClass().toString()); throw new IOException(getDataFlavors()[0].getMimeType() + " encoding not supported"); } }
throws IOException { if (!(obj instanceof String)) throw new IOException("\"" + getDataFlavors()[0].getMimeType() + "\" DataContentHandler requires String object, " + "was given object of type " + obj.getClass().toString());
throws IOException { if (!(obj instanceof String)) throw new IOException("\"" + getDataFlavors()[0].getMimeType() + "\" DataContentHandler requires String object, " + "was given object of type " + obj.getClass().toString());
/** * Write the object to the output stream, using the specified MIME type. */ public void writeTo(Object obj, String type, OutputStream os) throws IOException { if (!(obj instanceof Image)) throw new IOException("\"" + getDF().getMimeType() + "\" DataContentHandler requires Image object, " + "was given object of type " + obj.getClass().toString()); throw new IOException(getDF().getMimeType() + " encoding not supported"); } }
/** * Write the object to the output stream, using the specified MIME type. */ public void writeTo(Object obj, String type, OutputStream os) throws IOException { if (!(obj instanceof Image)) throw new IOException("\"" + getDF().getMimeType() + "\" DataContentHandler requires Image object, " + "was given object of type " + obj.getClass().toString()); throw new IOException(getDF().getMimeType() + " encoding not supported"); } }
/** * Write the object to the output stream, using the specified MIME type. */ @Override public void writeTo(Object obj, String type, OutputStream os) throws IOException { if (!(obj instanceof Image)) throw new IOException("\"" + getDataFlavors()[0].getMimeType() + "\" DataContentHandler requires Image object, " + "was given object of type " + obj.getClass().toString()); throw new IOException(getDataFlavors()[0].getMimeType() + " encoding not supported"); } }
/** * Write the object to the output stream, using the specified MIME type. */ @Override public void writeTo(Object obj, String type, OutputStream os) throws IOException { if (!(obj instanceof Image)) throw new IOException("\"" + getDataFlavors()[0].getMimeType() + "\" DataContentHandler requires Image object, " + "was given object of type " + obj.getClass().toString()); throw new IOException(getDataFlavors()[0].getMimeType() + " encoding not supported"); } }
/** * Write the object to the output stream, using the specified MIME type. */ @Override public void writeTo(Object obj, String type, OutputStream os) throws IOException { if (!(obj instanceof Image)) throw new IOException("\"" + getDataFlavors()[0].getMimeType() + "\" DataContentHandler requires Image object, " + "was given object of type " + obj.getClass().toString()); throw new IOException(getDataFlavors()[0].getMimeType() + " encoding not supported"); } }
/** * Write the object to the output stream, using the specified MIME type. */ @Override public void writeTo(Object obj, String type, OutputStream os) throws IOException { if (!(obj instanceof Image)) throw new IOException("\"" + getDataFlavors()[0].getMimeType() + "\" DataContentHandler requires Image object, " + "was given object of type " + obj.getClass().toString()); throw new IOException(getDataFlavors()[0].getMimeType() + " encoding not supported"); } }
public Object getContent(DataSource ds) throws IOException { Iterator i = ImageIO.getImageReadersByMIMEType(flavour.getMimeType()); if (!i.hasNext()) { throw new UnsupportedDataTypeException("Unknown image type " + flavour.getMimeType()); } ImageReader reader = (ImageReader) i.next(); ImageInputStream iis = ImageIO.createImageInputStream(ds.getInputStream()); reader.setInput(iis); return reader.read(0); }
@Override public void writeTo(Object aPart, String aMimeType, OutputStream aStream) throws IOException { if (!(aPart instanceof String)) { throw new IOException("Type \"" + aPart.getClass().getName() + "\" is not supported."); } String encoding = getCharacterSet(getDataFlavor().getMimeType()); Writer writer; try { writer = new BufferedWriter(new OutputStreamWriter(aStream, encoding), 2048); } catch (IllegalArgumentException e) { throw new UnsupportedEncodingException(encoding); } writer.write((String) aPart); writer.flush(); }
public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException { Iterator i = ImageIO.getImageWritersByMIMEType(flavour.getMimeType()); if (!i.hasNext()) { throw new UnsupportedDataTypeException("Unknown image type " + flavour.getMimeType()); } ImageWriter writer = (ImageWriter) i.next(); writer.setOutput(ImageIO.createImageOutputStream(os)); if (obj instanceof RenderedImage) { writer.write((RenderedImage) obj); } else if (obj instanceof BufferedImage) { BufferedImage buffered = (BufferedImage) obj; writer.write(new IIOImage(buffered.getRaster(), null, null)); } else if (obj instanceof Image) { Image image = (Image) obj; BufferedImage buffered = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = buffered.createGraphics(); graphics.drawImage(image, 0, 0, null, null); writer.write(new IIOImage(buffered.getRaster(), null, null)); } else { throw new UnsupportedDataTypeException("Unknown image type " + obj.getClass().getName()); } os.flush(); } }
/** * Write the object to the output stream, using the specified MIME type. */ public void writeTo(Object obj, String type, OutputStream os) throws IOException { if (!(obj instanceof String)) throw new IOException("\"" + getDF().getMimeType() + "\" DataContentHandler requires String object, " + "was given object of type " + obj.getClass().toString()); String enc = null; OutputStreamWriter osw; try { enc = getCharset(type); osw = new OutputStreamWriter(os, enc); } catch (IllegalArgumentException iex) { /* * An unknown charset of the form ISO-XXX-XXX will cause * the JDK to throw an IllegalArgumentException. The * JDK will attempt to create a classname using this string, * but valid classnames must not contain the character '-', * and this results in an IllegalArgumentException, rather than * the expected UnsupportedEncodingException. Yikes. */ throw new UnsupportedEncodingException(enc); } String s = (String) obj; osw.write(s, 0, s.length()); osw.flush(); }
/** * Write the object to the output stream, using the specified MIME type. */ public void writeTo(Object obj, String type, OutputStream os) throws IOException { if (!(obj instanceof String)) throw new IOException("\"" + getDF().getMimeType() + "\" DataContentHandler requires String object, " + "was given object of type " + obj.getClass().toString()); String enc = null; OutputStreamWriter osw = null; try { enc = getCharset(type); osw = new OutputStreamWriter(os, enc); } catch (IllegalArgumentException iex) { /* * An unknown charset of the form ISO-XXX-XXX will cause * the JDK to throw an IllegalArgumentException. The * JDK will attempt to create a classname using this string, * but valid classnames must not contain the character '-', * and this results in an IllegalArgumentException, rather than * the expected UnsupportedEncodingException. Yikes. */ throw new UnsupportedEncodingException(enc); } String s = (String)obj; osw.write(s, 0, s.length()); osw.flush(); }
@Override public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { final ActivationDataFlavor dataFlavor = ActivationDataFlavor.class.cast(source); final String mimeType = dataFlavor.getMimeType(); if (mimeType != null) { writer.startNode("mimeType"); writer.setValue(mimeType); writer.endNode(); } final String name = dataFlavor.getHumanPresentableName(); if (name != null) { writer.startNode("humanRepresentableName"); writer.setValue(name); writer.endNode(); } final Class<?> representationClass = dataFlavor.getRepresentationClass(); if (representationClass != null) { writer.startNode("representationClass"); context.convertAnother(representationClass); writer.endNode(); } }
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { final ActivationDataFlavor dataFlavor = (ActivationDataFlavor)source; final String mimeType = dataFlavor.getMimeType(); if (mimeType != null) { writer.startNode("mimeType"); writer.setValue(mimeType); writer.endNode(); } final String name = dataFlavor.getHumanPresentableName(); if (name != null) { writer.startNode("humanRepresentableName"); writer.setValue(name); writer.endNode(); } final Class representationClass = dataFlavor.getRepresentationClass(); if (representationClass != null) { writer.startNode("representationClass"); context.convertAnother(representationClass); writer.endNode(); } }
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { final ActivationDataFlavor dataFlavor = (ActivationDataFlavor)source; final String mimeType = dataFlavor.getMimeType(); if (mimeType != null) { writer.startNode("mimeType"); writer.setValue(mimeType); writer.endNode(); } final String name = dataFlavor.getHumanPresentableName(); if (name != null) { writer.startNode("humanRepresentableName"); writer.setValue(name); writer.endNode(); } final Class representationClass = dataFlavor.getRepresentationClass(); if (representationClass != null) { writer.startNode("representationClass"); context.convertAnother(representationClass); writer.endNode(); } }
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) { final ActivationDataFlavor dataFlavor = (ActivationDataFlavor)source; final String mimeType = dataFlavor.getMimeType(); if (mimeType != null) { writer.startNode("mimeType"); writer.setValue(mimeType); writer.endNode(); } final String name = dataFlavor.getHumanPresentableName(); if (name != null) { writer.startNode("humanRepresentableName"); writer.setValue(name); writer.endNode(); } final Class representationClass = dataFlavor.getRepresentationClass(); if (representationClass != null) { writer.startNode("representationClass"); context.convertAnother(representationClass); writer.endNode(); } }