Java Code Examples for javax.imageio.ImageIO#getImageWritersByMIMEType()
The following examples show how to use
javax.imageio.ImageIO#getImageWritersByMIMEType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GetReaderWriterInfo.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void testGetWriterMIMETypes() { String[] types = ImageIO.getWriterMIMETypes(); for (String t : types) { Iterator<ImageWriter> it = ImageIO.getImageWritersByMIMEType(t); if (!it.hasNext()) { throw new RuntimeException("getWriterMIMETypes returned " + "an unknown type: " + t); } } }
Example 2
Source File: BufferedImageHttpMessageConverter.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void writeInternal(BufferedImage image, MediaType contentType, HttpHeaders headers, OutputStream body) throws IOException, HttpMessageNotWritableException { if (contentType == null || contentType.isWildcardType() || contentType.isWildcardSubtype()) { contentType = getDefaultContentType(); } Assert.notNull(contentType, "Count not determine Content-Type, set one using the 'defaultContentType' property"); headers.setContentType(contentType); ImageOutputStream imageOutputStream = null; ImageWriter imageWriter = null; try { Iterator<ImageWriter> imageWriters = ImageIO.getImageWritersByMIMEType(contentType.toString()); if (imageWriters.hasNext()) { imageWriter = imageWriters.next(); ImageWriteParam iwp = imageWriter.getDefaultWriteParam(); process(iwp); imageOutputStream = createImageOutputStream(body); imageWriter.setOutput(imageOutputStream); imageWriter.write(null, new IIOImage(image, null, null), iwp); } else { throw new HttpMessageNotWritableException( "Could not find javax.imageio.ImageWriter for Content-Type [" + contentType + "]"); } } finally { if (imageWriter != null) { imageWriter.dispose(); } if (imageOutputStream != null) { try { imageOutputStream.close(); } catch (IOException ex) { // ignore } } } }
Example 3
Source File: RuntimeBuiltinLeafInfoImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public Base64Data print(Image v) { ByteArrayOutputStreamEx imageData = new ByteArrayOutputStreamEx(); XMLSerializer xs = XMLSerializer.getInstance(); String mimeType = xs.getXMIMEContentType(); if(mimeType==null || mimeType.startsWith("image/*")) // because PNG is lossless, it's a good default // // mime type can be a range, in which case we can't just pass that // to ImageIO.getImageWritersByMIMEType, so here I'm just assuming // the default of PNG. Not sure if this is complete. mimeType = "image/png"; try { Iterator<ImageWriter> itr = ImageIO.getImageWritersByMIMEType(mimeType); if(itr.hasNext()) { ImageWriter w = itr.next(); ImageOutputStream os = ImageIO.createImageOutputStream(imageData); w.setOutput(os); w.write(convertToBufferedImage(v)); os.close(); w.dispose(); } else { // no encoder xs.handleEvent(new ValidationEventImpl( ValidationEvent.ERROR, Messages.NO_IMAGE_WRITER.format(mimeType), xs.getCurrentLocation(null) )); // TODO: proper error reporting throw new RuntimeException("no encoder for MIME type "+mimeType); } } catch (IOException e) { xs.handleError(e); // TODO: proper error reporting throw new RuntimeException(e); } Base64Data bd = new Base64Data(); imageData.set(bd,mimeType); return bd; }
Example 4
Source File: RuntimeBuiltinLeafInfoImpl.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public Base64Data print(Image v) { ByteArrayOutputStreamEx imageData = new ByteArrayOutputStreamEx(); XMLSerializer xs = XMLSerializer.getInstance(); String mimeType = xs.getXMIMEContentType(); if(mimeType==null || mimeType.startsWith("image/*")) // because PNG is lossless, it's a good default // // mime type can be a range, in which case we can't just pass that // to ImageIO.getImageWritersByMIMEType, so here I'm just assuming // the default of PNG. Not sure if this is complete. mimeType = "image/png"; try { Iterator<ImageWriter> itr = ImageIO.getImageWritersByMIMEType(mimeType); if(itr.hasNext()) { ImageWriter w = itr.next(); ImageOutputStream os = ImageIO.createImageOutputStream(imageData); w.setOutput(os); w.write(convertToBufferedImage(v)); os.close(); w.dispose(); } else { // no encoder xs.handleEvent(new ValidationEventImpl( ValidationEvent.ERROR, Messages.NO_IMAGE_WRITER.format(mimeType), xs.getCurrentLocation(null) )); // TODO: proper error reporting throw new RuntimeException("no encoder for MIME type "+mimeType); } } catch (IOException e) { xs.handleError(e); // TODO: proper error reporting throw new RuntimeException(e); } Base64Data bd = new Base64Data(); imageData.set(bd,mimeType); return bd; }
Example 5
Source File: RuntimeBuiltinLeafInfoImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public Base64Data print(Image v) { ByteArrayOutputStreamEx imageData = new ByteArrayOutputStreamEx(); XMLSerializer xs = XMLSerializer.getInstance(); String mimeType = xs.getXMIMEContentType(); if(mimeType==null || mimeType.startsWith("image/*")) // because PNG is lossless, it's a good default // // mime type can be a range, in which case we can't just pass that // to ImageIO.getImageWritersByMIMEType, so here I'm just assuming // the default of PNG. Not sure if this is complete. mimeType = "image/png"; try { Iterator<ImageWriter> itr = ImageIO.getImageWritersByMIMEType(mimeType); if(itr.hasNext()) { ImageWriter w = itr.next(); ImageOutputStream os = ImageIO.createImageOutputStream(imageData); w.setOutput(os); w.write(convertToBufferedImage(v)); os.close(); w.dispose(); } else { // no encoder xs.handleEvent(new ValidationEventImpl( ValidationEvent.ERROR, Messages.NO_IMAGE_WRITER.format(mimeType), xs.getCurrentLocation(null) )); // TODO: proper error reporting throw new RuntimeException("no encoder for MIME type "+mimeType); } } catch (IOException e) { xs.handleError(e); // TODO: proper error reporting throw new RuntimeException(e); } Base64Data bd = new Base64Data(); imageData.set(bd,mimeType); return bd; }
Example 6
Source File: BufferedImageHttpMessageConverter.java From java-technology-stack with MIT License | 5 votes |
private boolean isWritable(@Nullable MediaType mediaType) { if (mediaType == null || MediaType.ALL.equalsTypeAndSubtype(mediaType)) { return true; } Iterator<ImageWriter> imageWriters = ImageIO.getImageWritersByMIMEType(mediaType.toString()); return imageWriters.hasNext(); }
Example 7
Source File: RuntimeBuiltinLeafInfoImpl.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public Base64Data print(Image v) { ByteArrayOutputStreamEx imageData = new ByteArrayOutputStreamEx(); XMLSerializer xs = XMLSerializer.getInstance(); String mimeType = xs.getXMIMEContentType(); if(mimeType==null || mimeType.startsWith("image/*")) // because PNG is lossless, it's a good default // // mime type can be a range, in which case we can't just pass that // to ImageIO.getImageWritersByMIMEType, so here I'm just assuming // the default of PNG. Not sure if this is complete. mimeType = "image/png"; try { Iterator<ImageWriter> itr = ImageIO.getImageWritersByMIMEType(mimeType); if(itr.hasNext()) { ImageWriter w = itr.next(); ImageOutputStream os = ImageIO.createImageOutputStream(imageData); w.setOutput(os); w.write(convertToBufferedImage(v)); os.close(); w.dispose(); } else { // no encoder xs.handleEvent(new ValidationEventImpl( ValidationEvent.ERROR, Messages.NO_IMAGE_WRITER.format(mimeType), xs.getCurrentLocation(null) )); // TODO: proper error reporting throw new RuntimeException("no encoder for MIME type "+mimeType); } } catch (IOException e) { xs.handleError(e); // TODO: proper error reporting throw new RuntimeException(e); } Base64Data bd = new Base64Data(); imageData.set(bd,mimeType); return bd; }
Example 8
Source File: ImageDataContentHandler.java From cxf with Apache License 2.0 | 5 votes |
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()); } }
Example 9
Source File: BufferedImageHttpMessageConverter.java From spring-analysis-note with MIT License | 5 votes |
/** * Sets the default {@code Content-Type} to be used for writing. * @throws IllegalArgumentException if the given content type is not supported by the Java Image I/O API */ public void setDefaultContentType(@Nullable MediaType defaultContentType) { if (defaultContentType != null) { Iterator<ImageWriter> imageWriters = ImageIO.getImageWritersByMIMEType(defaultContentType.toString()); if (!imageWriters.hasNext()) { throw new IllegalArgumentException( "Content-Type [" + defaultContentType + "] is not supported by the Java Image I/O API"); } } this.defaultContentType = defaultContentType; }
Example 10
Source File: BufferedImageHttpMessageConverter.java From lams with GNU General Public License v2.0 | 5 votes |
private void writeInternal(BufferedImage image, MediaType contentType, OutputStream body) throws IOException, HttpMessageNotWritableException { ImageOutputStream imageOutputStream = null; ImageWriter imageWriter = null; try { Iterator<ImageWriter> imageWriters = ImageIO.getImageWritersByMIMEType(contentType.toString()); if (imageWriters.hasNext()) { imageWriter = imageWriters.next(); ImageWriteParam iwp = imageWriter.getDefaultWriteParam(); process(iwp); imageOutputStream = createImageOutputStream(body); imageWriter.setOutput(imageOutputStream); imageWriter.write(null, new IIOImage(image, null, null), iwp); } else { throw new HttpMessageNotWritableException( "Could not find javax.imageio.ImageWriter for Content-Type [" + contentType + "]"); } } finally { if (imageWriter != null) { imageWriter.dispose(); } if (imageOutputStream != null) { try { imageOutputStream.close(); } catch (IOException ex) { // ignore } } } }
Example 11
Source File: BufferedImageHttpMessageConverter.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Sets the default {@code Content-Type} to be used for writing. * @throws IllegalArgumentException if the given content type is not supported by the Java Image I/O API */ public void setDefaultContentType(MediaType defaultContentType) { Assert.notNull(defaultContentType, "'contentType' must not be null"); Iterator<ImageWriter> imageWriters = ImageIO.getImageWritersByMIMEType(defaultContentType.toString()); if (!imageWriters.hasNext()) { throw new IllegalArgumentException( "Content-Type [" + defaultContentType + "] is not supported by the Java Image I/O API"); } this.defaultContentType = defaultContentType; }
Example 12
Source File: BufferedImageHttpMessageConverter.java From lams with GNU General Public License v2.0 | 5 votes |
private boolean isWritable(MediaType mediaType) { if (mediaType == null || MediaType.ALL.equals(mediaType)) { return true; } Iterator<ImageWriter> imageWriters = ImageIO.getImageWritersByMIMEType(mediaType.toString()); return imageWriters.hasNext(); }
Example 13
Source File: XDataTransferer.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df) { LinkedHashSet<String> natives = new LinkedHashSet<>(1); if (df == null) { return natives; } String charset = df.getParameter("charset"); String baseType = df.getPrimaryType() + "/" + df.getSubType(); String mimeType = baseType; if (charset != null && DataTransferer.isFlavorCharsetTextType(df)) { mimeType += ";charset=" + charset; } // Add a mapping to the MIME native whenever the representation class // doesn't require translation. if (df.getRepresentationClass() != null && (df.isRepresentationClassInputStream() || df.isRepresentationClassByteBuffer() || byte[].class.equals(df.getRepresentationClass()))) { natives.add(mimeType); } if (DataFlavor.imageFlavor.equals(df)) { String[] mimeTypes = ImageIO.getWriterMIMETypes(); if (mimeTypes != null) { for (int i = 0; i < mimeTypes.length; i++) { Iterator writers = ImageIO.getImageWritersByMIMEType(mimeTypes[i]); while (writers.hasNext()) { ImageWriter imageWriter = (ImageWriter)writers.next(); ImageWriterSpi writerSpi = imageWriter.getOriginatingProvider(); if (writerSpi != null && writerSpi.canEncodeImage(getDefaultImageTypeSpecifier())) { natives.add(mimeTypes[i]); break; } } } } } else if (DataTransferer.isFlavorCharsetTextType(df)) { // stringFlavor is semantically equivalent to the standard // "text/plain" MIME type. if (DataFlavor.stringFlavor.equals(df)) { baseType = "text/plain"; } for (String encoding : DataTransferer.standardEncodings()) { if (!encoding.equals(charset)) { natives.add(baseType + ";charset=" + encoding); } } // Add a MIME format without specified charset. if (!natives.contains(baseType)) { natives.add(baseType); } } return natives; }
Example 14
Source File: XDataTransferer.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df) { LinkedHashSet<String> natives = new LinkedHashSet<>(1); if (df == null) { return natives; } String charset = df.getParameter("charset"); String baseType = df.getPrimaryType() + "/" + df.getSubType(); String mimeType = baseType; if (charset != null && DataFlavorUtil.isFlavorCharsetTextType(df)) { mimeType += ";charset=" + charset; } // Add a mapping to the MIME native whenever the representation class // doesn't require translation. if (df.getRepresentationClass() != null && (df.isRepresentationClassInputStream() || df.isRepresentationClassByteBuffer() || byte[].class.equals(df.getRepresentationClass()))) { natives.add(mimeType); } if (DataFlavor.imageFlavor.equals(df)) { String[] mimeTypes = ImageIO.getWriterMIMETypes(); if (mimeTypes != null) { for (String mime : mimeTypes) { Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(mime); while (writers.hasNext()) { ImageWriter imageWriter = writers.next(); ImageWriterSpi writerSpi = imageWriter.getOriginatingProvider(); if (writerSpi != null && writerSpi.canEncodeImage(getDefaultImageTypeSpecifier())) { natives.add(mime); break; } } } } } else if (DataFlavorUtil.isFlavorCharsetTextType(df)) { // stringFlavor is semantically equivalent to the standard // "text/plain" MIME type. if (DataFlavor.stringFlavor.equals(df)) { baseType = "text/plain"; } for (String encoding : DataFlavorUtil.standardEncodings()) { if (!encoding.equals(charset)) { natives.add(baseType + ";charset=" + encoding); } } // Add a MIME format without specified charset. if (!natives.contains(baseType)) { natives.add(baseType); } } return natives; }
Example 15
Source File: XDataTransferer.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df) { LinkedHashSet<String> natives = new LinkedHashSet<>(1); if (df == null) { return natives; } String charset = df.getParameter("charset"); String baseType = df.getPrimaryType() + "/" + df.getSubType(); String mimeType = baseType; if (charset != null && DataTransferer.isFlavorCharsetTextType(df)) { mimeType += ";charset=" + charset; } // Add a mapping to the MIME native whenever the representation class // doesn't require translation. if (df.getRepresentationClass() != null && (df.isRepresentationClassInputStream() || df.isRepresentationClassByteBuffer() || byte[].class.equals(df.getRepresentationClass()))) { natives.add(mimeType); } if (DataFlavor.imageFlavor.equals(df)) { String[] mimeTypes = ImageIO.getWriterMIMETypes(); if (mimeTypes != null) { for (int i = 0; i < mimeTypes.length; i++) { Iterator writers = ImageIO.getImageWritersByMIMEType(mimeTypes[i]); while (writers.hasNext()) { ImageWriter imageWriter = (ImageWriter)writers.next(); ImageWriterSpi writerSpi = imageWriter.getOriginatingProvider(); if (writerSpi != null && writerSpi.canEncodeImage(getDefaultImageTypeSpecifier())) { natives.add(mimeTypes[i]); break; } } } } } else if (DataTransferer.isFlavorCharsetTextType(df)) { // stringFlavor is semantically equivalent to the standard // "text/plain" MIME type. if (DataFlavor.stringFlavor.equals(df)) { baseType = "text/plain"; } for (String encoding : DataTransferer.standardEncodings()) { if (!encoding.equals(charset)) { natives.add(baseType + ";charset=" + encoding); } } // Add a MIME format without specified charset. if (!natives.contains(baseType)) { natives.add(baseType); } } return natives; }
Example 16
Source File: XDataTransferer.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public List getPlatformMappingsForFlavor(DataFlavor df) { List natives = new ArrayList(1); if (df == null) { return natives; } String charset = df.getParameter("charset"); String baseType = df.getPrimaryType() + "/" + df.getSubType(); String mimeType = baseType; if (charset != null && DataTransferer.isFlavorCharsetTextType(df)) { mimeType += ";charset=" + charset; } // Add a mapping to the MIME native whenever the representation class // doesn't require translation. if (df.getRepresentationClass() != null && (df.isRepresentationClassInputStream() || df.isRepresentationClassByteBuffer() || byteArrayClass.equals(df.getRepresentationClass()))) { natives.add(mimeType); } if (DataFlavor.imageFlavor.equals(df)) { String[] mimeTypes = ImageIO.getWriterMIMETypes(); if (mimeTypes != null) { for (int i = 0; i < mimeTypes.length; i++) { Iterator writers = ImageIO.getImageWritersByMIMEType(mimeTypes[i]); while (writers.hasNext()) { ImageWriter imageWriter = (ImageWriter)writers.next(); ImageWriterSpi writerSpi = imageWriter.getOriginatingProvider(); if (writerSpi != null && writerSpi.canEncodeImage(getDefaultImageTypeSpecifier())) { natives.add(mimeTypes[i]); break; } } } } } else if (DataTransferer.isFlavorCharsetTextType(df)) { // stringFlavor is semantically equivalent to the standard // "text/plain" MIME type. if (DataFlavor.stringFlavor.equals(df)) { baseType = "text/plain"; } for (String encoding : DataTransferer.standardEncodings()) { if (!encoding.equals(charset)) { natives.add(baseType + ";charset=" + encoding); } } // Add a MIME format without specified charset. if (!natives.contains(baseType)) { natives.add(baseType); } } return natives; }
Example 17
Source File: JavaxImageIOWriter.java From birt with Eclipse Public License 1.0 | 4 votes |
public void after( ) throws ChartException { super.after( ); if ( _oOutputIdentifier != null ) { // SEARCH FOR WRITER USING FORMAT ImageWriter iw = ImageWriterFactory.instance( ) .createImageWriter( getFormat( ), outputFormat ); // SEARCH FOR WRITER USING MIME TYPE if ( iw == null ) { String s = getMimeType( ); if ( s == null ) { throw new ChartException( ChartDeviceExtensionPlugin.ID, ChartException.RENDERING, "JavaxImageIOWriter.exception.no.imagewriter.mimetype.and.format",//$NON-NLS-1$ new Object[]{ getMimeType( ), getFormat( ), getClass( ).getName( ) }, Messages.getResourceBundle( getULocale( ) ) ); } Iterator<ImageWriter> it = ImageIO.getImageWritersByMIMEType( s ); if ( !it.hasNext( ) ) { throw new ChartException( ChartDeviceExtensionPlugin.ID, ChartException.RENDERING, "JavaxImageIOWriter.exception.no.imagewriter.mimetype", //$NON-NLS-1$ new Object[]{ getMimeType( ) }, Messages.getResourceBundle( getULocale( ) ) ); } iw = it.next( ); } logger.log( ILogger.INFORMATION, Messages.getString( "JavaxImageIOWriter.info.using.imagewriter", getULocale( ) ) //$NON-NLS-1$ + getFormat( ) + iw.getClass( ).getName( ) ); // WRITE TO SPECIFIC FILE FORMAT final Object o = ( _oOutputIdentifier instanceof String ) ? new File( (String) _oOutputIdentifier ) : _oOutputIdentifier; try { final ImageOutputStream ios = SecurityUtil.newImageOutputStream( o ); ImageWriteParam iwp = iw.getDefaultWriteParam( ); updateWriterParameters( iwp ); iw.setOutput( ios ); iw.write( (IIOMetadata) null, new IIOImage( (BufferedImage) _img, null, null ), iwp ); ios.close( ); } catch ( Exception ex ) { throw new ChartException( ChartDeviceExtensionPlugin.ID, ChartException.RENDERING, ex ); } finally { iw.dispose( ); } } // FLUSH AND RESTORE STATE OF INTERNALLY CREATED IMAGE if ( !_bImageExternallySpecified ) { _img.flush( ); _img = null; } // ALWAYS DISPOSE THE GRAPHICS CONTEXT THAT WAS CREATED FROM THE IMAGE _g2d.dispose( ); _g2d = null; }
Example 18
Source File: XDataTransferer.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df) { LinkedHashSet<String> natives = new LinkedHashSet<>(1); if (df == null) { return natives; } String charset = df.getParameter("charset"); String baseType = df.getPrimaryType() + "/" + df.getSubType(); String mimeType = baseType; if (charset != null && DataTransferer.isFlavorCharsetTextType(df)) { mimeType += ";charset=" + charset; } // Add a mapping to the MIME native whenever the representation class // doesn't require translation. if (df.getRepresentationClass() != null && (df.isRepresentationClassInputStream() || df.isRepresentationClassByteBuffer() || byte[].class.equals(df.getRepresentationClass()))) { natives.add(mimeType); } if (DataFlavor.imageFlavor.equals(df)) { String[] mimeTypes = ImageIO.getWriterMIMETypes(); if (mimeTypes != null) { for (int i = 0; i < mimeTypes.length; i++) { Iterator writers = ImageIO.getImageWritersByMIMEType(mimeTypes[i]); while (writers.hasNext()) { ImageWriter imageWriter = (ImageWriter)writers.next(); ImageWriterSpi writerSpi = imageWriter.getOriginatingProvider(); if (writerSpi != null && writerSpi.canEncodeImage(getDefaultImageTypeSpecifier())) { natives.add(mimeTypes[i]); break; } } } } } else if (DataTransferer.isFlavorCharsetTextType(df)) { // stringFlavor is semantically equivalent to the standard // "text/plain" MIME type. if (DataFlavor.stringFlavor.equals(df)) { baseType = "text/plain"; } for (String encoding : DataTransferer.standardEncodings()) { if (!encoding.equals(charset)) { natives.add(baseType + ";charset=" + encoding); } } // Add a MIME format without specified charset. if (!natives.contains(baseType)) { natives.add(baseType); } } return natives; }
Example 19
Source File: XDataTransferer.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df) { LinkedHashSet<String> natives = new LinkedHashSet<>(1); if (df == null) { return natives; } String charset = df.getParameter("charset"); String baseType = df.getPrimaryType() + "/" + df.getSubType(); String mimeType = baseType; if (charset != null && DataTransferer.isFlavorCharsetTextType(df)) { mimeType += ";charset=" + charset; } // Add a mapping to the MIME native whenever the representation class // doesn't require translation. if (df.getRepresentationClass() != null && (df.isRepresentationClassInputStream() || df.isRepresentationClassByteBuffer() || byte[].class.equals(df.getRepresentationClass()))) { natives.add(mimeType); } if (DataFlavor.imageFlavor.equals(df)) { String[] mimeTypes = ImageIO.getWriterMIMETypes(); if (mimeTypes != null) { for (int i = 0; i < mimeTypes.length; i++) { Iterator writers = ImageIO.getImageWritersByMIMEType(mimeTypes[i]); while (writers.hasNext()) { ImageWriter imageWriter = (ImageWriter)writers.next(); ImageWriterSpi writerSpi = imageWriter.getOriginatingProvider(); if (writerSpi != null && writerSpi.canEncodeImage(getDefaultImageTypeSpecifier())) { natives.add(mimeTypes[i]); break; } } } } } else if (DataTransferer.isFlavorCharsetTextType(df)) { // stringFlavor is semantically equivalent to the standard // "text/plain" MIME type. if (DataFlavor.stringFlavor.equals(df)) { baseType = "text/plain"; } for (String encoding : DataTransferer.standardEncodings()) { if (!encoding.equals(charset)) { natives.add(baseType + ";charset=" + encoding); } } // Add a MIME format without specified charset. if (!natives.contains(baseType)) { natives.add(baseType); } } return natives; }
Example 20
Source File: XDataTransferer.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
public LinkedHashSet<String> getPlatformMappingsForFlavor(DataFlavor df) { LinkedHashSet<String> natives = new LinkedHashSet<>(1); if (df == null) { return natives; } String charset = df.getParameter("charset"); String baseType = df.getPrimaryType() + "/" + df.getSubType(); String mimeType = baseType; if (charset != null && DataTransferer.isFlavorCharsetTextType(df)) { mimeType += ";charset=" + charset; } // Add a mapping to the MIME native whenever the representation class // doesn't require translation. if (df.getRepresentationClass() != null && (df.isRepresentationClassInputStream() || df.isRepresentationClassByteBuffer() || byte[].class.equals(df.getRepresentationClass()))) { natives.add(mimeType); } if (DataFlavor.imageFlavor.equals(df)) { String[] mimeTypes = ImageIO.getWriterMIMETypes(); if (mimeTypes != null) { for (int i = 0; i < mimeTypes.length; i++) { Iterator writers = ImageIO.getImageWritersByMIMEType(mimeTypes[i]); while (writers.hasNext()) { ImageWriter imageWriter = (ImageWriter)writers.next(); ImageWriterSpi writerSpi = imageWriter.getOriginatingProvider(); if (writerSpi != null && writerSpi.canEncodeImage(getDefaultImageTypeSpecifier())) { natives.add(mimeTypes[i]); break; } } } } } else if (DataTransferer.isFlavorCharsetTextType(df)) { // stringFlavor is semantically equivalent to the standard // "text/plain" MIME type. if (DataFlavor.stringFlavor.equals(df)) { baseType = "text/plain"; } for (String encoding : DataTransferer.standardEncodings()) { if (!encoding.equals(charset)) { natives.add(baseType + ";charset=" + encoding); } } // Add a MIME format without specified charset. if (!natives.contains(baseType)) { natives.add(baseType); } } return natives; }