import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.zip.Inflater;
/**
* Created by Xuri on 2014/10/13.
*/
public class ZipUtil {
private final static int cacheSize = 1024;
/**
* Unpack Zip to byteArray
*/
public static byte[] unZipByte(byte[] data) {
Inflater decompresser = new Inflater();
// decompresser.reset();
decompresser.setInput(data); // decompresser.finish();
byte result[] = new byte[0];
ByteArrayOutputStream o = new ByteArrayOutputStream(data.length);
try {
byte[] buf = new byte[cacheSize];
int got = 0;
while (!decompresser.finished()) {
got = decompresser.inflate(buf);
o.write(buf, 0, got);
}
result = o.toByteArray();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
o.close();
} catch (IOException e) {
e.printStackTrace();
}
}
decompresser.end();
return result;
}
/**
* Unpack Zip to String
*/
public static String unZipByteToString(byte[] data) {
byte[] result = unZipByte(data);
String outputString = null;
try {
outputString = new String(result, 0, result.length, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return outputString;
}
}
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.zip.Inflater;
/**
* Created by Xuri on 2014/10/13.
*/
public class ZipUtil {
private final static int cacheSize = 1024;
/**
* Unpack Zip to byteArray
*/
public static byte[] unZipByte(byte[] data) {
Inflater decompresser = new Inflater();
// decompresser.reset();
decompresser.setInput(data); // decompresser.finish();
byte result[] = new byte[0];
ByteArrayOutputStream o = new ByteArrayOutputStream(data.length);
try {
byte[] buf = new byte[cacheSize];
int got = 0;
while (!decompresser.finished()) {
got = decompresser.inflate(buf);
o.write(buf, 0, got);
}
result = o.toByteArray();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
o.close();
} catch (IOException e) {
e.printStackTrace();
}
}
decompresser.end();
return result;
}
/**
* Unpack Zip to String
*/
public static String unZipByteToString(byte[] data) {
byte[] result = unZipByte(data);
String outputString = null;
try {
outputString = new String(result, 0, result.length, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return outputString;
}
}