/** * Writes the input stream to the output stream. Input is done without a Reader object, meaning * that the input is copied in its raw form. * * @param in * The input stream * @param out * The output stream * @return Number of bytes copied from one stream to the other * @throws IOException */ public static int copy(final InputStream in, final OutputStream out) throws IOException { return copy(in, out, 4096); }
/** * Writes the input stream to the output stream. Input is done without a Reader object, meaning * that the input is copied in its raw form. * * @param in * The input stream * @param out * The output stream * @return Number of bytes copied from one stream to the other * @throws IOException */ public static int copy(final InputStream in, final OutputStream out) throws IOException { return copy(in, out, 4096); }
/** * Writes the given input stream to the given file * * @param file * The file to write to * @param input * The input * @return Number of bytes written * @throws IOException */ public static final int writeTo(final java.io.File file, final InputStream input) throws IOException { final FileOutputStream out = new FileOutputStream(file); try { return Streams.copy(input, out); } finally { out.close(); } }
/** * Writes the node data to the specified output stream. * * @param stream * @throws IOException */ public void writeData(OutputStream stream) throws IOException { Streams.copy(getDataAsStream(), stream); }
/** * Writes the given input stream to the given file * * @param file * The file to write to * @param input * The input * @param bufSize * The memory buffer size. 4096 is a good value. * @return Number of bytes written * @throws IOException */ public static int writeTo(final java.io.File file, final InputStream input, final int bufSize) throws IOException { final FileOutputStream out = new FileOutputStream(file); try { return Streams.copy(input, out, bufSize); } finally { out.close(); } }
/** * Writes the given input stream to the given file * * @param file * The file to write to * @param input * The input * @param bufSize * The memory buffer size. 4096 is a good value. * @return Number of bytes written * @throws IOException */ public static final int writeTo(final java.io.File file, final InputStream input, final int bufSize) throws IOException { final FileOutputStream out = new FileOutputStream(file); try { return Streams.copy(input, out, bufSize); } finally { out.close(); } }
/** * Copies a resource from classpath to a {@link java.io.File} * * @param source classpath to resource * @param destination destination file */ public static void copyClassResourceToFile(String source, java.io.File destination) { final InputStream in = JcrUtils.class.getResourceAsStream(source); if (in == null) { throw new RuntimeException("Class resource: " + source + " does not exist"); } try { final FileOutputStream fos = new FileOutputStream(destination); Streams.copy(in, fos); fos.close(); in.close(); } catch (IOException e) { throw new RuntimeException("Could not copy class resource: " + source + " to destination: " + destination.getAbsolutePath()); } }
/** * Copies a resource from classpath to a {@link java.io.File} * * @param source classpath to resource * @param destination destination file */ public static void copyClassResourceToFile(String source, java.io.File destination) { final InputStream in = JcrUtils.class.getResourceAsStream(source); if (in == null) { throw new RuntimeException("Class resource: " + source + " does not exist"); } try { final FileOutputStream fos = new FileOutputStream(destination); Streams.copy(in, fos); fos.close(); in.close(); } catch (IOException e) { throw new RuntimeException("Could not copy class resource: " + source + " to destination: " + destination.getAbsolutePath()); } }
/** * Reads the state of this object during deserialization. * * @param in * The stream from which the state should be read. * * @throws IOException * if an error occurs. * @throws ClassNotFoundException * if class cannot be found. */ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { // read values in.defaultReadObject(); OutputStream output = getOutputStream(); if (cachedContent != null) { output.write(cachedContent); } else { FileInputStream input = new FileInputStream(dfosFile); Streams.copy(input, output); dfosFile.delete(); dfosFile = null; } output.close(); cachedContent = null; }
/** * Convenience method to write an {@link InputStream} to response. * * @param attributes * request attributes * @param stream * input stream */ protected final void writeStream(Attributes attributes, InputStream stream) throws IOException { final Response response = attributes.getResponse(); Streams.copy(stream, response.getOutputStream()); } }
/** * Convenience method to write an {@link InputStream} to response. * * @param attributes * request attributes * @param stream * input stream */ protected final void writeStream(Attributes attributes, InputStream stream) throws IOException { final Response response = attributes.getResponse(); Streams.copy(stream, response.getOutputStream()); } }
Streams.copy(stream, response.getOutputStream());
@Override protected byte[] getImageData(Attributes attributes) { try { Blob blob = getBlob(attributes); if (blob != null) { InputStream in = blob.getBinaryStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); Streams.copy(in, out); return out.toByteArray(); } return new byte[0]; } catch (SQLException e) { throw new WicketRuntimeException("Error while reading image data", e); } catch (IOException e) { throw new WicketRuntimeException("Error while reading image data", e); } }
/** * @see org.apache.wicket.markup.html.image.resource.DynamicImageResource#getImageData() */ protected byte[] getImageData() { try { Blob blob = getBlob(); if (blob != null) { InputStream in = blob.getBinaryStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); Streams.copy(in, out); return out.toByteArray(); } return new byte[0]; } catch (SQLException e) { throw new WicketRuntimeException("Error while reading image data", e); } catch (IOException e) { throw new WicketRuntimeException("Error while reading image data", e); } }
@Override protected byte[] getImageData(Attributes attributes) { try { Blob blob = getBlob(attributes); if (blob != null) { InputStream in = blob.getBinaryStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); Streams.copy(in, out); return out.toByteArray(); } return new byte[0]; } catch (SQLException e) { throw new WicketRuntimeException("Error while reading image data", e); } catch (IOException e) { throw new WicketRuntimeException("Error while reading image data", e); } }
/** * Writes the input stream to the output stream. Input is done without a Reader object, meaning * that the input is copied in its raw form. After it is copied it will close the streams. * * @param in * The input stream * @param out * The output stream * @return Number of bytes copied from one stream to the other * @throws IOException */ public static int copyAndClose(final InputStream in, final OutputStream out) throws IOException { try { return copy(in, out); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } }
/** * @see org.apache.wicket.markup.html.image.resource.DynamicImageResource#getImageData() */ @Override protected byte[] getImageData() { try { Blob blob = getBlob(); if (blob != null) { InputStream in = blob.getBinaryStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); Streams.copy(in, out); return out.toByteArray(); } return new byte[0]; } catch (SQLException e) { throw new WicketRuntimeException("Error while reading image data", e); } catch (IOException e) { throw new WicketRuntimeException("Error while reading image data", e); } }
/** * <p> * Reads <code>body-data</code> from the current <code>encapsulation</code> and writes its * contents into the output <code>Stream</code>. * * <p> * Arbitrary large amounts of data can be processed by this method using a constant size buffer. * (see * {@link #MultipartFormInputStream(InputStream,byte[],int, MultipartFormInputStream.ProgressNotifier) * constructor}). * * @param output * The <code>Stream</code> to write data into. May be null, in which case this method * is equivalent to {@link #discardBodyData()}. * * @return the amount of data written. * * @throws MalformedStreamException * if the stream ends unexpectedly. * @throws IOException * if an i/o error occurs. */ public int readBodyData(OutputStream output) throws MalformedStreamException, IOException { final InputStream istream = newInputStream(); return Streams.copy(istream, output == null ? new NoopOutputStream() : output); }
@Override public void writeData(final Attributes attributes) throws IOException { try { InputStream inputStream = webExternalResourceStream.getInputStream(); try { Streams.copy(inputStream, attributes.getResponse().getOutputStream()); } finally { IOUtils.closeQuietly(inputStream); } } catch (ResourceStreamNotFoundException rsnfx) { throw new WicketRuntimeException(rsnfx); } } });
@Override public void writeData(final Attributes attributes) throws IOException { try { InputStream inputStream = webExternalResourceStream.getInputStream(); try { Streams.copy(inputStream, attributes.getResponse().getOutputStream()); } finally { IOUtils.closeQuietly(inputStream); } } catch (ResourceStreamNotFoundException rsnfx) { throw new WicketRuntimeException(rsnfx); } } });