java.awt.image.DataBufferShort#javax.imageio.IIOException源码实例Demo

下面列出了java.awt.image.DataBufferShort#javax.imageio.IIOException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Test
void shouldLogIOException()
{
    File path = new File("route_66");
    filesystemScreenshotDebugger.setDebugScreenshotsLocation(Optional.of(path));
    filesystemScreenshotDebugger.debug(FilesystemScreenshotDebuggerTests.class, "",
            new BufferedImage(10, 10, 5));
    List<LoggingEvent> loggingEvents = testLogger.getLoggingEvents();
    LoggingEvent loggingEvent = loggingEvents.get(0);
    String message = loggingEvent.getMessage();
    assertThat(loggingEvents, Matchers.hasSize(1));
    assertEquals(Level.DEBUG, loggingEvent.getLevel());
    assertEquals("Unable to save debug screenshot to {}", message);
    assertThat(loggingEvent.getArguments().get(0).toString(), stringContainsInOrder(List.of(path.toString(),
            "FilesystemScreenshotDebuggerTests_.png")));
    assertThat(loggingEvent.getThrowable().get(), is(instanceOf(IIOException.class)));
}
 
源代码2 项目: jdk1.8-source-analysis   文件: JPEGBuffer.java
/**
 * Fills the data array from the stream, starting with
 * the buffer and then reading directly from the stream
 * if necessary.  The buffer is left in an appropriate
 * state.  If the end of the stream is encountered, an
 * <code>IIOException</code> is thrown with the
 * message "Image Format Error".
 */
void readData(byte [] data) throws IOException {
    int count = data.length;
    // First see what's left in the buffer.
    if (bufAvail >= count) {  // It's enough
        System.arraycopy(buf, bufPtr, data, 0, count);
        bufAvail -= count;
        bufPtr += count;
        return;
    }
    int offset = 0;
    if (bufAvail > 0) {  // Some there, but not enough
        System.arraycopy(buf, bufPtr, data, 0, bufAvail);
        offset = bufAvail;
        count -= bufAvail;
        bufAvail = 0;
        bufPtr = 0;
    }
    // Now read the rest directly from the stream
    if (iis.read(data, offset, count) != count) {
        throw new IIOException ("Image format Error");
    }
}
 
源代码3 项目: jdk1.8-source-analysis   文件: JPEGBuffer.java
/**
 * Skips <code>count</code> bytes, leaving the buffer
 * in an appropriate state.  If the end of the stream is
 * encountered, an <code>IIOException</code> is thrown with the
 * message "Image Format Error".
 */
void skipData(int count) throws IOException {
    // First see what's left in the buffer.
    if (bufAvail >= count) {  // It's enough
        bufAvail -= count;
        bufPtr += count;
        return;
    }
    if (bufAvail > 0) {  // Some there, but not enough
        count -= bufAvail;
        bufAvail = 0;
        bufPtr = 0;
    }
    // Now read the rest directly from the stream
    if (iis.skipBytes(count) != count) {
        throw new IIOException ("Image format Error");
    }
}
 
源代码4 项目: jdk1.8-source-analysis   文件: GIFImageReader.java
public int getNumImages(boolean allowSearch) throws IIOException {
    if (stream == null) {
        throw new IllegalStateException("Input not set!");
    }
    if (seekForwardOnly && allowSearch) {
        throw new IllegalStateException
            ("seekForwardOnly and allowSearch can't both be true!");
    }

    if (numImages > 0) {
        return numImages;
    }
    if (allowSearch) {
        this.numImages = locateImage(Integer.MAX_VALUE) + 1;
    }
    return numImages;
}
 
源代码5 项目: dragonwell8_jdk   文件: GIFImageWriter.java
private void writeApplicationExtension(GIFWritableImageMetadata im)
  throws IOException {
    if (im.applicationIDs != null) {
        Iterator iterIDs = im.applicationIDs.iterator();
        Iterator iterCodes = im.authenticationCodes.iterator();
        Iterator iterData = im.applicationData.iterator();

        while (iterIDs.hasNext()) {
            try {
                stream.write(0x21);
                stream.write(0xff);

                stream.write(11);
                stream.write((byte[])iterIDs.next(), 0, 8);
                stream.write((byte[])iterCodes.next(), 0, 3);

                writeBlocks((byte[])iterData.next());

                stream.write(0x00);
            } catch (IOException e) {
                throw new IIOException("I/O error writing Application Extension!", e);
            }
        }
    }
}
 
