Snappy-java 解压文件

snappy-java-1.1.2.6.jar 版本用的这个

public static JSONArray decompress() {
List<MapValue> list = new ArrayList<MapValue>();
try {
byte[] contents = Files.toByteArray(new File(
"F:/spz/20161028145900.9.ttr.pack.spz"));
SnappyFramedInputStream is = new SnappyFramedInputStream(
new ByteArrayInputStream(contents));
 
int unLen = Snappy.uncompressedLength(contents);
ByteArrayOutputStream os = new ByteArrayOutputStream(unLen);
is.transferTo(os);
os.close();
byte[] re = os.toByteArray();
MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(re);
 
while (unpacker.hasNext()) {
Value v = unpacker.unpackValue();
switch (v.getValueType()) {
case MAP:
MapValue map = v.asMapValue();
list.add(map);
break;
}
 
}
 
is.close();
 
} catch (Exception e) {
e.printStackTrace();
}
 
if (list != null && !list.isEmpty()) {
return JSONArray.parseArray(list.toString());
} else {
return null;
}
 
}
 
到标红那里解压结束 ,后面是msgpack反序列化.msgpack我用的是源码 jar发现不好使
posted @ 2018-06-01 16:44  劉先生  阅读(998)  评论(0编辑  收藏  举报