Java examples for java.lang:byte Array Compress
compress Object To Byte Array
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; public class Main { public static void main(String[] argv) throws Exception { Object obj = "java2s.com"; System.out.println(java.util.Arrays .toString(compressObjectToByteArray(obj))); }/* w ww . j av a 2s. c o m*/ public static byte[] compressObjectToByteArray(Object obj) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(bos); out.writeObject(obj); return bos.toByteArray(); } catch (Exception e) { e.printStackTrace(); } return new byte[] {}; } }