/** * Copies all the bytes it can read from the input stream into the output * stream; input and output streams management (opening, flushing, closing) * are all up to the caller. * * @param input * an open and ready-to-be-read input stream. * @param output * an open output stream. * @return * the total number of bytes copied. * @throws IOException */ public static long copy(InputStream input, OutputStream output) throws IOException { return copy(input, output, false); }
/** * Copies all the bytes it can read from the input stream into the output * stream; input and output streams management (opening, flushing, closing) * are all up to the caller. * * @param input * an open and ready-to-be-read input stream. * @param output * an open output stream. * @return * the total number of bytes copied. * @throws IOException */ public static long copy(InputStream input, OutputStream output) throws IOException { return copy(input, output, false); }
/** * Copies all the bytes it can read from the input stream into the output * stream; input and output streams management (opening, flushing, closing) * are all up to the caller. * * @param input * an open and ready-to-be-read input stream. * @param output * an open output stream. * @return * the total number of bytes copied. * @throws IOException */ public static long copy(InputStream input, OutputStream output) throws IOException { return copy(input, output, false); }
/** * Adds a file to the ZIP archive, given its content as an input stream. * * @param zipEntry * name of the entry in the archive. * @param input * the stream from which data will be read to be added to the ZIP archive; * the stream must be open and will not be closed once the operation is * complete, so it is up to the caller to release it. */ public void addFile(String zipEntry, InputStream input) throws IOException { if(input != null) { stream.putNextEntry(new ZipEntry(zipEntry)); Streams.copy(input, stream); } }
/** * Dumps the response data as a string. * * @see java.lang.Object#toString() */ @Override public String toString() { try(InputStream input = connection.getInputStream(); ByteArrayOutputStream output = new ByteArrayOutputStream()) { Streams.copy(input, output); String data = new String(output.toByteArray()); // logger.trace("response data:\n{}", data); return data; } catch (IOException e) { logger.error("error reading response data from stream", e); } return null; } }
try (InputStream input = handler.getAsStream(); OutputStream output = storage.store(resource)) { if(input != null) { long copied = Streams.copy(input, output); logger.trace("... stored {} bytes for resource '{}'", copied, resource); break lookup;
if(input != null) { output = new ByteArrayOutputStream(); long copied = Streams.copy(input, output); logger.trace("copied {} bytes from cache", copied); return output.toByteArray();
/** * Copies data from one resource to another, possibly replacing the destination * resource if one exists. * * @param source * the name of the source resource. * @param destination * the name of the destination resource * @return * the cache itself, for method chaining. */ public Cache copyAs(String source, String destination) throws CacheException { if(!Strings.areValid(source, destination)) { logger.error("invalid input parameters for copy from '{}' to '{}'", source, destination); throw new CacheException("invalid input parameters (source: '" + source + "', destination: '" + destination + "')"); } try (InputStream input = storage.retrieve(source); OutputStream output = storage.store(destination)) { long copied = Streams.copy(input, output); logger.trace("copied {} bytes from '{}' to '{}'", copied, source, destination); } catch (IOException e) { logger.error("error copying from '" + source + "' to '" + destination + "'", e); throw new CacheException("error copying from '" + source + "' to '" + destination + "'", e); } return this; }
if(output != null) { input = new ByteArrayInputStream(data); long copied = Streams.copy(input, output); logger.trace("copied {} bytes into cache", copied); return copied;
stream.writeBytes("Content-Transfer-Encoding: binary" + NEWLINE); stream.writeBytes(NEWLINE); Streams.copy(((HttpFileParameter)parameter).getInputStream(), stream); stream.writeBytes(NEWLINE); break;