Here you can find the source of serializeObject(Object serializedObject)
Parameter | Description |
---|---|
serializedObject | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static byte[] serializeObject(Object serializedObject) throws IOException
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.util.zip.Deflater; import java.util.zip.DeflaterOutputStream; public class Main { /**//from ww w . ja v a 2 s . c o m * compress and serialize the object * @param serializedObject * @throws IOException * @return byte[] serialized byte array */ public static byte[] serializeObject(Object serializedObject) throws IOException { Deflater deflater = new Deflater(); deflater.setStrategy(Deflater.DEFAULT_STRATEGY); deflater.setLevel(Deflater.BEST_COMPRESSION); ByteArrayOutputStream outbytes = new ByteArrayOutputStream(); DeflaterOutputStream deflating = new DeflaterOutputStream(outbytes, deflater); ObjectOutputStream out = new ObjectOutputStream(deflating); out.writeObject(serializedObject); out.close(); return outbytes.toByteArray(); } }