Here you can find the source of serializeAsByteArray(Object b)
Parameter | Description |
---|---|
the | object |
Parameter | Description |
---|---|
IOException | an exception |
public static byte[] serializeAsByteArray(Object b) throws IOException
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; public class Main { /**/*from www .ja va 2 s . c o m*/ * Serialize an object as a raw byte array * * @param the object * @return byte array * @throws IOException */ public static byte[] serializeAsByteArray(Object b) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bos); try { out.writeObject(b); } finally { out.close(); } return bos.toByteArray(); } }