源代码6 项目: jdk1.8-source-analysis   文件: GIFImageWriter.java
private void writePlainTextExtension(GIFWritableImageMetadata im)
  throws IOException {
    if (im.hasPlainTextExtension) {
        try {
            stream.write(0x21);
            stream.write(0x1);

            stream.write(12);

            stream.writeShort(im.textGridLeft);
            stream.writeShort(im.textGridTop);
            stream.writeShort(im.textGridWidth);
            stream.writeShort(im.textGridHeight);
            stream.write(im.characterCellWidth);
            stream.write(im.characterCellHeight);
            stream.write(im.textForegroundColor);
            stream.write(im.textBackgroundColor);

            writeBlocks(im.text);

            stream.write(0x00);
        } catch (IOException e) {
            throw new IIOException("I/O error writing Plain Text Extension!", e);
        }
    }
}
 
源代码7 项目: jdk1.8-source-analysis   文件: GIFImageWriter.java
private void writeApplicationExtension(GIFWritableImageMetadata im)
  throws IOException {
    if (im.applicationIDs != null) {
        Iterator iterIDs = im.applicationIDs.iterator();
        Iterator iterCodes = im.authenticationCodes.iterator();
        Iterator iterData = im.applicationData.iterator();

        while (iterIDs.hasNext()) {
            try {
                stream.write(0x21);
                stream.write(0xff);

                stream.write(11);
                stream.write((byte[])iterIDs.next(), 0, 8);
                stream.write((byte[])iterCodes.next(), 0, 3);

                writeBlocks((byte[])iterData.next());

                stream.write(0x00);
            } catch (IOException e) {
                throw new IIOException("I/O error writing Application Extension!", e);
            }
        }
    }
}
 
源代码8 项目: TencentKona-8   文件: ImageInputStreamImpl.java
/**
 * Resets the current stream byte and bit positions from the stack
 * of marked positions.
 *
 * <p> An <code>IOException</code> will be thrown if the previous
 * marked position lies in the discarded portion of the stream.
 *
 * @exception IOException if an I/O error occurs.
 */
public void reset() throws IOException {
    if (markByteStack.empty()) {
        return;
    }

    long pos = ((Long)markByteStack.pop()).longValue();
    if (pos < flushedPos) {
        throw new IIOException
            ("Previous marked position has been discarded!");
    }
    seek(pos);

    int offset = ((Integer)markBitStack.pop()).intValue();
    setBitOffset(offset);
}
 
源代码9 项目: TencentKona-8   文件: GIFImageWriter.java
private void writeApplicationExtension(GIFWritableImageMetadata im)
  throws IOException {
    if (im.applicationIDs != null) {
        Iterator iterIDs = im.applicationIDs.iterator();
        Iterator iterCodes = im.authenticationCodes.iterator();
        Iterator iterData = im.applicationData.iterator();

        while (iterIDs.hasNext()) {
            try {
                stream.write(0x21);
                stream.write(0xff);

                stream.write(11);
                stream.write((byte[])iterIDs.next(), 0, 8);
                stream.write((byte[])iterCodes.next(), 0, 3);

                writeBlocks((byte[])iterData.next());

                stream.write(0x00);
            } catch (IOException e) {
                throw new IIOException("I/O error writing Application Extension!", e);
            }
        }
    }
}
 
源代码10 项目: TencentKona-8   文件: PNGImageWriter.java
private void write_IHDR() throws IOException {
        // Write IHDR chunk
        ChunkStream cs = new ChunkStream(PNGImageReader.IHDR_TYPE, stream);
        cs.writeInt(metadata.IHDR_width);
        cs.writeInt(metadata.IHDR_height);
        cs.writeByte(metadata.IHDR_bitDepth);
        cs.writeByte(metadata.IHDR_colorType);
        if (metadata.IHDR_compressionMethod != 0) {
            throw new IIOException(
"Only compression method 0 is defined in PNG 1.1");
        }
        cs.writeByte(metadata.IHDR_compressionMethod);
        if (metadata.IHDR_filterMethod != 0) {
            throw new IIOException(
"Only filter method 0 is defined in PNG 1.1");
        }
        cs.writeByte(metadata.IHDR_filterMethod);
        if (metadata.IHDR_interlaceMethod < 0 ||
            metadata.IHDR_interlaceMethod > 1) {
            throw new IIOException(
"Only interlace methods 0 (node) and 1 (adam7) are defined in PNG 1.1");
        }
        cs.writeByte(metadata.IHDR_interlaceMethod);
        cs.finish();
    }
 
