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

The following examples show how to use javax.imageio.ImageIO#getImageReadersByMIMEType() . These examples are extracted from open source projects. 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
private boolean isReadable(@Nullable MediaType mediaType) {
	if (mediaType == null) {
		return true;
	}
	Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(mediaType.toString());
	return imageReaders.hasNext();
}
 
Example 2
@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
private boolean isReadable(@Nullable MediaType mediaType) {
	if (mediaType == null) {
		return true;
	}
	Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(mediaType.toString());
	return imageReaders.hasNext();
}
 
Example 4
@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
private boolean isReadable(MediaType mediaType) {
	if (mediaType == null) {
		return true;
	}
	Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(mediaType.toString());
	return imageReaders.hasNext();
}
 
Example 6
@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
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
private boolean isReadable(MediaType mediaType) {
	if (mediaType == null) {
		return true;
	}
	Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(mediaType.toString());
	return imageReaders.hasNext();
}
 
Example 9
@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
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
@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(); }
}