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

The following examples show how to use javax.imageio.ImageIO#getImageReadersByMIMEType() . 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: BufferedImageHttpMessageConverter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private boolean isReadable(@Nullable MediaType mediaType) {
	if (mediaType == null) {
		return true;
	}
	Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(mediaType.toString());
	return imageReaders.hasNext();
}
 
Example 2
Source File: BufferedImageHttpMessageConverter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public BufferedImage read(@Nullable 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();
		if (contentType == null) {
			throw new HttpMessageNotReadableException("No Content-Type header", inputMessage);
		}
		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 + "]",
					inputMessage);
		}
	}
	finally {
		if (imageReader != null) {
			imageReader.dispose();
		}
		if (imageInputStream != null) {
			try {
				imageInputStream.close();
			}
			catch (IOException ex) {
				// ignore
			}
		}
	}
}
 
Example 3
Source File: BufferedImageHttpMessageConverter.java    From java-technology-stack with MIT License 5 votes vote down vote up
private boolean isReadable(@Nullable MediaType mediaType) {
	if (mediaType == null) {
		return true;
	}
	Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(mediaType.toString());
	return imageReaders.hasNext();
}
 
Example 4
Source File: BufferedImageHttpMessageConverter.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public BufferedImage read(@Nullable 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();
		if (contentType == null) {
			throw new HttpMessageNotReadableException("No Content-Type header", inputMessage);
		}
		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 + "]",
					inputMessage);
		}
	}
	finally {
		if (imageReader != null) {
			imageReader.dispose();
		}
		if (imageInputStream != null) {
			try {
				imageInputStream.close();
			}
			catch (IOException ex) {
				// ignore
			}
		}
	}
}
 
Example 5
Source File: BufferedImageHttpMessageConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private boolean isReadable(MediaType mediaType) {
	if (mediaType == null) {
		return true;
	}
	Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(mediaType.toString());
	return imageReaders.hasNext();
}
 
Example 6
Source File: BufferedImageHttpMessageConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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 7
Source File: GetReaderWriterInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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 8
Source File: BufferedImageHttpMessageConverter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private boolean isReadable(MediaType mediaType) {
	if (mediaType == null) {
		return true;
	}
	Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(mediaType.toString());
	return imageReaders.hasNext();
}
 
Example 9
Source File: BufferedImageHttpMessageConverter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: GetReaderWriterInfo.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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 11
Source File: TestAxisCameraDriver.java    From sensorhub with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void handleEvent(Event<?> e)
{
    assertTrue(e instanceof SensorDataEvent);
    SensorDataEvent newDataEvent = (SensorDataEvent)e;
    
    if (newDataEvent.getSource().getClass().equals(AxisVideoOutput.class))
    {
     DataComponent camDataStruct = newDataEvent.getRecordDescription().copy();
     camDataStruct.setData(newDataEvent.getRecords()[0]);
     
     actualHeight = camDataStruct.getComponent(1).getComponentCount();
     actualWidth = camDataStruct.getComponent(1).getComponent(0).getComponentCount();
     dataBlockSize = newDataEvent.getRecords()[0].getAtomCount();
     		
     byte[] frameData = (byte[])camDataStruct.getComponent(1).getData().getUnderlyingObject();
                    
     /*// use RGB data directly
     byte[] destArray = ((DataBufferByte)img.getRaster().getDataBuffer()).getData();
     System.arraycopy(frameData, 0, destArray, 0, dataBlockSize-1);*/
     
     // uncompress JPEG data
     BufferedImage rgbImage;
        try
        {
            InputStream imageStream = new ByteArrayInputStream(frameData);                               
            ImageInputStream input = ImageIO.createImageInputStream(imageStream); 
            Iterator<ImageReader> readers = ImageIO.getImageReadersByMIMEType("image/jpeg");
            ImageReader reader = readers.next();
            reader.setInput(input);
            rgbImage = reader.read(0);
            videoWindow.getContentPane().getGraphics().drawImage(rgbImage, 0, 0, null);
        }
        catch (IOException e1)
        {
            throw new RuntimeException(e1);
        }
        
        frameCount++;
    }
    else if (newDataEvent.getSource().getClass().equals(AxisSettingsOutput.class))
    {
    	DataComponent ptzParams = newDataEvent.getRecordDescription().copy();
    	ptzParams.setData(newDataEvent.getRecords()[0]);
    	System.out.println(ptzParams);
    }
    
    synchronized (this) { this.notify(); }
}