源代码11 项目: TencentKona-8   文件: PNGImageReader.java
private void parse_hIST_chunk(int chunkLength) throws IOException,
    IIOException
{
    if (!metadata.PLTE_present) {
        throw new IIOException("hIST chunk without prior PLTE chunk!");
    }

    /* According to PNG specification length of
     * hIST chunk is specified in bytes and
     * hIST chunk consists of 2 byte elements
     * (so we expect length is even).
     */
    metadata.hIST_histogram = new char[chunkLength/2];
    stream.readFully(metadata.hIST_histogram,
                     0, metadata.hIST_histogram.length);

    metadata.hIST_present = true;
}
 
源代码12 项目: dragonwell8_jdk   文件: PNGImageReader.java
private void parse_hIST_chunk(int chunkLength) throws IOException,
    IIOException
{
    if (!metadata.PLTE_present) {
        throw new IIOException("hIST chunk without prior PLTE chunk!");
    }

    /* According to PNG specification length of
     * hIST chunk is specified in bytes and
     * hIST chunk consists of 2 byte elements
     * (so we expect length is even).
     */
    metadata.hIST_histogram = new char[chunkLength/2];
    stream.readFully(metadata.hIST_histogram,
                     0, metadata.hIST_histogram.length);

    metadata.hIST_present = true;
}
 
源代码13 项目: jdk1.8-source-analysis   文件: PNGImageReader.java
private void skipPass(int passWidth, int passHeight)
    throws IOException, IIOException  {
    if ((passWidth == 0) || (passHeight == 0)) {
        return;
    }

    int inputBands = inputBandsForColorType[metadata.IHDR_colorType];
    int bytesPerRow = (inputBands*passWidth*metadata.IHDR_bitDepth + 7)/8;

    // Read the image row-by-row
    for (int srcY = 0; srcY < passHeight; srcY++) {
        // Skip filter byte and the remaining row bytes
        pixelStream.skipBytes(1 + bytesPerRow);

        // If read has been aborted, just return
        // processReadAborted will be called later
        if (abortRequested()) {
            return;
        }
    }
}
 
/**
 * Resets the current stream byte and bit positions from the stack
 * of marked positions.
 *
 * <p> An <code>IOException</code> will be thrown if the previous
 * marked position lies in the discarded portion of the stream.
 *
 * @exception IOException if an I/O error occurs.
 */
public void reset() throws IOException {
    if (markByteStack.empty()) {
        return;
    }

    long pos = ((Long)markByteStack.pop()).longValue();
    if (pos < flushedPos) {
        throw new IIOException
            ("Previous marked position has been discarded!");
    }
    seek(pos);

    int offset = ((Integer)markBitStack.pop()).intValue();
    setBitOffset(offset);
}
 
源代码15 项目: dragonwell8_jdk   文件: JPEGBuffer.java
/**
 * Skips <code>count</code> bytes, leaving the buffer
 * in an appropriate state.  If the end of the stream is
 * encountered, an <code>IIOException</code> is thrown with the
 * message "Image Format Error".
 */
void skipData(int count) throws IOException {
    // First see what's left in the buffer.
    if (bufAvail >= count) {  // It's enough
        bufAvail -= count;
        bufPtr += count;
        return;
    }
    if (bufAvail > 0) {  // Some there, but not enough
        count -= bufAvail;
        bufAvail = 0;
        bufPtr = 0;
    }
    // Now read the rest directly from the stream
    if (iis.skipBytes(count) != count) {
        throw new IIOException ("Image format Error");
    }
}
 
源代码16 项目: TencentKona-8   文件: GIFImageWriter.java
private void writeCommentExtension(GIFWritableImageMetadata im)
  throws IOException {
    if (im.comments != null) {
        try {
            Iterator iter = im.comments.iterator();
            while (iter.hasNext()) {
                stream.write(0x21);
                stream.write(0xfe);
                writeBlocks((byte[])iter.next());
                stream.write(0x00);
            }
        } catch (IOException e) {
            throw new IIOException("I/O error writing Comment Extension!", e);
        }
    }
}
 
源代码17 项目: TencentKona-8   文件: MarkerSegment.java
/**
 * Constructor for creating <code>MarkerSegment</code>s by reading
 * from an <code>ImageInputStream</code>.
 */
