/**
* 功能说明:将List对象压缩转化为byte[]
* @param data
* @return
* @throws IOException
*/
public static byte[] compressList(List data) throws IOException {
byte[] result=null;
//序列化使用的输出流
ByteArrayOutputStream o = new ByteArrayOutputStream();
GZIPOutputStream gzout=new GZIPOutputStream(o);
//建立对象序列化输出流
ObjectOutputStream out = new ObjectOutputStream(gzout);
out.writeObject(data);
out.flush();
out.close();
gzout.close();
result=o.toByteArray();
o.close();
return result;
}
/**
* 功能说明:将byte[]数据解压成List对象于上面过程逆向
* @param data
* @return
* @throws IOException
*/
public static List uncompressList(byte[] data) throws IOException {
List result=null;
ByteArrayInputStream i = new ByteArrayInputStream(data);
GZIPInputStream gzin=new GZIPInputStream(i);
ObjectInputStream in = new ObjectInputStream(gzin);
try {
result=(List)in.readObject();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
i.close();
gzin.close();
in.close();
return result;
}