PiRSquared17 / tomproject

Automatically exported from code.google.com/p/tomproject
0 stars 0 forks source link

TomUtils objectToByteArray and byteArrayToObject #81

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
    /*
     * http://snippets.dzone.com/posts/show/3897
     */
    public static byte[] toByteArray(Object obj) throws IOException {
    @Cleanup
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    @Cleanup
    ObjectOutputStream oos = new ObjectOutputStream(baos);

    oos.writeObject(obj);
    oos.flush();
    byte[] data = baos.toByteArray();
    return data;
    }

Original issue reported on code.google.com by brito....@gmail.com on 5 Apr 2010 at 1:15

GoogleCodeExporter commented 9 years ago
http://www.javafaq.nu/java-article236.html
(the snippets is for c#)

Original comment by brito....@gmail.com on 6 Apr 2010 at 4:57

GoogleCodeExporter commented 9 years ago
check http://commons.apache.org/lang/

Original comment by brito....@gmail.com on 6 Apr 2010 at 5:27

GoogleCodeExporter commented 9 years ago
Already implemented in apache commons:
org.apache.commons.lang.SerializationUtils

Original comment by brito....@gmail.com on 6 Apr 2010 at 6:36

GoogleCodeExporter commented 9 years ago

Original comment by brito....@gmail.com on 9 Apr 2010 at 12:39