/** * This method is a shorthand for {@link #copyStream(java.io.InputStream, java.io.OutputStream, int, long)} called * with a {@link Long#MAX_VALUE}. * * @param in the InputStream to read from * @param out the OutputStream to write to * @param bufferSize size of the buffer to use, in bytes * @return the number of bytes that were copied * @throws FileTransferException if something went wrong while reading from or writing to one of the provided streams */ public static long copyStream(InputStream in, OutputStream out, int bufferSize) throws FileTransferException { return copyStream(in, out, bufferSize, Long.MAX_VALUE); }
private void sendFile(InputStream in, URLConnection conn) throws IOException { conn.connect(); OutputStream out = conn.getOutputStream(); try { StreamUtils.copyStream(in, out, IO_BUFFER_SIZE); } finally { out.close(); } }
/** * This method is a shorthand for {@link #copyStream(java.io.InputStream, java.io.OutputStream, int)} called with a * {@link BufferPool#getDefaultBufferSize() default buffer size}. * * @param in the InputStream to read from * @param out the OutputStream to write to * @return the number of bytes that were copied * @throws FileTransferException if something went wrong while reading from or writing to one of the provided streams */ public static long copyStream(InputStream in, OutputStream out) throws FileTransferException { return copyStream(in, out, BufferPool.getDefaultBufferSize()); }
/** * Exports the specified theme to the specified output stream. * <p> * If <code>type</code> is equal to {@link Theme#USER_THEME}, the <code>name</code> argument will be ignored * as there is only one user theme. * </p> * <p> * This method differs from {@link #writeThemeData(ThemeData,OutputStream)} in that it doesn't only copy * the theme's data, but the whole content of the theme file, including comments. It also requires the theme * file to exist. * </p> * @param type type of the theme to export. * @param name name of the theme to export. * @param out where to write the theme. * @throws IOException if any I/O related error occurs. * @see #exportTheme(int,String,File) * @see #writeThemeData(ThemeData,OutputStream) */ public static void exportTheme(int type, String name, OutputStream out) throws IOException { InputStream in; // Where to read the theme from. in = null; try {StreamUtils.copyStream(in = getInputStream(type, name), out);} finally { if(in != null) { try {in.close();} catch(Exception e) {} } } }
StreamUtils.copyStream(pin, bout);
/** * Shorthand for {@link #copyStream(InputStream, OutputStream, byte[], long)} called with a buffer of the specified * size retrieved from {@link BufferPool}. * * @param in the InputStream to read from * @param out the OutputStream to write to * @param bufferSize size of the buffer to use, in bytes * @param length number of bytes to copy from InputStream * @return the number of bytes that were copied * @throws FileTransferException if something went wrong while reading from or writing to one of the provided streams */ public static long copyStream(InputStream in, OutputStream out, int bufferSize, long length) throws FileTransferException { // Use BufferPool to reuse any available buffer of the same size byte buffer[] = BufferPool.getByteArray(bufferSize); try { return copyStream(in, out, buffer, length); } finally { // Make the buffer available for further use BufferPool.releaseByteArray(buffer); } }
public static Theme importTheme(File file) throws IOException, Exception { String name; // Name of the new theme. OutputStream out; // Where to write the theme data to. InputStream in; // Where to read the theme data from. ThemeData data; // Makes sure the file contains a valid theme. data = readThemeData(file); // Initialisation. name = getAvailableCustomThemeName(file); out = null; in = null; // Imports the theme. try {StreamUtils.copyStream(in = new FileInputStream(file), out = getCustomThemeOutputStream(name));} // Cleanup. finally { if(in != null) { try {in.close();} catch(Exception e) {} } if(out != null) { try {out.close();} catch(Exception e) {} } } return new Theme(listener, data, Theme.CUSTOM_THEME, name); }
StreamUtils.copyStream(in, out, IO_BUFFER_SIZE);
/** * Tests {@link CompoundInputStream} in merged mode. * * @throws IOException should not happen. */ @Test public void testMerged() throws IOException { CompoundInputStream in = new IteratorCompoundInputStream(getTestInputStreamIterator(), true); assert in.isMerged(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); StreamUtils.copyStream(in, bout); assert TEST_FLATTENED_STRINGS.equals(bout.toString()); assert !in.advanceInputStream(); }
/** * Tests {@link CompoundInputStream} in unmerged mode. * * @throws IOException should not happen. */ @Test public void testUnmerged() throws IOException { CompoundInputStream in = new IteratorCompoundInputStream(getTestInputStreamIterator(), false); assert !in.isMerged(); for(int i=0; i<TEST_STRINGS.length; i++) { ByteArrayOutputStream bout = new ByteArrayOutputStream(); StreamUtils.copyStream(in, bout); assert TEST_STRINGS[i].equals(bout.toString()); // Try to advance to the next stream assert (i != TEST_STRINGS.length-1) == in.advanceInputStream(); } } }
StreamUtils.copyStream(fileIn, out64);
InputStream in = file.getInputStream(); setCurrentInputStream(in); StreamUtils.copyStream(in, out); } catch (IOException e) { LOGGER.debug("Caught exception", e);
StreamUtils.copyStream(in, archiver.createEntry(entryRelativePath, file)); in.close();
StreamUtils.copyStream(in, tempOut, IO_BUFFER_SIZE);
long written = StreamUtils.copyStream(origFileStream, out, BufferPool.getDefaultBufferSize(), partSize); sizeLeft -= written; } catch (FileTransferException e) {