Java Apache Commons users
Posted
by Tom Brito
on Stack Overflow
See other posts from Stack Overflow
or by Tom Brito
Published on 2010-04-06T17:37:47Z
Indexed on
2010/04/06
17:43 UTC
Read the original article
Hit count: 312
java
|apache-commons
Is there anything in apache commons to convert a Object to byte array, like the following method does?
public static byte[] toByteArray(Object obj) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(obj);
oos.flush();
byte[] data = baos.toByteArray();
return data;
}
[try-finally block closing buffers were omitted to simplify]
© Stack Overflow or respective owner