|
@@ -108,85 +108,7 @@
|
|
<version>3.17.4</version>
|
|
<version>3.17.4</version>
|
|
</dependency>
|
|
</dependency>
|
|
<!-- Snappy compression library -->
|
|
<!-- Snappy compression library -->
|
|
- <dependency>import org.xerial.snappy.Snappy;
|
|
|
|
-
|
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
|
-import java.io.ByteArrayOutputStream;
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.util.zip.GZIPInputStream;
|
|
|
|
-import java.util.zip.GZIPOutputStream;
|
|
|
|
-import java.util.zip.ZipEntry;
|
|
|
|
-import java.util.zip.ZipInputStream;
|
|
|
|
-import java.util.zip.ZipOutputStream;
|
|
|
|
-
|
|
|
|
-public class CompressionUtil {
|
|
|
|
-
|
|
|
|
- // ZIP压缩
|
|
|
|
- public static byte[] zipCompress(byte[] data) throws IOException {
|
|
|
|
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
|
- ZipOutputStream zipOutputStream = new ZipOutputStream(byteArrayOutputStream);
|
|
|
|
- ZipEntry zipEntry = new ZipEntry("data");
|
|
|
|
- zipOutputStream.putNextEntry(zipEntry);
|
|
|
|
- zipOutputStream.write(data);
|
|
|
|
- zipOutputStream.closeEntry();
|
|
|
|
- zipOutputStream.close();
|
|
|
|
- return byteArrayOutputStream.toByteArray();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // ZIP解压缩
|
|
|
|
- public static byte[] zipDecompress(byte[] compressedData) throws IOException {
|
|
|
|
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(compressedData);
|
|
|
|
- ZipInputStream zipInputStream = new ZipInputStream(byteArrayInputStream);
|
|
|
|
- ZipEntry zipEntry = zipInputStream.getNextEntry();
|
|
|
|
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
|
- byte[] buffer = new byte[1024];
|
|
|
|
- int len;
|
|
|
|
- while ((len = zipInputStream.read(buffer)) != -1) {
|
|
|
|
- byteArrayOutputStream.write(buffer, 0, len);
|
|
|
|
- }
|
|
|
|
- zipInputStream.closeEntry();
|
|
|
|
- zipInputStream.close();
|
|
|
|
- return byteArrayOutputStream.toByteArray();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // ZLIB压缩(使用Java的ZipOutputStream进行模拟)
|
|
|
|
- public static byte[] zlibCompress(byte[] data) throws IOException {
|
|
|
|
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
|
- ZipOutputStream zipOutputStream = new ZipOutputStream(byteArrayOutputStream);
|
|
|
|
- ZipEntry zipEntry = new ZipEntry("data");
|
|
|
|
- zipOutputStream.putNextEntry(zipEntry);
|
|
|
|
- zipOutputStream.write(data);
|
|
|
|
- zipOutputStream.closeEntry();
|
|
|
|
- zipOutputStream.close();
|
|
|
|
- return byteArrayOutputStream.toByteArray();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // ZLIB解压缩(使用Java的ZipInputStream进行模拟)
|
|
|
|
- public static byte[] zlibDecompress(byte[] compressedData) throws IOException {
|
|
|
|
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(compressedData);
|
|
|
|
- ZipInputStream zipInputStream = new ZipInputStream(byteArrayInputStream);
|
|
|
|
- ZipEntry zipEntry = zipInputStream.getNextEntry();
|
|
|
|
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
|
- byte[] buffer = new byte[1024];
|
|
|
|
- int len;
|
|
|
|
- while ((len = zipInputStream.read(buffer)) != -1) {
|
|
|
|
- byteArrayOutputStream.write(buffer, 0, len);
|
|
|
|
- }
|
|
|
|
- zipInputStream.closeEntry();
|
|
|
|
- zipInputStream.close();
|
|
|
|
- return byteArrayOutputStream.toByteArray();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Snappy压缩
|
|
|
|
- public static byte[] snappyCompress(byte[] data) {
|
|
|
|
- return Snappy.compress(data);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Snappy解压缩
|
|
|
|
- public static byte[] snappyDecompress(byte[] compressedData) {
|
|
|
|
- return Snappy.uncompress(compressedData);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+ <dependency>
|
|
<groupId>org.xerial.snappy</groupId>
|
|
<groupId>org.xerial.snappy</groupId>
|
|
<artifactId>snappy-java</artifactId>
|
|
<artifactId>snappy-java</artifactId>
|
|
<version>1.1.8.4</version>
|
|
<version>1.1.8.4</version>
|