MarkerSegment(JPEGBuffer buffer) throws IOException {

    buffer.loadBuf(3);  // tag plus length
    tag = buffer.buf[buffer.bufPtr++] & 0xff;
    length = (buffer.buf[buffer.bufPtr++] & 0xff) << 8;
    length |= buffer.buf[buffer.bufPtr++] & 0xff;
    length -= 2;  // JPEG length includes itself, we don't

    if (length < 0) {
        throw new IIOException("Invalid segment length: " + length);
    }
    buffer.bufAvail -= 3;
    // Now that we know the true length, ensure that we've got it,
    // or at least a bufferful if length is too big.
    buffer.loadBuf(length);
}
 
源代码18 项目: jdk1.8-source-analysis   文件: DQTMarkerSegment.java
Qtable(JPEGBuffer buffer) throws IIOException {
    elementPrecision = buffer.buf[buffer.bufPtr] >>> 4;
    tableID = buffer.buf[buffer.bufPtr++] & 0xf;
    if (elementPrecision != 0) {
        // IJG is compiled for 8-bits, so this shouldn't happen
        throw new IIOException ("Unsupported element precision");
    }
    data = new int [QTABLE_SIZE];
    // Read from zig-zag order to natural order
    for (int i = 0; i < QTABLE_SIZE; i++) {
        data[i] = buffer.buf[buffer.bufPtr+zigzag[i]] & 0xff;
    }
    buffer.bufPtr += QTABLE_SIZE;
}
 
源代码19 项目: TencentKona-8   文件: BMPImageReader.java
public IIOMetadata getImageMetadata(int imageIndex)
  throws IOException {
    checkIndex(imageIndex);
    if (metadata == null) {
        try {
            readHeader();
        } catch (IllegalArgumentException e) {
            throw new IIOException(I18N.getString("BMPImageReader6"), e);
        }
    }
    return metadata;
}
 
源代码20 项目: TencentKona-8   文件: GIFImageWriter.java
private void writeImageDescriptor(int imageLeftPosition,
                                  int imageTopPosition,
                                  int imageWidth,
                                  int imageHeight,
                                  boolean interlaceFlag,
                                  boolean sortFlag,
                                  int bitsPerPixel,
                                  byte[] localColorTable)
  throws IOException {

    try {
        stream.write(0x2c);

        stream.writeShort((short)imageLeftPosition);
        stream.writeShort((short)imageTopPosition);
        stream.writeShort((short)imageWidth);
        stream.writeShort((short)imageHeight);

        int packedFields = localColorTable != null ? 0x80 : 0x00;
        if (interlaceFlag) {
            packedFields |= 0x40;
        }
        if (sortFlag) {
            packedFields |= 0x8;
        }
        packedFields |= (bitsPerPixel - 1);
        stream.write(packedFields);

        if (localColorTable != null) {
            stream.write(localColorTable);
        }
    } catch (IOException e) {
        throw new IIOException("I/O error writing Image Descriptor!", e);
    }
}
 
源代码21 项目: TencentKona-8   文件: PNGImageReader.java
public int getHeight(int imageIndex) throws IIOException {
    if (imageIndex != 0) {
        throw new IndexOutOfBoundsException("imageIndex != 0!");
    }

    readHeader();

    return metadata.IHDR_height;
}
 
源代码22 项目: TencentKona-8   文件: ImageUtil.java
/** Checks that the provided <code>ImageWriter</code> can encode
 * the provided <code>ImageTypeSpecifier</code> or not.  If not, an
 * <code>IIOException</code> will be thrown.
 * @param writer The provided <code>ImageWriter</code>.
 * @param type The image to be tested.
 * @throws IIOException If the writer cannot encoded the provided image.
 */
public static final void canEncodeImage(ImageWriter writer,
                                        ImageTypeSpecifier type)
    throws IIOException {
    ImageWriterSpi spi = writer.getOriginatingProvider();

    if(type != null && spi != null && !spi.canEncodeImage(type))  {
        throw new IIOException(I18N.getString("ImageUtil2")+" "+
                               writer.getClass().getName());
    }
}
 
源代码23 项目: jdk1.8-source-analysis   文件: GIFImageReader.java
public int getWidth(int imageIndex) throws IIOException {
    checkIndex(imageIndex);

    int index = locateImage(imageIndex);
    if (index != imageIndex) {
        throw new IndexOutOfBoundsException();
    }
    readMetadata();
    return imageMetadata.imageWidth;
}
 
源代码24 项目: dragonwell8_jdk   文件: PNGImageReader.java
public int getWidth(int imageIndex) throws IIOException {
    if (imageIndex != 0) {
        throw new IndexOutOfBoundsException("imageIndex != 0!");
    }

    readHeader();

    return metadata.IHDR_width;
}
 
