/** * Returns the data for this output stream as an array of bytes, assuming that the data has been * retained in memory. If the data was written to disk, this method returns <code>null</code>. * * @return The data for this output stream, or <code>null</code> if no such data is available. */ public byte[] getData() { if (memoryOutputStream != null) { return memoryOutputStream.toByteArray(); } return null; }
/** * Returns the data for this output stream as an array of bytes, assuming that the data has been * retained in memory. If the data was written to disk, this method returns <code>null</code>. * * @return The data for this output stream, or <code>null</code> if no such data is available. */ public byte[] getData() { if (memoryOutputStream != null) { return memoryOutputStream.toByteArray(); } return null; }
/** * Returns the data for this output stream as an array of bytes, assuming that the data has been * retained in memory. If the data was written to disk, this method returns <code>null</code>. * * @return The data for this output stream, or <code>null</code> if no such data is available. */ public byte[] getData() { if (memoryOutputStream != null) { return memoryOutputStream.toByteArray(); } return null; }
/** * This as a string using the provided encoding. * * @param enc * the encoding to use * @return This as a string using the provided encoding * @throws UnsupportedEncodingException */ public String toString(final String enc) throws UnsupportedEncodingException { return new String(toByteArray(), enc); }
/** * This as a string using the provided encoding. * * @param enc * the encoding to use * @return This as a string using the provided encoding * @throws UnsupportedEncodingException */ public String toString(String enc) throws UnsupportedEncodingException { return new String(toByteArray(), enc); }
/** * This as a string using the provided encoding. * * @param enc * the encoding to use * @return This as a string using the provided encoding * @throws UnsupportedEncodingException */ public String toString(String enc) throws UnsupportedEncodingException { return new String(toByteArray(), enc); }
/** * @see java.lang.Object#toString() */ @Override public String toString() { return new String(toByteArray()); }
/** * @see java.lang.Object#toString() */ public String toString() { return new String(toByteArray()); }
/** * @see java.lang.Object#toString() */ @Override public String toString() { return new String(toByteArray()); }
/** * Switches the underlying output stream from a memory based stream to one that is backed by * disk. This is the point at which we realize that too much data is being written to keep in * memory, so we elect to switch to disk-based storage. * * @exception IOException * if an error occurs. */ protected void thresholdReached() throws IOException { byte[] data = memoryOutputStream.toByteArray(); FileOutputStream fos = new FileOutputStream(outputFile); fos.write(data); currentOutputStream = fos; memoryOutputStream = null; } }
/** * Switches the underlying output stream from a memory based stream to one that is backed by * disk. This is the point at which we realize that too much data is being written to keep in * memory, so we elect to switch to disk-based storage. * * @exception IOException * if an error occurs. */ @Override protected void thresholdReached() throws IOException { byte[] data = memoryOutputStream.toByteArray(); if (outputFile == null) { outputFile = fileFactory.createFile(); } FileOutputStream fos = new FileOutputStream(outputFile); fos.write(data); currentOutputStream = fos; memoryOutputStream = null; }
public static byte[] obtainByteData(InputStream is) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); byte[] bytes = new byte[512]; // Read bytes from the input stream in bytes.length-sized chunks and write // them into the output stream int readBytes; while ((readBytes = is.read(bytes)) > 0) { os.write(bytes, 0, readBytes); } // Convert the contents of the output stream into a byte array byte[] byteData = os.toByteArray(); // Close the streams is.close(); os.close(); return byteData; }
/** * Get the contents of a <code>Reader</code> as a <code>byte[]</code> using the default * character encoding of the platform. * <p> * This method buffers the input internally, so there is no need to use a * <code>BufferedReader</code>. * * @param input * the <code>Reader</code> to read from * @return the requested byte array * @throws NullPointerException * if the input is null * @throws IOException * if an I/O error occurs */ public static byte[] toByteArray(final Reader input) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); copy(input, output); return output.toByteArray(); }
/** * Get the contents of a <code>Reader</code> as a <code>byte[]</code> using the default * character encoding of the platform. * <p> * This method buffers the input internally, so there is no need to use a * <code>BufferedReader</code>. * * @param input * the <code>Reader</code> to read from * @return the requested byte array * @throws NullPointerException * if the input is null * @throws IOException * if an I/O error occurs */ public static byte[] toByteArray(Reader input) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); copy(input, output); return output.toByteArray(); }
/** * Get the contents of an <code>InputStream</code> as a <code>byte[]</code>. * <p> * This method buffers the input internally, so there is no need to use a * <code>BufferedInputStream</code>. * * @param input * the <code>InputStream</code> to read from * @return the requested byte array * @throws NullPointerException * if the input is null * @throws IOException * if an I/O error occurs */ public static byte[] toByteArray(final InputStream input) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); copy(input, output); return output.toByteArray(); }
/** * Get the contents of an <code>InputStream</code> as a <code>byte[]</code>. * <p> * This method buffers the input internally, so there is no need to use a * <code>BufferedInputStream</code>. * * @param input * the <code>InputStream</code> to read from * @return the requested byte array * @throws NullPointerException * if the input is null * @throws IOException * if an I/O error occurs */ public static byte[] toByteArray(InputStream input) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); copy(input, output); return output.toByteArray(); }
/** * Get the contents of an <code>InputStream</code> as a <code>byte[]</code>. * <p> * This method buffers the input internally, so there is no need to use a * <code>BufferedInputStream</code>. * * @param input * the <code>InputStream</code> to read from * @return the requested byte array * @throws NullPointerException * if the input is null * @throws IOException * if an I/O error occurs */ public static byte[] toByteArray(InputStream input) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); copy(input, output); return output.toByteArray(); }
protected byte[] readAllResources(List<IResourceStream> resources) throws IOException, ResourceStreamNotFoundException { ByteArrayOutputStream output = new ByteArrayOutputStream(); for (IResourceStream curStream : resources) IOUtils.copy(curStream.getInputStream(), output); byte[] bytes = output.toByteArray(); if (getCompressor() != null) { String nonCompressed = new String(bytes, "UTF-8"); bytes = getCompressor().compress(nonCompressed).getBytes("UTF-8"); } return bytes; }
@Override protected byte[] readAllResources(List<IResourceStream> resources) throws IOException, ResourceStreamNotFoundException { ByteArrayOutputStream output = new ByteArrayOutputStream(); for (IResourceStream curStream : resources) { IOUtils.copy(curStream.getInputStream(), output); output.write(";".getBytes()); } byte[] bytes = output.toByteArray(); if (getCompressor() != null) { String nonCompressed = new String(bytes, "UTF-8"); bytes = getCompressor().compress(nonCompressed).getBytes("UTF-8"); } return bytes; }
protected byte[] readAllResources(List<IResourceStream> resources) throws IOException, ResourceStreamNotFoundException { ByteArrayOutputStream output = new ByteArrayOutputStream(); for (IResourceStream curStream : resources) IOUtils.copy(curStream.getInputStream(), output); byte[] bytes = output.toByteArray(); if (getCompressor() != null) { String nonCompressed = new String(bytes, "UTF-8"); bytes = getCompressor().compress(nonCompressed).getBytes("UTF-8"); } return bytes; }