/** * 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(); }
/** * @see java.io.ByteArrayOutputStream#reset() */ public synchronized void reset() { count = 0; filledBufferSum = 0; currentBufferIndex = 0; currentBuffer = getBuffer(currentBufferIndex); }
/** * Write a byte to byte array. * @param b the byte to write */ public synchronized void write(int b) { int inBufferPos = count - filledBufferSum; if (inBufferPos == currentBuffer.length) { needNewBuffer(count + 1); inBufferPos = 0; } currentBuffer[inBufferPos] = (byte) b; count++; }
@Test public void testNodePathConversion5() { final String assetName = "one]two"; final String pathName = NodeUtils.makeJSR170ComplaintName( assetName ); assertEquals( "one_two", pathName ); }
/** * Get the contents of a <code>Reader</code> as a String. * <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 String * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs */ public static String toString(Reader input) throws IOException { StringWriter sw = new StringWriter(); copy(input, sw); return sw.toString(); }
/** * Gets the curent contents of this byte stream as a string. * @return the contents of the byte array as a String * @see java.io.ByteArrayOutputStream#toString() */ public String toString() { return new String(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(); }
@Test public void testNodePathConversion7() { final String assetName = "one\"two"; final String pathName = NodeUtils.makeJSR170ComplaintName( assetName ); assertEquals( "one_two", pathName ); }
/** * Get the contents of a <code>Reader</code> as a character array. * <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 character array * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs * @since Commons IO 1.1 */ public static char[] toCharArray(Reader input) throws IOException { CharArrayWriter sw = new CharArrayWriter(); copy(input, sw); return sw.toCharArray(); }
/** * Write a byte to byte array. * @param b the byte to write */ public synchronized void write(int b) { int inBufferPos = count - filledBufferSum; if (inBufferPos == currentBuffer.length) { needNewBuffer(count + 1); inBufferPos = 0; } currentBuffer[inBufferPos] = (byte) b; count++; }
/** * Gets the curent contents of this byte stream as a string * using the specified encoding. * * @param enc the name of the character encoding * @return the string converted from the byte array * @throws UnsupportedEncodingException if the encoding is not supported * @see java.io.ByteArrayOutputStream#toString(String) */ public String toString(String enc) throws UnsupportedEncodingException { return new String(toByteArray(), enc); }
/** * @see java.io.ByteArrayOutputStream#reset() */ public synchronized void reset() { count = 0; filledBufferSum = 0; currentBufferIndex = 0; currentBuffer = getBuffer(currentBufferIndex); }
/** * 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(); }
/** * Creates a new byte array output stream, with a buffer capacity of * the specified size, in bytes. * * @param size the initial size * @throws IllegalArgumentException if size is negative */ public ByteArrayOutputStream(int size) { if (size < 0) { throw new IllegalArgumentException( "Negative initial size: " + size); } needNewBuffer(size); }
/** * Gets the curent contents of this byte stream as a string. * @return the contents of the byte array as a String * @see java.io.ByteArrayOutputStream#toString() */ public String toString() { return new String(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(); }
/** * Creates a new byte array output stream, with a buffer capacity of * the specified size, in bytes. * * @param size the initial size * @throws IllegalArgumentException if size is negative */ public ByteArrayOutputStream(int size) { if (size < 0) { throw new IllegalArgumentException( "Negative initial size: " + size); } needNewBuffer(size); }
/** * Gets the curent contents of this byte stream as a string * using the specified encoding. * * @param enc the name of the character encoding * @return the string converted from the byte array * @throws UnsupportedEncodingException if the encoding is not supported * @see java.io.ByteArrayOutputStream#toString(String) */ public String toString(String enc) throws UnsupportedEncodingException { return new String(toByteArray(), enc); }
/** * Get the contents of a <code>Reader</code> as a <code>byte[]</code> * using the specified character encoding. * <p> * Character encoding names can be found at * <a href="http://www.iana.org/assignments/character-sets">IANA</a>. * <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 * @param encoding the encoding to use, null means platform default * @return the requested byte array * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs * @since Commons IO 1.1 */ public static byte[] toByteArray(Reader input, String encoding) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); copy(input, output, encoding); return output.toByteArray(); }
/** * Get the contents of a <code>Reader</code> as a <code>byte[]</code> * using the specified character encoding. * <p> * Character encoding names can be found at * <a href="http://www.iana.org/assignments/character-sets">IANA</a>. * <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 * @param encoding the encoding to use, null means platform default * @return the requested byte array * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs * @since Commons IO 1.1 */ public static byte[] toByteArray(Reader input, String encoding) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); copy(input, output, encoding); return output.toByteArray(); }