源代码25 项目: dragonwell8_jdk   文件: BMPImageReader.java
public int getHeight(int imageIndex) throws IOException {
    checkIndex(imageIndex);
    try {
        readHeader();
    } catch (IllegalArgumentException e) {
        throw new IIOException(I18N.getString("BMPImageReader6"), e);
    }
    return height;
}
 
源代码26 项目: TencentKona-8   文件: GIFImageReader.java
private int locateImage(int imageIndex) throws IIOException {
    readHeader();

    try {
        // Find closest known index
        int index = Math.min(imageIndex, imageStartPosition.size() - 1);

        // Seek to that position
        Long l = (Long)imageStartPosition.get(index);
        stream.seek(l.longValue());

        // Skip images until at desired index or last image found
        while (index < imageIndex) {
            if (!skipImage()) {
                --index;
                return index;
            }

            Long l1 = new Long(stream.getStreamPosition());
            imageStartPosition.add(l1);
            ++index;
        }
    } catch (IOException e) {
        throw new IIOException("Couldn't seek!", e);
    }

    if (currIndex != imageIndex) {
        imageMetadata = null;
    }
    currIndex = imageIndex;
    return imageIndex;
}
 
源代码27 项目: dragonwell8_jdk   文件: PNGImageReader.java
private void parse_sPLT_chunk(int chunkLength)
    throws IOException, IIOException {
    metadata.sPLT_paletteName = readNullTerminatedString("ISO-8859-1", 80);
    chunkLength -= metadata.sPLT_paletteName.length() + 1;

    int sampleDepth = stream.readUnsignedByte();
    metadata.sPLT_sampleDepth = sampleDepth;

    int numEntries = chunkLength/(4*(sampleDepth/8) + 2);
    metadata.sPLT_red = new int[numEntries];
    metadata.sPLT_green = new int[numEntries];
    metadata.sPLT_blue = new int[numEntries];
    metadata.sPLT_alpha = new int[numEntries];
    metadata.sPLT_frequency = new int[numEntries];

    if (sampleDepth == 8) {
        for (int i = 0; i < numEntries; i++) {
            metadata.sPLT_red[i] = stream.readUnsignedByte();
            metadata.sPLT_green[i] = stream.readUnsignedByte();
            metadata.sPLT_blue[i] = stream.readUnsignedByte();
            metadata.sPLT_alpha[i] = stream.readUnsignedByte();
            metadata.sPLT_frequency[i] = stream.readUnsignedShort();
        }
    } else if (sampleDepth == 16) {
        for (int i = 0; i < numEntries; i++) {
            metadata.sPLT_red[i] = stream.readUnsignedShort();
            metadata.sPLT_green[i] = stream.readUnsignedShort();
            metadata.sPLT_blue[i] = stream.readUnsignedShort();
            metadata.sPLT_alpha[i] = stream.readUnsignedShort();
            metadata.sPLT_frequency[i] = stream.readUnsignedShort();
        }
    } else {
        throw new IIOException("sPLT sample depth not 8 or 16!");
    }

    metadata.sPLT_present = true;
}
 
源代码28 项目: jdk1.8-source-analysis   文件: BMPImageReader.java
public int getHeight(int imageIndex) throws IOException {
    checkIndex(imageIndex);
    try {
        readHeader();
    } catch (IllegalArgumentException e) {
        throw new IIOException(I18N.getString("BMPImageReader6"), e);
    }
    return height;
}
 
源代码29 项目: jdk1.8-source-analysis   文件: BMPImageReader.java
public Iterator getImageTypes(int imageIndex)
  throws IOException {
    checkIndex(imageIndex);
    try {
        readHeader();
    } catch (IllegalArgumentException e) {
        throw new IIOException(I18N.getString("BMPImageReader6"), e);
    }
    ArrayList list = new ArrayList(1);
    list.add(new ImageTypeSpecifier(originalColorModel,
                                    originalSampleModel));
    return list.iterator();
}
 
源代码30 项目: jdk1.8-source-analysis   文件: BMPImageReader.java
public IIOMetadata getImageMetadata(int imageIndex)
  throws IOException {
    checkIndex(imageIndex);
    if (metadata == null) {
        try {
            readHeader();
        } catch (IllegalArgumentException e) {
            throw new IIOException(I18N.getString("BMPImageReader6"), e);
        }
    }
    return metadata;
}