public static byte[] encodeImage( final Image image, final String mimeType, final float quality, final boolean alpha ) throws UnsupportedEncoderException, IOException { final MemoryByteArrayOutputStream byteOut = new MemoryByteArrayOutputStream( 65536, 65536 * 2 ); encodeImage( byteOut, image, mimeType, quality, alpha ); return byteOut.toByteArray(); }
/** * Write a portion of an array of characters. * * @param cbuf Array of characters * @param off Offset from which to start writing characters * @param len Number of characters to write * @throws java.io.IOException If an I/O error occurs */ public void write( final byte[] cbuf, final int off, final int len ) throws IOException { if ( len < 0 ) { throw new IllegalArgumentException(); } if ( off < 0 ) { throw new IndexOutOfBoundsException(); } if ( cbuf == null ) { throw new NullPointerException(); } if ( ( len + off ) > cbuf.length ) { throw new IndexOutOfBoundsException(); } ensureSize( cursor + len ); System.arraycopy( cbuf, off, this.buffer, cursor, len ); cursor += len; }
/** * Writes <code>b.length</code> bytes from the specified byte array to this output stream. The general contract for * <code>write(b)</code> is that it should have exactly the same effect as the call <code>write(b, 0, * b.length)</code>. * * @param b the data. * @throws java.io.IOException if an I/O error occurs. * @see java.io.OutputStream#write(byte[], int, int) */ public void write( final byte[] b ) throws IOException { write( b, 0, b.length ); }
protected byte[] executePageable( final MasterReport report ) throws IOException, ReportProcessingException { final MemoryByteArrayOutputStream outputStream = new MemoryByteArrayOutputStream(); try { final XmlPageOutputProcessor outputProcessor = new XmlPageOutputProcessor( outputStream, new XmlPageOutputProcessorMetaData( localFontRegistry ) ); final PageableReportProcessor streamReportProcessor = new PageableReportProcessor( report, outputProcessor ); try { streamReportProcessor.processReport(); } finally { streamReportProcessor.close(); } } finally { outputStream.close(); } return ( outputStream.toByteArray() ); }
private MasterReport saveAndLoad( final MasterReport originalReport ) throws Exception { final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream(); BundleWriter.writeReportToZipStream( originalReport, bout ); assertTrue( bout.getLength() > 0 ); /* * final File f = File.createTempFile("test-output-", ".prpt", new File ("test-output")); final FileOutputStream * outputStream = new FileOutputStream(f); outputStream.write(bout.toByteArray()); outputStream.close(); */ final ResourceManager mgr = new ResourceManager(); final Resource reportRes = mgr.createDirectly( bout.toByteArray(), MasterReport.class ); return (MasterReport) reportRes.getResource(); }
protected byte[] executeTablePage( final MasterReport report ) throws IOException, ReportProcessingException { final MemoryByteArrayOutputStream outputStream = new MemoryByteArrayOutputStream(); try { final XmlTableOutputProcessor outputProcessor = new XmlTableOutputProcessor( outputStream, new XmlTableOutputProcessorMetaData( XmlTableOutputProcessorMetaData.PAGINATION_FULL, localFontRegistry ) ); final ReportProcessor streamReportProcessor = new PageableReportProcessor( report, outputProcessor ); try { streamReportProcessor.processReport(); } finally { streamReportProcessor.close(); } } finally { outputStream.close(); } return ( outputStream.toByteArray() ); }
/** * Converts a SQL-Clob object into a String. If the Clob is larger than 2^31 characters, we cannot convert it. If * there are errors converting it, this method will log the cause and return null. * * @param clob the clob to be read as string. * @return the string or null in case of errors. */ public byte[] readBlob( final Blob clob ) throws IOException, SQLException { final long length = clob.length(); if ( length > Integer.MAX_VALUE ) { logger.warn( "This CLOB contains more than 2^31 characters. We cannot handle that." ); throw new IOException( "This BLOB contains more than 2^31 characters. We cannot handle that." ); } final InputStream inStream = clob.getBinaryStream(); final MemoryByteArrayOutputStream outStream = new MemoryByteArrayOutputStream( (int) length, 65536 ); try { IOUtils.getInstance().copyStreams( inStream, outStream ); } finally { try { inStream.close(); } catch ( IOException e ) { logger.warn( "Failed to close input stream. No worries, we will be alright anyway.", e ); } } return outStream.toByteArray(); } }
protected byte[] executeTableStream( final MasterReport report ) throws IOException, ReportProcessingException { final MemoryByteArrayOutputStream outputStream = new MemoryByteArrayOutputStream(); try { final XmlTableOutputProcessor outputProcessor = new XmlTableOutputProcessor( outputStream, new XmlTableOutputProcessorMetaData( XmlTableOutputProcessorMetaData.PAGINATION_NONE, localFontRegistry ) ); final ReportProcessor streamReportProcessor = new StreamReportProcessor( report, outputProcessor ); try { streamReportProcessor.processReport(); } finally { streamReportProcessor.close(); } } finally { outputStream.close(); } return ( outputStream.toByteArray() ); }
/** * Writes <code>b.length</code> bytes from the specified byte array to this output stream. The general contract for * <code>write(b)</code> is that it should have exactly the same effect as the call <code>write(b, 0, * b.length)</code>. * * @param b the data. * @throws java.io.IOException if an I/O error occurs. * @see java.io.OutputStream#write(byte[], int, int) */ public void write(final byte[] b) throws IOException { write(b, 0, b.length); }
/** * Write a portion of an array of characters. * * @param cbuf Array of characters * @param off Offset from which to start writing characters * @param len Number of characters to write * @throws java.io.IOException If an I/O error occurs */ public void write(final byte[] cbuf, final int off, final int len) throws IOException { if (len < 0) { throw new IllegalArgumentException(); } if (off < 0) { throw new IndexOutOfBoundsException(); } if (cbuf == null) { throw new NullPointerException(); } if ((len + off) > cbuf.length) { throw new IndexOutOfBoundsException(); } ensureSize(cursor + len); System.arraycopy(cbuf, off, this.buffer, cursor, len); cursor += len; }
/** * @noinspection IOResourceOpenedButNotSafelyClosed */ private byte[] extractData( final InputSource input ) throws IOException { final InputStream byteStream = input.getByteStream(); if ( byteStream != null ) { try { final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream(); IOUtils.getInstance().copyStreams( byteStream, bout ); return bout.toByteArray(); } finally { byteStream.close(); } } final Reader characterStream = input.getCharacterStream(); if ( characterStream == null ) { throw new IOException( "InputSource has neither an Byte nor a CharacterStream" ); } try { final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream(); final OutputStreamWriter owriter = new OutputStreamWriter( bout ); IOUtils.getInstance().copyWriter( characterStream, owriter ); owriter.close(); return bout.toByteArray(); } finally { characterStream.close(); } }
protected byte[] executeTableFlow( final MasterReport report ) throws IOException, ReportProcessingException { final MemoryByteArrayOutputStream outputStream = new MemoryByteArrayOutputStream(); try { final XmlTableOutputProcessor outputProcessor = new XmlTableOutputProcessor( outputStream, new XmlTableOutputProcessorMetaData( XmlTableOutputProcessorMetaData.PAGINATION_MANUAL, localFontRegistry ) ); final ReportProcessor streamReportProcessor = new FlowReportProcessor( report, outputProcessor ); try { streamReportProcessor.processReport(); } finally { streamReportProcessor.close(); } } finally { outputStream.close(); } return ( outputStream.toByteArray() ); }
/** * Writes the specified byte to this output stream. The general contract for <code>write</code> is that one byte is * written to the output stream. The byte to be written is the eight low-order bits of the argument <code>b</code>. * The 24 high-order bits of <code>b</code> are ignored. * <p/> * Subclasses of <code>OutputStream</code> must provide an implementation for this method. * * @param b the <code>byte</code>. * @throws java.io.IOException if an I/O error occurs. In particular, an <code>IOException</code> may be thrown if the * output stream has been closed. */ public void write( final int b ) throws IOException { this.singleIntArray[ 0 ] = (byte) ( 0xFF & b ); write( singleIntArray, 0, 1 ); }
final MemoryByteArrayOutputStream outStream = new MemoryByteArrayOutputStream((int) length, 65536); try return outStream.toByteArray();
public static byte[] createXmlTablePageable( final MasterReport report ) throws IOException, ReportProcessingException { final MemoryByteArrayOutputStream outputStream = new MemoryByteArrayOutputStream(); try { final LocalFontRegistry localFontRegistry = new LocalFontRegistry(); localFontRegistry.initialize(); final XmlTableOutputProcessor outputProcessor = new XmlTableOutputProcessor( outputStream, new XmlTableOutputProcessorMetaData( XmlTableOutputProcessorMetaData.PAGINATION_FULL, localFontRegistry ) ); final ReportProcessor streamReportProcessor = new PageableReportProcessor( report, outputProcessor ); try { streamReportProcessor.processReport(); } finally { streamReportProcessor.close(); } } finally { outputStream.close(); } return ( outputStream.toByteArray() ); }
/** * Writes the specified byte to this output stream. The general contract for <code>write</code> is that one byte is * written to the output stream. The byte to be written is the eight low-order bits of the argument <code>b</code>. * The 24 high-order bits of <code>b</code> are ignored. * <p/> * Subclasses of <code>OutputStream</code> must provide an implementation for this method. * * @param b the <code>byte</code>. * @throws java.io.IOException if an I/O error occurs. In particular, an <code>IOException</code> may be thrown if the * output stream has been closed. */ public void write(final int b) throws IOException { this.singleIntArray[0] = (byte) (0xFF & b); write(singleIntArray, 0, 1); }
final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream(); IOUtils.getInstance().copyStreams( postResult, bout ); return bout.toByteArray(); } finally { postResult.close();
protected void handleXmlContent( final byte[] reportOutput, final File goldSample ) throws Exception { final byte[] goldData; final InputStream goldInput = new BufferedInputStream( new FileInputStream( goldSample ) ); final MemoryByteArrayOutputStream goldByteStream = new MemoryByteArrayOutputStream( Math.min( 1024 * 1024, (int) goldSample.length() ), 1024 * 1024 ); try { IOUtils.getInstance().copyStreams( goldInput, goldByteStream ); goldData = goldByteStream.toByteArray(); if ( Arrays.equals( goldData, reportOutput ) ) { return; } } finally { goldInput.close(); } final Reader reader = new InputStreamReader( new ByteArrayInputStream( goldData ), "UTF-8" ); final ByteArrayInputStream inputStream = new ByteArrayInputStream( reportOutput ); final Reader report = new InputStreamReader( inputStream, "UTF-8" ); try { XMLAssert.assertXMLEqual( "File " + goldSample + " failed", new Diff( reader, report ), true ); } catch ( AssertionFailedError afe ) { debugOutput( reportOutput, goldSample ); throw afe; } finally { reader.close(); } }
public static MasterReport saveAndLoad( MasterReport report ) throws Exception { final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream(); BundleWriter.writeReportToZipStream( report, bout ); final ResourceManager mgr = new ResourceManager(); mgr.registerDefaults(); final Resource resource = mgr.createDirectly( bout.toByteArray(), MasterReport.class ); return (MasterReport) resource.getResource(); } }
public static DataFactory loadAndSaveOnReport( final DataFactory dataFactory ) throws IOException, BundleWriterException, ContentIOException, ResourceException { final MasterReport report = new MasterReport(); report.setDataFactory( dataFactory ); final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream(); BundleWriter.writeReportToZipStream( report, bout ); final ResourceManager mgr = new ResourceManager(); mgr.registerDefaults(); final Resource resource = mgr.createDirectly( bout.toByteArray(), MasterReport.class ); final MasterReport r2 = (MasterReport) resource.getResource(); return r2.getDataFactory(); }