Java Code Examples for javax.imageio.stream.ImageInputStream#reset()

The following examples show how to use javax.imageio.stream.ImageInputStream#reset() . 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: PNGImageReaderSpi.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public boolean canDecodeInput(Object input) throws IOException {
    if (!(input instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)input;
    byte[] b = new byte[8];
    stream.mark();
    stream.readFully(b);
    stream.reset();

    return (b[0] == (byte)137 &&
            b[1] == (byte)80 &&
            b[2] == (byte)78 &&
            b[3] == (byte)71 &&
            b[4] == (byte)13 &&
            b[5] == (byte)10 &&
            b[6] == (byte)26 &&
            b[7] == (byte)10);
}
 
Example 2
Source File: PNGImageReaderSpi.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public boolean canDecodeInput(Object input) throws IOException {
    if (!(input instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)input;
    byte[] b = new byte[8];
    stream.mark();
    stream.readFully(b);
    stream.reset();

    return (b[0] == (byte)137 &&
            b[1] == (byte)80 &&
            b[2] == (byte)78 &&
            b[3] == (byte)71 &&
            b[4] == (byte)13 &&
            b[5] == (byte)10 &&
            b[6] == (byte)26 &&
            b[7] == (byte)10);
}
 
Example 3
Source File: PNGImageReaderSpi.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public boolean canDecodeInput(Object input) throws IOException {
    if (!(input instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)input;
    byte[] b = new byte[8];
    stream.mark();
    stream.readFully(b);
    stream.reset();

    return (b[0] == (byte)137 &&
            b[1] == (byte)80 &&
            b[2] == (byte)78 &&
            b[3] == (byte)71 &&
            b[4] == (byte)13 &&
            b[5] == (byte)10 &&
            b[6] == (byte)26 &&
            b[7] == (byte)10);
}
 
Example 4
Source File: PNGImageReaderSpi.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public boolean canDecodeInput(Object input) throws IOException {
    if (!(input instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)input;
    byte[] b = new byte[8];
    stream.mark();
    stream.readFully(b);
    stream.reset();

    return (b[0] == (byte)137 &&
            b[1] == (byte)80 &&
            b[2] == (byte)78 &&
            b[3] == (byte)71 &&
            b[4] == (byte)13 &&
            b[5] == (byte)10 &&
            b[6] == (byte)26 &&
            b[7] == (byte)10);
}
 
Example 5
Source File: JFIFMarkerSegment.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    JPEGImageReader thumbReader = new JPEGImageReader(null);
    thumbReader.setInput(iis);
    thumbReader.addIIOReadProgressListener
        (new ThumbnailReadListener(reader));
    BufferedImage ret = thumbReader.read(0, null);
    thumbReader.dispose();
    iis.reset();
    return ret;
}
 
Example 6
Source File: GIFImageReaderSpi.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public boolean canDecodeInput(Object input) throws IOException {
    if (!(input instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)input;
    byte[] b = new byte[6];
    stream.mark();
    stream.readFully(b);
    stream.reset();

    return b[0] == 'G' && b[1] == 'I' && b[2] == 'F' && b[3] == '8' &&
        (b[4] == '7' || b[4] == '9') && b[5] == 'a';
}
 
Example 7
Source File: BMPImageReaderSpi.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)source;
    byte[] b = new byte[2];
    stream.mark();
    stream.readFully(b);
    stream.reset();

    return (b[0] == 0x42) && (b[1] == 0x4d);
}
 
Example 8
Source File: JFIFMarkerSegment.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    DataBufferByte buffer = new DataBufferByte(getLength());
    readByteBuffer(iis,
                   buffer.getData(),
                   reader,
                   1.0F,
                   0.0F);
    iis.reset();

    WritableRaster raster =
        Raster.createInterleavedRaster(buffer,
                                       thumbWidth,
                                       thumbHeight,
                                       thumbWidth*3,
                                       3,
                                       new int [] {0, 1, 2},
                                       null);
    ColorModel cm = new ComponentColorModel(JPEG.JCS.sRGB,
                                            false,
                                            false,
                                            ColorModel.OPAQUE,
                                            DataBuffer.TYPE_BYTE);
    return new BufferedImage(cm,
                             raster,
                             false,
                             null);
}
 
Example 9
Source File: JFIFMarkerSegment.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    JPEGImageReader thumbReader = new JPEGImageReader(null);
    thumbReader.setInput(iis);
    thumbReader.addIIOReadProgressListener
        (new ThumbnailReadListener(reader));
    BufferedImage ret = thumbReader.read(0, null);
    thumbReader.dispose();
    iis.reset();
    return ret;
}
 
Example 10
Source File: JFIFMarkerSegment.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    JPEGImageReader thumbReader = new JPEGImageReader(null);
    thumbReader.setInput(iis);
    thumbReader.addIIOReadProgressListener
        (new ThumbnailReadListener(reader));
    BufferedImage ret = thumbReader.read(0, null);
    thumbReader.dispose();
    iis.reset();
    return ret;
}
 
Example 11
Source File: BMPImageReaderSpi.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)source;
    byte[] b = new byte[2];
    stream.mark();
    stream.readFully(b);
    stream.reset();

    return (b[0] == 0x42) && (b[1] == 0x4d);
}
 
Example 12
Source File: BMPImageReaderSpi.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)source;
    byte[] b = new byte[2];
    stream.mark();
    stream.readFully(b);
    stream.reset();

    return (b[0] == 0x42) && (b[1] == 0x4d);
}
 
