/***
* 压缩Zip
*
* @param data
* @return
*/
public static byte[] Zip(byte[] data) {
byte[] b = null;
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(bos);
ZipEntry entry = nezipEntry("data");
entry.setSize(data.length);
zip.putNextEntry(entry);
zip.write(data);
zip.closeEntry();
zip.close();
b = bos.toByteArray();
bos.close();
} catch (Exception ex) {
ex.printStackTrace();
}
return b;
}
/***
* 解压Zip
*
* @param data
* @return
*/
public static String UnZip(byte[] data) throws IOException {
ZIPInputStream zipStream = new ZIPInputStream(new ByteArryInputStream(data));
byte[] buffer = new byte[1024];
ZipEntry entry;
while ((entry = zipStream.getNextEntry()) != null) {
zipStream.read(buffer);
zipStream.closeEntry();
}
zip.close();
return new String(buffer);
}