@Override protected void readData(final ImageInputStream pInput) throws IOException { data = new byte[(int) size]; // TODO: Fix potential overflow, or document why that can't happen (read spec) pInput.readFully(data); }
protected void readData(final ImageInputStream pInput) throws IOException { // TODO: This design is ugly, as subclasses readData is invoked BEFORE their respective constructor... data = new byte[(int) size]; pInput.readFully(data); }
private static byte[] readSegment(final int marker, final int length, final ImageInputStream stream) throws IOException { byte[] data = new byte[length]; data[0] = (byte) ((marker >> 8) & 0xff); data[1] = (byte) (marker & 0xff); data[2] = (byte) (((length - 2) >> 8) & 0xff); data[3] = (byte) ((length - 2) & 0xff); stream.readFully(data, 4, length - 4); return data; }
private byte[] readHUFFTable() throws IOException { byte[] lengths = new byte[16]; stream.readFully(lengths); int numCodes = 0; for (int i = 0; i < lengths.length; i++) { numCodes += ((int) lengths[i]) & 0xff; } byte table[] = new byte[16 + numCodes]; System.arraycopy(lengths, 0, table, 0, 16); stream.readFully(table, 16, numCodes); return table; }
private static void readFully(final DataInput input, final float[] floats) throws IOException { if (input instanceof ImageInputStream) { // Optimization for ImageInputStreams, read all in one go ((ImageInputStream) input).readFully(floats, 0, floats.length); } else { for (int i = 0; i < floats.length; i++) { floats[i] = input.readFloat(); } } }
private void readFully(final DataInput input, final int[] rowDataInt) throws IOException { if (input instanceof ImageInputStream) { ImageInputStream imageInputStream = (ImageInputStream) input; imageInputStream.readFully(rowDataInt, 0, rowDataInt.length); } else { for (int k = 0; k < rowDataInt.length; k++) { rowDataInt[k] = input.readInt(); } } }
private static void readFully(final DataInput input, final int[] ints) throws IOException { if (input instanceof ImageInputStream) { // Optimization for ImageInputStreams, read all in one go ((ImageInputStream) input).readFully(ints, 0, ints.length); } else { for (int i = 0; i < ints.length; i++) { ints[i] = input.readInt(); } } }
private static void readFully(final DataInput input, final short[] shorts) throws IOException { if (input instanceof ImageInputStream) { // Optimization for ImageInputStreams, read all in one go ((ImageInputStream) input).readFully(shorts, 0, shorts.length); } else { for (int i = 0; i < shorts.length; i++) { shorts[i] = input.readShort(); } } }
private static void readFully(final DataInput input, final short[] shorts) throws IOException { if (input instanceof ImageInputStream) { // Optimization for ImageInputStreams, read all in one go ((ImageInputStream) input).readFully(shorts, 0, shorts.length); } else { for (int i = 0; i < shorts.length; i++) { shorts[i] = input.readShort(); } } }
private static void readFully(final DataInput input, final short[] shorts) throws IOException { if (input instanceof ImageInputStream) { // Optimization for ImageInputStreams, read all in one go ((ImageInputStream) input).readFully(shorts, 0, shorts.length); } else { for (int i = 0; i < shorts.length; i++) { shorts[i] = input.readShort(); } } }
private static void readFully(final DataInput input, final short[] shorts) throws IOException { if (input instanceof ImageInputStream) { // Optimization for ImageInputStreams, read all in one go ((ImageInputStream) input).readFully(shorts, 0, shorts.length); } else { for (int i = 0; i < shorts.length; i++) { shorts[i] = input.readShort(); } } }
private void readFully(final DataInput input, final float[] rowDataFloat) throws IOException { if (input instanceof ImageInputStream) { ImageInputStream imageInputStream = (ImageInputStream) input; imageInputStream.readFully(rowDataFloat, 0, rowDataFloat.length); } else { for (int k = 0; k < rowDataFloat.length; k++) { rowDataFloat[k] = input.readFloat(); } } }
private void readFully(final DataInput input, final short[] rowDataShort) throws IOException { if (input instanceof ImageInputStream) { ImageInputStream imageInputStream = (ImageInputStream) input; imageInputStream.readFully(rowDataShort, 0, rowDataShort.length); } else { for (int k = 0; k < rowDataShort.length; k++) { rowDataShort[k] = input.readShort(); } } }
private static String readString(final ImageInputStream stream, final int maxLength) throws IOException { byte[] data = new byte[maxLength]; stream.readFully(data); return asZeroTerminatedASCIIString(data); }
private void writeData(ImageInputStream input, ImageOutputStream output, long offset, long length) throws IOException { input.seek(offset); byte[] buffer = new byte[(int) length]; stream.readFully(buffer); output.write(buffer); }
@Test(expected = IIOException.class) public void testStreamNonJPEGArray() throws IOException { ImageInputStream stream = new JPEGSegmentImageInputStream(ImageIO.createImageInputStream(new ByteArrayInputStream(new byte[] {42, 42, 0, 0, 77, 99}))); stream.readFully(new byte[1]); }
@Test(expected = IIOException.class) public void testStreamEmptyArray() throws IOException { ImageInputStream stream = new JPEGSegmentImageInputStream(ImageIO.createImageInputStream(new ByteArrayInputStream(new byte[0]))); stream.readFully(new byte[1]); }
PSDGlobalLayerMask(final ImageInputStream pInput, final long globalLayerMaskLength) throws IOException { colorSpace = pInput.readUnsignedShort(); // Undocumented pInput.readFully(colors, 0, colors.length); opacity = pInput.readUnsignedShort(); // 0-100 // Kind: 0: Selected (ie inverted), 1: Color protected, 128: Use value stored per layer (actually, the value is 80, not 0x80) kind = pInput.readUnsignedByte(); // Skip "Variable: Filler zeros" pInput.skipBytes(globalLayerMaskLength - 17); }
@Test public void testReadResetRead() throws IOException { ImageInputStream stream = new SubImageInputStream(createStream(32), 16); stream.mark(); byte[] first = new byte[16]; stream.readFully(first); stream.reset(); byte[] second = new byte[16]; stream.readFully(second); assertTrue(Arrays.equals(first, second)); }
@Test public void testSimplePath() throws IOException { // We'll read this from a real file, with hardcoded offsets for simplicity // PSD IRB: offset: 34, length: 32598 // Clipping path: offset: 31146, length: 1248 ImageInputStream stream = PathsTest.resourceAsIIOStream("/psd/grape_with_path.psd"); stream.seek(34 + 31146); byte[] data = new byte[1248]; stream.readFully(data); Path2D path = new AdobePathBuilder(data).path(); assertNotNull(path); assertPathEquals(path, readExpectedPath("/ser/grape-path.ser")); }