/** * Copy with default buffer size. * * @see #copy(java.io.OutputStream, java.io.InputStream) * @see #DEFAULT_BUFFER_SIZE */ public static void copy(OutputStream dest, InputStream source) throws IOException { copy(dest, source, DEFAULT_BUFFER_SIZE); }
/** * Read the contents of the given URL into a byte array. * * @param input * the URL to read * @return an array of bytes. * @throws IOException * in case of I/O error */ public static byte[] read(URL input) throws IOException { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(DEFAULT_BUFFER_SIZE); copy(byteStream, input); return byteStream.toByteArray(); }
/** * Read the contents of the given InputStream into a byte array. * * @param input * the InputStream to read * @return an array of bytes. * @throws IOException * in case of I/O error */ public static byte[] read(InputStream source) throws IOException { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(DEFAULT_BUFFER_SIZE); copy(byteStream, source); return byteStream.toByteArray(); }
/** * Copy from {@link URL} stream. * * @see #copy(java.io.OutputStream, java.io.InputStream, int) * @param dest * destination {@link OutputStream} * @param source * source {@link URL} */ public static void copy(OutputStream dest, URL source) throws IOException { InputStream urlStream = source.openStream(); copy(dest, urlStream); urlStream.close(); }
/** * Expand a Jar input stream. */ public static void extractJar(File dest, InputStream is) throws IOException { JarInputStream jis = new JarInputStream(is); JarEntry je; while ((je = jis.getNextJarEntry()) != null) { File outputFile = new File(dest, je.getName()); if (je.isDirectory()) { outputFile.mkdirs(); } else { outputFile.getParentFile().mkdirs(); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outputFile)); copy(bos, jis); bos.flush(); bos.close(); } jis.closeEntry(); } }
public static String doSend(URL u, InputStream is, String proxyServer, int proxyPort, String username, String password, String soapAction) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(8192); StreamUtils.copy(bos, is); String now = Long.toString(System.currentTimeMillis()); int c = 1;