public static void writeBytes(byte[] data, OutputStream out) throws IOException { transfer(new ByteArrayInputStream(data), out); }
public void writeTo(OutputStream out) throws IOException { try { OutputStreamWriter writer = new OutputStreamWriter(out, charset); IOUtil.transfer(contents, writer); writer.flush(); } finally { contents.close(); } } };
/** * Reads all bytes from the supplied input stream and returns them as a byte * array. * * @param in * The InputStream supplying the bytes. * @return A byte array containing all bytes from the supplied input stream. */ public static byte[] readBytes(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); transfer(in, out); return out.toByteArray(); }
/** * Writes all bytes from an <tt>InputStream</tt> to a file. * * @param in * The <tt>InputStream</tt> containing the data to write to the file. * @param file * The file to write the data to. * @return The total number of bytes written. * @throws IOException * If an I/O error occured while trying to write the data to the * file. */ public static final long transfer(InputStream in, File file) throws IOException { FileOutputStream out = new FileOutputStream(file); try { return transfer(in, out); } finally { out.close(); } }
/** * Store a resource to a file on the file system. * * @param resourceName * the name of the resource * @param output * the file to write to * @throws IOException * if there was a problem reading the resource or writing to the file */ public static void resourceToFile(String resourceName, File output) throws IOException { output.getParentFile().mkdirs(); InputStream in = ResourceUtil.class.getResourceAsStream(resourceName); OutputStream out = new FileOutputStream(output); IOUtil.transfer(in, out); }
/** * Writes all characters from a <tt>Reader</tt> to a file using the default * character encoding. * * @param reader * The <tt>Reader</tt> containing the data to write to the file. * @param file * The file to write the data to. * @return The total number of characters written. * @throws IOException * If an I/O error occured while trying to write the data to the * file. * @see java.io.FileWriter */ public static final long transfer(Reader reader, File file) throws IOException { FileWriter writer = new FileWriter(file); try { return transfer(reader, writer); } finally { writer.close(); } } }
/** * Writes all data that can be read from the supplied InputStream to the * specified file. * * @param in * An InputStream. * @param file * The file to write the data to. * @throws IOException * If an I/O error occurred. */ public static void writeStream(InputStream in, File file) throws IOException { FileOutputStream out = new FileOutputStream(file); try { transfer(in, out); } finally { try { out.flush(); } finally { out.close(); } } }
response.setContentLength(contentLength); IOUtil.transfer(content, out);
response.setContentLength(contentLength); IOUtil.transfer(content, out);