/** * Copies the contents of the Reader into the Writer, until the end of the stream has been reached. This method uses a * buffer of 4096 kbyte. * * @param in the reader from which to read. * @param out the writer where the data is written to. * @throws java.io.IOException if a IOError occurs. */ public void copyWriter( final Reader in, final Writer out ) throws IOException { copyWriter( in, out, 4096 ); }
/** * Copies the contents of the Reader into the Writer, until the end of the stream has been reached. This method uses * a buffer of 4096 kbyte. * * @param in the reader from which to read. * @param out the writer where the data is written to. * @throws java.io.IOException if a IOError occurs. */ public void copyWriter(final Reader in, final Writer out) throws IOException { copyWriter(in, out, 4096); }
/** * Copies the given reader to the character stream. This method should be used for large chunks of data. * * @param reader the reader providing the text. * @throws IOException if there is a problem writing to the character stream. */ public void writeStream( final Reader reader ) throws IOException { IOUtils.getInstance().copyWriter( reader, writer ); support.setLineEmpty( false ); }
public void actionPerformed( final ActionEvent e ) { if ( resource == null ) { return; } if ( checkOverwriteText() ) { return; } try { InputStreamReader r = new InputStreamReader( resource.openStream(), "UTF-8" ); try { final StringWriter w = new StringWriter(); IOUtils.getInstance().copyWriter( r, w ); setText( w.toString() ); } finally { r.close(); } } catch ( IOException ex ) { logger.warn( "Unable to read template.", ex ); // NON-NLS } }
/** * 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 String readClob( final Clob 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 CLOB contains more than 2^31 characters. We cannot handle that." ); } final Reader inStream = clob.getCharacterStream(); final MemoryStringWriter outStream = new MemoryStringWriter( (int) length, 65536 ); try { IOUtils.getInstance().copyWriter( 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.toString(); }
try IOUtils.getInstance().copyWriter(inStream, outStream);
/** * @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(); } }