/** * Copies the InputStream into the OutputStream, until the end of the stream has been reached. This method uses a * buffer of 4096 kbyte. * * @param in the inputstream from which to read. * @param out the outputstream where the data is written to. * @throws java.io.IOException if a IOError occurs. */ public void copyStreams( final InputStream in, final OutputStream out ) throws IOException { copyStreams( in, out, 4096 ); }
/** * Copies the InputStream into the OutputStream, until the end of the stream has been reached. This method uses a * buffer of 4096 kbyte. * * @param in the inputstream from which to read. * @param out the outputstream where the data is written to. * @throws java.io.IOException if a IOError occurs. */ public void copyStreams(final InputStream in, final OutputStream out) throws IOException { copyStreams(in, out, 4096); }
protected byte[] loadData( final String name ) { final InputStream stream = ObjectUtilities.getResourceAsStream( name, getClass() ); if ( stream == null ) { return null; } try { try { final ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.getInstance().copyStreams( stream, out ); return out.toByteArray(); } finally { stream.close(); } } catch ( IOException e ) { e.printStackTrace(); return null; } }
public void writeContent( final ZipEntry entry, final InputStream in, final int method, final int compression ) throws IOException { zipOutputStream.setMethod( method ); zipOutputStream.setLevel( compression ); zipOutputStream.putNextEntry( entry ); IOUtils.getInstance().copyStreams( in, zipOutputStream ); zipOutputStream.closeEntry(); } }
/** * 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(); } }
public static String getBundleType( final Repository repository ) { if ( repository == null ) { throw new NullPointerException(); } try { final ContentEntity mimeTypeContentEntity = repository.getRoot().getEntry( "mimetype" ); if ( mimeTypeContentEntity instanceof ContentItem ) { final ContentItem mimeTypeItem = (ContentItem) mimeTypeContentEntity; final ByteArrayOutputStream bout = new ByteArrayOutputStream(); final InputStream in = mimeTypeItem.getInputStream(); try { IOUtils.getInstance().copyStreams( in, bout ); } finally { in.close(); } return bout.toString( "ASCII" ); } return null; } catch ( Exception e ) { return null; } }
try IOUtils.getInstance().copyStreams(inStream, outStream);
final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { IOUtils.getInstance().copyStreams( in, out );
final DeflaterOutputStream dos = new DeflaterOutputStream( bos, def ); try { IOUtils.getInstance().copyStreams( zipIn, dos ); dos.flush(); } finally {
public byte[] getResource( final ResourceManager caller ) throws ResourceLoadingException { try { final InputStream in = getResourceAsStream( caller ); if ( in == null ) { throw new ResourceLoadingException( "Unable to read Stream: No input stream: " + getKey() ); } try { final ByteArrayOutputStream bout = new ByteArrayOutputStream(); IOUtils.getInstance().copyStreams( in, bout ); return bout.toByteArray(); } finally { in.close(); } } catch ( ResourceLoadingException rle ) { throw rle; } catch ( IOException e ) { throw new ResourceLoadingException( "Unable to read Stream: ", e ); } }
final OutputStream outStream = bundle.createEntry( targetPath, contentType ); try { IOUtils.getInstance().copyStreams( stream, outStream ); } finally { outStream.close();
final DeflaterOutputStream dos = new DeflaterOutputStream( bos, def ); try { IOUtils.getInstance().copyStreams( zipIn, dos ); dos.flush(); } finally {
/** * @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(); } }
final OutputStream out = documentBundle.createEntry( name, mimeType ); try { IOUtils.getInstance().copyStreams( in, out ); } finally { try {
try { final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream(); IOUtils.getInstance().copyStreams( postResult, bout ); return bout.toByteArray(); } finally {
final OutputStream outputStream = new BufferedOutputStream( item.getOutputStream() ); try { IOUtils.getInstance().copyStreams( stream, outputStream ); } finally { outputStream.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(); } }
final InputStream inStream = sourceBundle.getEntryAsStream( entryName ); try { IOUtils.getInstance().copyStreams( inStream, dataStream ); } finally { inStream.close();
final InputStream inStream = sourceBundle.getEntryAsStream( entryName ); try { IOUtils.getInstance().copyStreams( inStream, dataStream ); } finally { inStream.close();
final InputStream inputStream = item.getInputStream(); try { IOUtils.getInstance().copyStreams( inputStream, outputStream ); } finally { inputStream.close();