Java Code Examples for javax.imageio.stream.ImageInputStream#getByteOrder()
The following examples show how to use
javax.imageio.stream.ImageInputStream#getByteOrder() .
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: WebPImageReaderSpi.java From j-webp with Apache License 2.0 | 5 votes |
@Override public boolean canDecodeInput( Object source ) throws IOException { if ( !( source instanceof ImageInputStream ) ) { return false; } ImageInputStream stream = ( ImageInputStream ) source; byte[] b = new byte[ 4 ]; ByteOrder oldByteOrder = stream.getByteOrder(); stream.mark(); stream.setByteOrder( ByteOrder.LITTLE_ENDIAN ); try { stream.readFully( b ); if ( !Arrays.equals( b, RIFF ) ) { return false; } long chunkLength = stream.readUnsignedInt(); long streamLength = stream.length(); if ( streamLength != -1 && streamLength != chunkLength + 8 ) { return false; } stream.readFully( b ); if ( !Arrays.equals( b, WEBP ) ) { return false; } stream.readFully( b ); if ( !Arrays.equals( b, VP8_ ) && !Arrays.equals( b, VP8L ) && !Arrays.equals( b, VP8X ) ) { return false; } } finally { stream.setByteOrder( oldByteOrder ); stream.reset(); } return true; }
Example 2
Source File: WebPImageReaderSpi.java From webp-imageio with Apache License 2.0 | 5 votes |
@Override public boolean canDecodeInput( Object source ) throws IOException { if ( !( source instanceof ImageInputStream ) ) { return false; } ImageInputStream stream = ( ImageInputStream ) source; byte[] b = new byte[ 4 ]; ByteOrder oldByteOrder = stream.getByteOrder(); stream.mark(); stream.setByteOrder( ByteOrder.LITTLE_ENDIAN ); try { stream.readFully( b ); if ( !Arrays.equals( b, RIFF ) ) { return false; } long chunkLength = stream.readUnsignedInt(); long streamLength = stream.length(); if ( streamLength != -1 && streamLength != chunkLength + 8 ) { return false; } stream.readFully( b ); if ( !Arrays.equals( b, WEBP ) ) { return false; } stream.readFully( b ); if ( !Arrays.equals( b, VP8_ ) && !Arrays.equals( b, VP8X ) ) { return false; } } finally { stream.setByteOrder( oldByteOrder ); stream.reset(); } return true; }