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

The following examples show how to use javax.imageio.stream.ImageInputStream#readByte() . 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: MarkTryFinallyReproducer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
    MarkTryFinallyReproducerSpi spi = new MarkTryFinallyReproducerSpi();
    IIORegistry.getDefaultInstance().registerServiceProvider(spi);

    ImageInputStream iis1 =
      new NotClosingImageInputStream(ImageIO.createImageInputStream(new ByteArrayInputStream(bmp)));
    iis1.readByte();
    iis1.mark();
    long p1 = iis1.getStreamPosition();
    iis1.readByte();
    iis1.mark();
    long p2 = iis1.getStreamPosition();
    BufferedImage bi1 = ImageIO.read(iis1);
    iis1.reset();
    long pn2 = iis1.getStreamPosition();
    iis1.reset();
    long pn1 = iis1.getStreamPosition();
    if (p1 != pn1 || p2!= pn2) {
        throw new RuntimeException("Exception from call to canDecodeInput in ImageIO. " +
                                   "Corrupted stack in ImageInputStream");
    }

}
 
Example 2
Source File: ReaderUtil.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public static int readMultiByteInteger(ImageInputStream iis)
    throws IOException
{
    int value = iis.readByte();
    int result = value & 0x7f;
    while((value & 0x80) == 0x80) {
        result <<= 7;
        value = iis.readByte();
        result |= (value & 0x7f);
    }
    return result;
}
 
Example 3
Source File: ReaderUtil.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static int readMultiByteInteger(ImageInputStream iis)
    throws IOException
{
    int value = iis.readByte();
    int result = value & 0x7f;
    while((value & 0x80) == 0x80) {
        result <<= 7;
        value = iis.readByte();
        result |= (value & 0x7f);
    }
    return result;
}
 
Example 4
Source File: ReaderUtil.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static int readMultiByteInteger(ImageInputStream iis)
    throws IOException
{
    int value = iis.readByte();
    int result = value & 0x7f;
    while((value & 0x80) == 0x80) {
        result <<= 7;
        value = iis.readByte();
        result |= (value & 0x7f);
    }
    return result;
}
 
Example 5
Source File: ReaderUtil.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static int readMultiByteInteger(ImageInputStream iis)
    throws IOException
{
    int value = iis.readByte();
    int result = value & 0x7f;
    while((value & 0x80) == 0x80) {
        result <<= 7;
        value = iis.readByte();
        result |= (value & 0x7f);
    }
    return result;
}
 
Example 6
Source File: ReaderUtil.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public static int readMultiByteInteger(ImageInputStream iis)
    throws IOException
{
    int value = iis.readByte();
    int result = value & 0x7f;
    while((value & 0x80) == 0x80) {
        result <<= 7;
        value = iis.readByte();
        result |= (value & 0x7f);
    }
    return result;
}
 
Example 7
Source File: ReaderUtil.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static int readMultiByteInteger(ImageInputStream iis)
    throws IOException
{
    int value = iis.readByte();
    int result = value & 0x7f;
    while((value & 0x80) == 0x80) {
        result <<= 7;
        value = iis.readByte();
        result |= (value & 0x7f);
    }
    return result;
}
 
Example 8
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 9
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 10
Source File: WBMPImageReaderSpi.java    From openjdk-jdk9 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 11
Source File: WBMPImageReaderSpi.java    From openjdk-8-source 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 12
Source File: WBMPImageReaderSpi.java    From Bytecoder 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 13
Source File: WBMPImageReaderSpi.java    From jdk8u-dev-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 14
Source File: WBMPImageReaderSpi.java    From openjdk-jdk8u-backup 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 15
Source File: WBMPImageReaderSpi.java    From openjdk-jdk8u 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 16
Source File: WBMPImageReaderSpi.java    From JDKSourceCode1.8 with MIT License 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 17
Source File: WBMPImageReaderSpi.java    From jdk8u60 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 18
Source File: WBMPImageReaderSpi.java    From openjdk-8 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 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 20
Source File: WBMPImageReaderSpi.java    From dragonwell8_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();
    }
}