javax.imageio.IIOException Java Examples
The following examples show how to use
javax.imageio.IIOException.
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: FilesystemScreenshotDebuggerTests.java From vividus with Apache License 2.0 | 6 votes |
@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))); }
Example #2
Source File: GIFImageWriter.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
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); } } }
Example #3
Source File: GIFImageWriter.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
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); } } } }
Example #4
Source File: ImageInputStreamImpl.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** * 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); }
Example #5
Source File: GIFImageWriter.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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); } } } }
Example #6
Source File: ImageInputStreamImpl.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * 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); }
Example #7
Source File: GIFImageReader.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
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; }
Example #8
Source File: JPEGBuffer.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * 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"); } }
Example #9
Source File: GIFImageWriter.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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); } } }
Example #10
Source File: PNGImageReader.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
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; } } }
Example #11
Source File: GIFImageWriter.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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); } } } }
Example #12
Source File: PNGImageReader.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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; }
Example #13
Source File: MarkerSegment.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * 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); }
Example #14
Source File: PNGImageWriter.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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(); }
Example #15
Source File: JPEGBuffer.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** * 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"); } }
Example #16
Source File: JPEGBuffer.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** * 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"); } }
Example #17
Source File: PNGImageReader.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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; }
Example #18
Source File: PNGImageReader.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
public int getWidth(int imageIndex) throws IIOException { if (imageIndex != 0) { throw new IndexOutOfBoundsException("imageIndex != 0!"); } readHeader(); return metadata.IHDR_width; }
Example #19
Source File: GIFImageReader.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public IIOMetadata getImageMetadata(int imageIndex) throws IIOException { checkIndex(imageIndex); int index = locateImage(imageIndex); if (index != imageIndex) { throw new IndexOutOfBoundsException("Bad image index!"); } readMetadata(); return imageMetadata; }
Example #20
Source File: JFIFMarkerSegment.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Add an ICC Profile APP2 segment by constructing it from * the given ICC_ColorSpace object. */ void addICC(ICC_ColorSpace cs) throws IOException { if (iccSegment != null) { throw new IIOException ("> 1 ICC APP2 Marker Segment not supported"); } iccSegment = new ICCMarkerSegment(cs); }
Example #21
Source File: JPEGBuffer.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Ensures that there are at least <code>count</code> bytes available * in the buffer, loading more data and moving any remaining * bytes to the front. A count of 0 means to just fill the buffer. * If the count is larger than the buffer size, just fills the buffer. * If the end of the stream is encountered before a non-0 count can * be satisfied, an <code>IIOException</code> is thrown with the * message "Image Format Error". */ void loadBuf(int count) throws IOException { if (debug) { System.out.print("loadbuf called with "); System.out.print("count " + count + ", "); System.out.println("bufAvail " + bufAvail + ", "); } if (count != 0) { if (bufAvail >= count) { // have enough return; } } else { if (bufAvail == BUFFER_SIZE) { // already full return; } } // First copy any remaining bytes down to the beginning if ((bufAvail > 0) && (bufAvail < BUFFER_SIZE)) { System.arraycopy(buf, bufPtr, buf, 0, bufAvail); } // Now fill the rest of the buffer int ret = iis.read(buf, bufAvail, buf.length - bufAvail); if (debug) { System.out.println("iis.read returned " + ret); } if (ret != -1) { bufAvail += ret; } bufPtr = 0; int minimum = Math.min(BUFFER_SIZE, count); if (bufAvail < minimum) { throw new IIOException ("Image Format Error"); } }
Example #22
Source File: BMPImageReader.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public boolean isRandomAccessEasy(int imageIndex) throws IOException { checkIndex(imageIndex); try { readHeader(); } catch (IllegalArgumentException e) { throw new IIOException(I18N.getString("BMPImageReader6"), e); } return metadata.compression == BI_RGB; }
Example #23
Source File: UserPluginMetadataFormatTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static BufferedImage getDestination(ImageReadParam param, Iterator imageTypes, int width, int height) throws IIOException { return ImageReader.getDestination(param, imageTypes, width, height); }
Example #24
Source File: BMPImageReader.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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(); }
Example #25
Source File: PNGImageReader.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public BufferedImage read(int imageIndex, ImageReadParam param) throws IIOException { if (imageIndex != 0) { throw new IndexOutOfBoundsException("imageIndex != 0!"); } readImage(param); return theImage; }
Example #26
Source File: JFIFMarkerSegment.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Add an ICC Profile APP2 segment by constructing it from * the given ICC_ColorSpace object. */ void addICC(ICC_ColorSpace cs) throws IOException { if (iccSegment != null) { throw new IIOException ("> 1 ICC APP2 Marker Segment not supported"); } iccSegment = new ICCMarkerSegment(cs); }
Example #27
Source File: GIFImageWriter.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private void writeGraphicControlExtension(int disposalMethod, boolean userInputFlag, boolean transparentColorFlag, int delayTime, int transparentColorIndex) throws IOException { try { stream.write(0x21); stream.write(0xf9); stream.write(4); int packedFields = (disposalMethod & 0x3) << 2; if (userInputFlag) { packedFields |= 0x2; } if (transparentColorFlag) { packedFields |= 0x1; } stream.write(packedFields); stream.writeShort((short)delayTime); stream.write(transparentColorIndex); stream.write(0x00); } catch (IOException e) { throw new IIOException("I/O error writing Graphic Control Extension!", e); } }
Example #28
Source File: WBMPImageReader.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public void readHeader() throws IOException { if (gotHeader) return; if (iis == null) { throw new IllegalStateException("Input source not set!"); } metadata = new WBMPMetadata(); wbmpType = iis.readByte(); // TypeField byte fixHeaderField = iis.readByte(); // check for valid wbmp image if (fixHeaderField != 0 || !isValidWbmpType(wbmpType)) { throw new IIOException(I18N.getString("WBMPImageReader2")); } metadata.wbmpType = wbmpType; // Read image width width = ReaderUtil.readMultiByteInteger(iis); metadata.width = width; // Read image height height = ReaderUtil.readMultiByteInteger(iis); metadata.height = height; gotHeader = true; }
Example #29
Source File: ImageUtil.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** 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()); } }
Example #30
Source File: PNGImageReader.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public BufferedImage read(int imageIndex, ImageReadParam param) throws IIOException { if (imageIndex != 0) { throw new IndexOutOfBoundsException("imageIndex != 0!"); } readImage(param); return theImage; }