@Test public void testWrite() throws IOException { List<IPTCEntry> entries = new ArrayList<>(); entries.add(new IPTCEntry(IPTC.TAG_KEYWORDS, new String[] {"Uno", "Due", "Tre"})); Directory iptc = new IPTCDirectory(entries); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); MemoryCacheImageOutputStream stream = new MemoryCacheImageOutputStream(bytes); createWriter().write(iptc, stream); stream.close(); Directory written = createReader().read(new ByteArrayImageInputStream(bytes.toByteArray())); assertEquals(iptc, written); } }
try { if(memoryImage!=null){ memoryImage.close();
@Test public void testRewriteExisting() throws IOException { IPTCReader reader = createReader(); Directory iptc = reader.read(getDataAsIIS()); assumeNotNull(iptc); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); MemoryCacheImageOutputStream stream = new MemoryCacheImageOutputStream(bytes); createWriter().write(iptc, stream); stream.close(); Directory written = reader.read(new ByteArrayImageInputStream(bytes.toByteArray())); assertEquals(iptc, written); }
public static void writeImage( OutputStream out, final BufferedImage image, final String format, final int quality ) throws IOException { final ImageWriter writer = getWriterByFormat( format ); final MemoryCacheImageOutputStream output = new MemoryCacheImageOutputStream( out ); writer.setOutput( output ); final ImageWriteParam params = writer.getDefaultWriteParam(); setCompressionQuality( params, quality ); writer.write( null, new IIOImage( image, null, null ), params ); writer.dispose(); output.close(); }
private void writeTo(OutputStream out) throws IOException { compress(); try { cacheout.set(out); long start = System.currentTimeMillis(); cache.seek(streamLength); cache.flushBefore(streamLength); if ((streamLength & 1) != 0) out.write(0); long end = System.currentTimeMillis(); LOG.debug("Flushed frame #{} from memory in {} ms", frameIndex + 1, end - start); } finally { try { cache.close(); } catch (IOException ignore) {} cache = null; } }
/** * This method gets the encoded image from the given object as a byte array * of data. */ protected byte[] extractImageEncoding(IIOImage iioimage, ImageWriteParam param) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); MemoryCacheImageOutputStream imageOutput = new MemoryCacheImageOutputStream( baos); writer.setOutput(imageOutput); writer.write(null, iioimage, writeParam); imageOutput.close(); baos.close(); byte[] data = baos.toByteArray(); // Write little endian raw data if( (!encapsulated) && bytes==2 && ! dos.getTransferSyntax().bigEndian() ) { for(int i=0; i<data.length; i+=2) { byte swap = data[i]; data[i] = data[i+1]; data[i+1] = swap; } } return data; }
private static PDImageXObject createFromGrayImage(BufferedImage image, PDDocument document) throws IOException { int height = image.getHeight(); int width = image.getWidth(); int[] rgbLineBuffer = new int[width]; int bpc = image.getColorModel().getPixelSize(); ByteArrayOutputStream baos = new ByteArrayOutputStream(((width*bpc/8)+(width*bpc%8 != 0 ? 1:0))*height); MemoryCacheImageOutputStream mcios = new MemoryCacheImageOutputStream(baos); for (int y = 0; y < height; ++y) { for (int pixel : image.getRGB(0, y, width, 1, rgbLineBuffer, 0, width)) { mcios.writeBits(pixel & 0xFF, bpc); } int bitOffset = mcios.getBitOffset(); if (bitOffset != 0) { mcios.writeBits(0, 8 - bitOffset); } } mcios.flush(); mcios.close(); return prepareImageXObject(document, baos.toByteArray(), image.getWidth(), image.getHeight(), bpc, PDDeviceGray.INSTANCE); }
/** * Writes the bits (if any) before to close the stream. */ @Override public void close() throws IOException { flushBits(); super.close(); } }
memOutStream.flush(); memOutStream.close(); } finally { writer.dispose();
writer.write(null, new IIOImage(finalImage, null, null), iwp); memOutStream.flush(); memOutStream.close(); writer.dispose();
public void testMagicNumber_bigEndian() throws Exception { _tiffHeader.setBigEndianOrder(true); final ByteArrayOutputStream stream = new ByteArrayOutputStream(); final MemoryCacheImageOutputStream ios = new MemoryCacheImageOutputStream(stream); _tiffHeader.write(ios); ios.close(); final byte[] bytes = stream.toByteArray(); assertEquals(0x00, bytes[2]); assertEquals(0x2a, bytes[3]); }
public void testMagicNumber_littleEndian() throws Exception { _tiffHeader.setBigEndianOrder(false); final ByteArrayOutputStream stream = new ByteArrayOutputStream(); final MemoryCacheImageOutputStream ios = new MemoryCacheImageOutputStream(stream); _tiffHeader.write(ios); ios.close(); final byte[] bytes = stream.toByteArray(); assertEquals(0x2a, bytes[2]); assertEquals(0x00, bytes[3]); }
public void testSetBigEndianOrder_littleEndian() throws Exception { _tiffHeader.setBigEndianOrder(false); final ByteArrayOutputStream stream = new ByteArrayOutputStream(); final MemoryCacheImageOutputStream ios = new MemoryCacheImageOutputStream(stream); _tiffHeader.write(ios); ios.close(); final byte[] bytes = stream.toByteArray(); assertEquals(0x49, bytes[0]); assertEquals(0x49, bytes[1]); }
public void testSetBigEndianOrder_bigEndian() throws Exception { _tiffHeader.setBigEndianOrder(true); final ByteArrayOutputStream stream = new ByteArrayOutputStream(); final MemoryCacheImageOutputStream ios = new MemoryCacheImageOutputStream(stream); _tiffHeader.write(ios); ios.close(); final byte[] bytes = stream.toByteArray(); assertEquals(0x4D, bytes[0]); assertEquals(0x4D, bytes[1]); }
public void testFirstIfdOffset_littleEndian() throws Exception { _tiffHeader.setBigEndianOrder(false); final ByteArrayOutputStream stream = new ByteArrayOutputStream(); final MemoryCacheImageOutputStream ios = new MemoryCacheImageOutputStream(stream); _tiffHeader.write(ios); ios.close(); final byte[] bytes = stream.toByteArray(); assertEquals(0x0a, bytes[4]); assertEquals(0x00, bytes[5]); assertEquals(0x00, bytes[6]); assertEquals(0x00, bytes[7]); }
public void testFirstIfdOffset_bigEndian() throws Exception { _tiffHeader.setBigEndianOrder(true); final ByteArrayOutputStream stream = new ByteArrayOutputStream(); final MemoryCacheImageOutputStream ios = new MemoryCacheImageOutputStream(stream); _tiffHeader.write(ios); ios.close(); final byte[] bytes = stream.toByteArray(); assertEquals(0x00, bytes[4]); assertEquals(0x00, bytes[5]); assertEquals(0x00, bytes[6]); assertEquals(0x0a, bytes[7]); } }
@Test public void testWrite() throws IOException { List<IPTCEntry> entries = new ArrayList<>(); entries.add(new IPTCEntry(IPTC.TAG_KEYWORDS, new String[] {"Uno", "Due", "Tre"})); Directory iptc = new IPTCDirectory(entries); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); MemoryCacheImageOutputStream stream = new MemoryCacheImageOutputStream(bytes); createWriter().write(iptc, stream); stream.close(); Directory written = createReader().read(new ByteArrayImageInputStream(bytes.toByteArray())); assertEquals(iptc, written); } }
@Test public void testRewriteExisting() throws IOException { IPTCReader reader = createReader(); Directory iptc = reader.read(getDataAsIIS()); assumeNotNull(iptc); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); MemoryCacheImageOutputStream stream = new MemoryCacheImageOutputStream(bytes); createWriter().write(iptc, stream); stream.close(); Directory written = reader.read(new ByteArrayImageInputStream(bytes.toByteArray())); assertEquals(iptc, written); }