/** * Copy bytes from an <code>InputStream</code> to chars on a <code>Writer</code> using the default character * encoding of the platform. * <p> * This method buffers the input internally, so there is no need to use a <code>BufferedInputStream</code>. * <p> * This method uses {@link InputStreamReader}. * * @param input the <code>InputStream</code> to read from * @param output the <code>Writer</code> to write to * @throws NullPointerException if the input or output is null * @throws IOException if an I/O error occurs * @since Commons IO 1.1 */ public static void copy( InputStream input, Writer output ) throws IOException { InputStreamReader in = new InputStreamReader( input ); copy( in, output ); }
/** * Get the contents of a <code>Reader</code> as a String. * <p> * This method buffers the input internally, so there is no need to use a <code>BufferedReader</code>. * * @param input the <code>Reader</code> to read from * @return the requested String * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs */ public static String toString( Reader input ) throws IOException { StringWriter sw = new StringWriter(); copy( input, sw ); return sw.toString(); }
/** * Get the contents of a <code>Reader</code> as a character array. * <p> * This method buffers the input internally, so there is no need to use a <code>BufferedReader</code>. * * @param input the <code>Reader</code> to read from * @return the requested character array * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs * @since Commons IO 1.1 */ public static char[] toCharArray( Reader input ) throws IOException { CharArrayWriter sw = new CharArrayWriter(); copy( input, sw ); return sw.toCharArray(); }
/** * Get the contents of an <code>InputStream</code> as a String using the default character encoding of the platform. * <p> * This method buffers the input internally, so there is no need to use a <code>BufferedInputStream</code>. * * @param input the <code>InputStream</code> to read from * @return the requested String * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs */ public static String toString( InputStream input ) throws IOException { StringWriter sw = new StringWriter(); copy( input, sw ); return sw.toString(); }
/** * Get the contents of an <code>InputStream</code> as a character array using the default character encoding of the * platform. * <p> * This method buffers the input internally, so there is no need to use a <code>BufferedInputStream</code>. * * @param is the <code>InputStream</code> to read from * @return the requested character array * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs * @since Commons IO 1.1 */ public static char[] toCharArray( InputStream is ) throws IOException { CharArrayWriter output = new CharArrayWriter(); copy( is, output ); return output.toCharArray(); }
/** * Get the contents of an <code>InputStream</code> as a String using the specified character encoding. * <p> * Character encoding names can be found at <a href="http://www.iana.org/assignments/character-sets">IANA</a>. * <p> * This method buffers the input internally, so there is no need to use a <code>BufferedInputStream</code>. * * @param input the <code>InputStream</code> to read from * @param encoding the encoding to use, null means platform default * @return the requested String * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs */ public static String toString( InputStream input, String encoding ) throws IOException { StringWriter sw = new StringWriter(); copy( input, sw, encoding ); return sw.toString(); }
/** * Get the contents of a <code>Reader</code> as a character array. * <p> * This method buffers the input internally, so there is no need to use a * <code>BufferedReader</code>. * * @param input * the <code>Reader</code> to read from * @return the requested character array * @throws NullPointerException * if the input is null * @throws IOException * if an I/O error occurs * @since Commons IO 1.1 */ public static char[] toCharArray(Reader input) throws IOException { CharArrayWriter sw = new CharArrayWriter(); copy(input, sw); return sw.toCharArray(); }
/** * Get the contents of an <code>InputStream</code> as a String using the * default character encoding of the platform. * <p> * This method buffers the input internally, so there is no need to use a * <code>BufferedInputStream</code>. * * @param input * the <code>InputStream</code> to read from * @return the requested String * @throws NullPointerException * if the input is null * @throws IOException * if an I/O error occurs */ public static String toString(InputStream input) throws IOException { StringWriter sw = new StringWriter(); copy(input, sw); return sw.toString(); }
/** * Get the contents of a <code>Reader</code> as a String. * <p> * This method buffers the input internally, so there is no need to use a * <code>BufferedReader</code>. * * @param input * the <code>Reader</code> to read from * @return the requested String * @throws NullPointerException * if the input is null * @throws IOException * if an I/O error occurs */ public static String toString(Reader input) throws IOException { StringWriter sw = new StringWriter(); copy(input, sw); return sw.toString(); }
/** * Get the contents of an <code>InputStream</code> as a character array using the specified character encoding. * <p> * Character encoding names can be found at <a href="http://www.iana.org/assignments/character-sets">IANA</a>. * <p> * This method buffers the input internally, so there is no need to use a <code>BufferedInputStream</code>. * * @param is the <code>InputStream</code> to read from * @param encoding the encoding to use, null means platform default * @return the requested character array * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs * @since Commons IO 1.1 */ public static char[] toCharArray( InputStream is, String encoding ) throws IOException { CharArrayWriter output = new CharArrayWriter(); copy( is, output, encoding ); return output.toCharArray(); }
/** * Get the contents of an <code>InputStream</code> as a character array * using the default character encoding of the platform. * <p> * This method buffers the input internally, so there is no need to use a * <code>BufferedInputStream</code>. * * @param is * the <code>InputStream</code> to read from * @return the requested character array * @throws NullPointerException * if the input is null * @throws IOException * if an I/O error occurs * @since Commons IO 1.1 */ public static char[] toCharArray(InputStream is) throws IOException { CharArrayWriter output = new CharArrayWriter(); copy(is, output); return output.toCharArray(); }
public static void generateDocumentZipEntry( IXDocReport report, InputStream documentIn, IContext dumpContext, ZipOutputStream out, String src ) throws IOException { String documentFileName = getDocumentFileName( report, dumpContext ); ZipEntry zipEntry = new ZipEntry( src + "/" + documentFileName ); out.putNextEntry( zipEntry ); try { IOUtils.copy( documentIn, out ); } finally { out.closeEntry(); } }
public static void generateDocumentFile( IXDocReport report, InputStream documentIn, IContext dumpContext, File srcDir ) throws FileNotFoundException, IOException { String documentFileName = getDocumentFileName( report, dumpContext ); File documentFile = new File( srcDir, documentFileName ); documentFile.getParentFile().mkdirs(); OutputStream documentOut = null; try { documentOut = new FileOutputStream( documentFile ); IOUtils.copy( documentIn, documentOut ); } finally { if ( documentOut != null ) { IOUtils.closeQuietly( documentOut ); } } }
public void write( OutputStream outputStream ) throws IOException { InputStream inputStream = null; try { inputStream = getInputStream(); IOUtils.copy( inputStream, outputStream ); } finally { IOUtils.closeQuietly( inputStream ); } }
/** * Set the given input stream in the given entry of the document archive. * * @param archive * @param inputStream * @throws IOException */ public static void setEntry( XDocArchive archive, String entryName, InputStream input ) throws IOException { // entry name must uses '/' (see https://code.google.com/p/xdocreport/issues/detail?id=234) if ( entryName.indexOf( "\\" ) != -1 ) { entryName = StringUtils.replaceAll( entryName, "\\", "/" ); } // 1) Create empty output stream and register it with the entry // name OutputStream output = archive.getEntryOutputStream( entryName ); // 2) Copy original stream form the input stream to the empty output stream IOUtils.copy( input, output ); output.close(); }
/** * Get the contents of an <code>InputStream</code> as a <code>byte[]</code>. * <p> * This method buffers the input internally, so there is no need to use a <code>BufferedInputStream</code>. * * @param input the <code>InputStream</code> to read from * @return the requested byte array * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs */ public static byte[] toByteArray( InputStream input ) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); copy( input, output ); return output.toByteArray(); }
/** * Get the contents of a <code>Reader</code> as a <code>byte[]</code> using the default character encoding of the * platform. * <p> * This method buffers the input internally, so there is no need to use a <code>BufferedReader</code>. * * @param input the <code>Reader</code> to read from * @return the requested byte array * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs */ public static byte[] toByteArray( Reader input ) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); copy( input, output ); return output.toByteArray(); }
/** * Get the contents of a <code>Reader</code> as a <code>byte[]</code> using * the default character encoding of the platform. * <p> * This method buffers the input internally, so there is no need to use a * <code>BufferedReader</code>. * * @param input * the <code>Reader</code> to read from * @return the requested byte array * @throws NullPointerException * if the input is null * @throws IOException * if an I/O error occurs */ public static byte[] toByteArray(Reader input) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); copy(input, output); return output.toByteArray(); }
/** * Get the contents of an <code>InputStream</code> as a <code>byte[]</code>. * <p> * This method buffers the input internally, so there is no need to use a * <code>BufferedInputStream</code>. * * @param input * the <code>InputStream</code> to read from * @return the requested byte array * @throws NullPointerException * if the input is null * @throws IOException * if an I/O error occurs */ public static byte[] toByteArray(InputStream input) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); copy(input, output); return output.toByteArray(); }
/** * Get the contents of a <code>Reader</code> as a <code>byte[]</code> using the specified character encoding. * <p> * Character encoding names can be found at <a href="http://www.iana.org/assignments/character-sets">IANA</a>. * <p> * This method buffers the input internally, so there is no need to use a <code>BufferedReader</code>. * * @param input the <code>Reader</code> to read from * @param encoding the encoding to use, null means platform default * @return the requested byte array * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs * @since Commons IO 1.1 */ public static byte[] toByteArray( Reader input, String encoding ) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); copy( input, output, encoding ); return output.toByteArray(); }