/** * @see java.io.ByteArrayOutputStream#toString(String) */ public String toString(String enc) throws UnsupportedEncodingException { return new String(toByteArray(), enc); }
/** * @see java.io.ByteArrayOutputStream#toString() */ @Override public String toString() { return new String(toByteArray()); }
/** * @see ByteArrayOutputStream#toString() */ @Override public String toString() { return new String(toByteArray()); }
/** * Get the underlying byte array. */ public byte[] toByteArray() { return out.getByteArrayStream().toByteArray(); } }
/** * Returns buffered servlet output content as byte array. * Returns <code>null</code> if writer is not used. */ public byte[] toByteArray() { if (bufferOutputStream != null) { return bufferOutputStream.getByteArrayStream().toByteArray(); } return null; }
/** * @see ByteArrayOutputStream#toString(String) */ public String toString(final String enc) { return StringUtil.newString(toByteArray(), enc); } }
/** * @see #copyToOutputStream(InputStream, int) */ public static byte[] readBytes(final InputStream input, final int count) throws IOException { return copyToOutputStream(input, count).toByteArray(); }
/** * @see #copyToOutputStream(Reader, String, int) */ public static byte[] readBytes(final Reader input, final String encoding, final int count) throws IOException { return copyToOutputStream(input, encoding, count).toByteArray(); }
/** * Serialize an object to byte array. */ public static byte[] objectToByteArray(Object obj) throws IOException { FastByteArrayOutputStream bos = new FastByteArrayOutputStream(); ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(bos); oos.writeObject(obj); } finally { StreamUtil.close(oos); } return bos.toByteArray(); }
public static byte[] readBytes(Reader input) throws IOException { FastByteArrayOutputStream output = new FastByteArrayOutputStream(); copy(input, output); return output.toByteArray(); } public static byte[] readBytes(Reader input, int byteCount) throws IOException {
public static byte[] readBytes(Reader input, String encoding) throws IOException { FastByteArrayOutputStream output = new FastByteArrayOutputStream(); copy(input, output, encoding); return output.toByteArray(); } public static byte[] readBytes(Reader input, String encoding, int byteCount) throws IOException {
public static byte[] readBytes(InputStream input, int byteCount) throws IOException { FastByteArrayOutputStream output = new FastByteArrayOutputStream(); copy(input, output, byteCount); return output.toByteArray(); }
public static byte[] readBytes(Reader input, String encoding, int byteCount) throws IOException { FastByteArrayOutputStream output = new FastByteArrayOutputStream(); copy(input, output, encoding, byteCount); return output.toByteArray(); }
public static byte[] readBytes(InputStream input) throws IOException { FastByteArrayOutputStream output = new FastByteArrayOutputStream(); copy(input, output); return output.toByteArray(); } public static byte[] readBytes(InputStream input, int byteCount) throws IOException {
public static byte[] readBytes(Reader input, int byteCount) throws IOException { FastByteArrayOutputStream output = new FastByteArrayOutputStream(); copy(input, output, byteCount); return output.toByteArray(); } public static byte[] readBytes(Reader input, String encoding) throws IOException {
/** * Create object copy using serialization mechanism. */ public static <T extends Serializable> T cloneViaSerialization(T obj) throws IOException, ClassNotFoundException { FastByteArrayOutputStream bos = new FastByteArrayOutputStream(); ObjectOutputStream out = null; ObjectInputStream in = null; Object objCopy = null; try { out = new ObjectOutputStream(bos); out.writeObject(obj); out.flush(); byte[] bytes = bos.toByteArray(); in = new ObjectInputStream(new ByteArrayInputStream(bytes)); objCopy = in.readObject(); } finally { StreamUtil.close(out); StreamUtil.close(in); } return (T) objCopy; }
/** * Serialize an object to byte array. */ public static byte[] objectToByteArray(final Object obj) throws IOException { FastByteArrayOutputStream bos = new FastByteArrayOutputStream(); ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(bos); oos.writeObject(obj); } finally { StreamUtil.close(oos); } return bos.toByteArray(); }
@Test void testFbat() throws IOException { FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream(); fbaos.write(173); fbaos.write(new byte[]{1, 2, 3}); fbaos.write(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 4, 3); byte[] result = fbaos.toByteArray(); byte[] expected = new byte[]{(byte) 173, 1, 2, 3, 5, 6, 7}; assertTrue(Arrays.equals(expected, result)); }
@Test void testFbat2() throws IOException { FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream(2); fbaos.write(173); fbaos.write(new byte[]{1, 2, 3}); fbaos.write(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 4, 3); byte[] result = fbaos.toByteArray(); byte[] expected = new byte[]{(byte) 173, 1, 2, 3, 5, 6, 7}; assertTrue(Arrays.equals(expected, result)); }
@Test void testFbatSingle() throws IOException { FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream(2); fbaos.write(73); fbaos.write(74); fbaos.write(75); fbaos.write(76); fbaos.write(77); byte[] result = fbaos.toByteArray(); byte[] expected = new byte[]{73, 74, 75, 76, 77}; assertTrue(Arrays.equals(expected, result)); } }