TestCompress
public class TestCompress {
public static void main(String[] args) throws Exception {
// 解压缩
decompress("e:/hello.txt.bz2");
}
private static void decompress(String fileName) throws Exception {
// 1 压缩方式检查
CompressionCodecFactory factory = new CompressionCodecFactory(new Configuration());
CompressionCodec codec = factory.getCodec(new Path(fileName));
if (codec == null) {
System.out.println("can not process");
return;
}
// 2 获取输入流
FileInputStream fis = new FileInputStream(new File(fileName));
CompressionInputStream cis = codec.createInputStream(fis);
// 3 获取输出流
FileOutputStream fos = new FileOutputStream(new File(fileName + ".decode"));
// 4 流的对拷
IOUtils.copyBytes(cis, fos, 1024 * 1024, false);
// 5 关闭资源
IOUtils.closeStream(fos);
IOUtils.closeStream(cis);
IOUtils.closeStream(fis);
}
}
网友评论