Example 13
Source File: JFIFMarkerSegment.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    JPEGImageReader thumbReader = new JPEGImageReader(null);
    thumbReader.setInput(iis);
    thumbReader.addIIOReadProgressListener
        (new ThumbnailReadListener(reader));
    BufferedImage ret = thumbReader.read(0, null);
    thumbReader.dispose();
    iis.reset();
    return ret;
}
 
Example 14
Source File: JFIFMarkerSegment.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    DataBufferByte buffer = new DataBufferByte(getLength());
    readByteBuffer(iis,
                   buffer.getData(),
                   reader,
                   1.0F,
                   0.0F);
    iis.reset();

    WritableRaster raster =
        Raster.createInterleavedRaster(buffer,
                                       thumbWidth,
                                       thumbHeight,
                                       thumbWidth*3,
                                       3,
                                       new int [] {0, 1, 2},
                                       null);
    ColorModel cm = new ComponentColorModel(JPEG.JCS.sRGB,
                                            false,
                                            false,
                                            ColorModel.OPAQUE,
                                            DataBuffer.TYPE_BYTE);
    return new BufferedImage(cm,
                             raster,
                             false,
                             null);
}
 
Example 15
Source File: BMPImageReaderSpi.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)source;
    byte[] b = new byte[2];
    stream.mark();
    stream.readFully(b);
    stream.reset();

    return (b[0] == 0x42) && (b[1] == 0x4d);
}
 
Example 16
Source File: WebPImageReaderSpi.java    From webp-imageio with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 17
Source File: JFIFMarkerSegment.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    JPEGImageReader thumbReader = new JPEGImageReader(null);
    thumbReader.setInput(iis);
    thumbReader.addIIOReadProgressListener
        (new ThumbnailReadListener(reader));
    BufferedImage ret = thumbReader.read(0, null);
    thumbReader.dispose();
    iis.reset();
    return ret;
}
 
Example 18
Source File: WBMPImageReaderSpi.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)source;

    stream.mark();
    try {
        int type = stream.readByte();   // TypeField
        int fixHeaderField = stream.readByte();
        // check WBMP "header"
        if (type != 0 || fixHeaderField != 0) {
            // while WBMP reader does not support ext WBMP headers
            return false;
        }

        int width = ReaderUtil.readMultiByteInteger(stream);
        int height = ReaderUtil.readMultiByteInteger(stream);
        // check image dimension
        if (width <= 0 || height <= 0) {
            return false;
        }

        long dataLength = stream.length();
        if (dataLength == -1) {
            // We can't verify that amount of data in the stream
            // corresponds to image dimension because we do not know
            // the length of the data stream.
            // Assuming that wbmp image are used for mobile devices,
            // let's introduce an upper limit for image dimension.
            // In case if exact amount of raster data is unknown,
            // let's reject images with dimension above the limit.
            return (width < MAX_WBMP_WIDTH) && (height < MAX_WBMP_HEIGHT);
        }

        dataLength -= stream.getStreamPosition();

        long scanSize = (width / 8) + ((width % 8) == 0 ? 0 : 1);

        return (dataLength == scanSize * height);
    } finally {
        stream.reset();
    }
}
 
Example 19
Source File: WBMPImageReaderSpi.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)source;

    stream.mark();
    try {
        int type = stream.readByte();   // TypeField
        int fixHeaderField = stream.readByte();
        // check WBMP "header"
        if (type != 0 || fixHeaderField != 0) {
            // while WBMP reader does not support ext WBMP headers
            return false;
        }

        int width = ReaderUtil.readMultiByteInteger(stream);
        int height = ReaderUtil.readMultiByteInteger(stream);
        // check image dimension
        if (width <= 0 || height <= 0) {
            return false;
        }

        long dataLength = stream.length();
        if (dataLength == -1) {
            // We can't verify that amount of data in the stream
            // corresponds to image dimension because we do not know
            // the length of the data stream.
            // Assuming that wbmp image are used for mobile devices,
            // let's introduce an upper limit for image dimension.
            // In case if exact amount of raster data is unknown,
            // let's reject images with dimension above the limit.
            return (width < MAX_WBMP_WIDTH) && (height < MAX_WBMP_HEIGHT);
        }

        dataLength -= stream.getStreamPosition();

        long scanSize = (width / 8) + ((width % 8) == 0 ? 0 : 1);

        return (dataLength == scanSize * height);
    } finally {
        stream.reset();
    }
}
 
Example 20
Source File: WBMPImageReaderSpi.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public boolean canDecodeInput(Object source) throws IOException {
    if (!(source instanceof ImageInputStream)) {
        return false;
    }

    ImageInputStream stream = (ImageInputStream)source;

    stream.mark();
    try {
        int type = stream.readByte();   // TypeField
        int fixHeaderField = stream.readByte();
        // check WBMP "header"
        if (type != 0 || fixHeaderField != 0) {
            // while WBMP reader does not support ext WBMP headers
            return false;
        }

        int width = ReaderUtil.readMultiByteInteger(stream);
        int height = ReaderUtil.readMultiByteInteger(stream);
        // check image dimension
        if (width <= 0 || height <= 0) {
            return false;
        }

        long dataLength = stream.length();
        if (dataLength == -1) {
            // We can't verify that amount of data in the stream
            // corresponds to image dimension because we do not know
            // the length of the data stream.
            // Assuming that wbmp image are used for mobile devices,
            // let's introduce an upper limit for image dimension.
            // In case if exact amount of raster data is unknown,
            // let's reject images with dimension above the limit.
            return (width < MAX_WBMP_WIDTH) && (height < MAX_WBMP_HEIGHT);
        }

        dataLength -= stream.getStreamPosition();

        long scanSize = (width / 8) + ((width % 8) == 0 ? 0 : 1);

        return (dataLength == scanSize * height);
    } finally {
        stream.reset();
    }
}