Java Code Examples for javax.imageio.ImageIO.getImageReadersByMIMEType()

The following are Jave code examples for showing how to use getImageReadersByMIMEType() of the javax.imageio.ImageIO class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: geomapapp   File: LayerExplorer.java   View Source Code Vote up 6 votes
public static String chooseImageFormat(String[] formats) {
	 if (formats == null || formats.length == 0)
		return null;
	for (String s : formatOrderPreference) {
		for (String f : formats) {
			if (f.equalsIgnoreCase(s)) {
				Iterator it = ImageIO.getImageReadersByMIMEType(f); 
				if (it.hasNext())
						return f;
			}
		}
	}

	System.err.println("No image recoginized, using " + formats[0]); 

	return formats[0]; // none recognized; just use the first in the caps list
}
 
Example 2
Project: lams   File: BufferedImageHttpMessageConverter.java   View Source Code Vote up 5 votes
private boolean isReadable(MediaType mediaType) {
	if (mediaType == null) {
		return true;
	}
	Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(mediaType.toString());
	return imageReaders.hasNext();
}
 
Example 3
Project: lams   File: BufferedImageHttpMessageConverter.java   View Source Code Vote up 5 votes
@Override
public BufferedImage read(Class<? extends BufferedImage> clazz, HttpInputMessage inputMessage)
		throws IOException, HttpMessageNotReadableException {

	ImageInputStream imageInputStream = null;
	ImageReader imageReader = null;
	try {
		imageInputStream = createImageInputStream(inputMessage.getBody());
		MediaType contentType = inputMessage.getHeaders().getContentType();
		Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(contentType.toString());
		if (imageReaders.hasNext()) {
			imageReader = imageReaders.next();
			ImageReadParam irp = imageReader.getDefaultReadParam();
			process(irp);
			imageReader.setInput(imageInputStream, true);
			return imageReader.read(0, irp);
		}
		else {
			throw new HttpMessageNotReadableException(
					"Could not find javax.imageio.ImageReader for Content-Type [" + contentType + "]");
		}
	}
	finally {
		if (imageReader != null) {
			imageReader.dispose();
		}
		if (imageInputStream != null) {
			try {
				imageInputStream.close();
			}
			catch (IOException ex) {
				// ignore
			}
		}
	}
}
 
Example 4
Project: openjdk-jdk10   File: GetReaderWriterInfo.java   View Source Code Vote up 5 votes
private static void testGetReaderMIMETypes() {
    String[] types = ImageIO.getReaderMIMETypes();
    for (String t : types) {
        Iterator<ImageReader> it = ImageIO.getImageReadersByMIMEType(t);
        if (!it.hasNext()) {
            throw new RuntimeException("getReaderMIMETypes returned " +
                                       "an unknown type: " + t);
        }
    }
}
 
Example 5
Project: imageio-jnr   File: TurboJpegImageReaderTest.java   View Source Code Vote up 5 votes
@Test
public void testReaderIsRegistered() {
  Supplier<Iterator<ImageReader>> getReaderIter = () -> ImageIO.getImageReadersBySuffix("jpg");
  assertThat(getReaderIter.get()).isNotEmpty();
  assertThat(getReaderIter.get()).hasAtLeastOneElementOfType(TurboJpegImageReader.class);
  getReaderIter = () -> ImageIO.getImageReadersByMIMEType("image/jpeg");
  assertThat(getReaderIter.get()).isNotEmpty();
  assertThat(getReaderIter.get()).hasAtLeastOneElementOfType(TurboJpegImageReader.class);
  getReaderIter = () -> ImageIO.getImageReadersByFormatName("jpeg");
  assertThat(getReaderIter.get()).isNotEmpty();
  assertThat(getReaderIter.get()).hasAtLeastOneElementOfType(TurboJpegImageReader.class);
}