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: 297

Filed under:
|

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

Related posts about java

Related posts about apache-commons