chore(project): 添加项目配置文件和忽略规则
- 添加 Babel 配置文件支持 ES6+ 语法转换 - 添加 ESLint 忽略规则和配置文件 - 添加 Git 忽略规则文件 - 添加 Travis CI 配置文件 - 添加 1.4.2 版本变更日志文件 - 添加 Helm 图表辅助模板文件 - 添加 Helm 忽略规则文件
This commit is contained in:
41
compressor/pom.xml
Normal file
41
compressor/pom.xml
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 1999-2019 Seata.io Group.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>seata-compressor</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>seata-compressor ${project.version}</name>
|
||||
|
||||
<modules>
|
||||
<module>seata-compressor-all</module>
|
||||
<module>seata-compressor-gzip</module>
|
||||
<module>seata-compressor-zip</module>
|
||||
<module>seata-compressor-7z</module>
|
||||
<module>seata-compressor-bzip2</module>
|
||||
<module>seata-compressor-lz4</module>
|
||||
<module>seata-compressor-deflater</module>
|
||||
</modules>
|
||||
|
||||
|
||||
</project>
|
||||
47
compressor/seata-compressor-7z/pom.xml
Normal file
47
compressor/seata-compressor-7z/pom.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 1999-2019 Seata.io Group.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-compressor</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>seata-compressor-7z</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>seata-compressor-7z ${project.version}</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.tukaani</groupId>
|
||||
<artifactId>xz</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-compress</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.sevenz;
|
||||
|
||||
import io.seata.common.loader.LoadLevel;
|
||||
import io.seata.core.compressor.Compressor;
|
||||
|
||||
/**
|
||||
* the SevenZ Compressor
|
||||
*
|
||||
* @author ph3636
|
||||
*/
|
||||
@LoadLevel(name = "SEVENZ")
|
||||
public class SevenZCompressor implements Compressor {
|
||||
|
||||
@Override
|
||||
public byte[] compress(byte[] bytes) {
|
||||
return SevenZUtil.compress(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decompress(byte[] bytes) {
|
||||
return SevenZUtil.decompress(bytes);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.sevenz;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.sevenz.SevenZFile;
|
||||
import org.apache.commons.compress.archivers.sevenz.SevenZOutputFile;
|
||||
import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
|
||||
|
||||
/**
|
||||
* the SevenZ Util
|
||||
*
|
||||
* @author ph3636
|
||||
*/
|
||||
public class SevenZUtil {
|
||||
|
||||
private static final int BUFFER_SIZE = 8192;
|
||||
|
||||
public static byte[] compress(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
throw new NullPointerException("bytes is null");
|
||||
}
|
||||
SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel();
|
||||
try (SevenZOutputFile z7z = new SevenZOutputFile(channel)) {
|
||||
SevenZArchiveEntry entry = new SevenZArchiveEntry();
|
||||
entry.setName("sevenZip");
|
||||
entry.setSize(bytes.length);
|
||||
z7z.putArchiveEntry(entry);
|
||||
z7z.write(bytes);
|
||||
z7z.closeArchiveEntry();
|
||||
z7z.finish();
|
||||
return channel.array();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("SevenZ compress error", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] decompress(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
throw new NullPointerException("bytes is null");
|
||||
}
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel(bytes);
|
||||
try (SevenZFile sevenZFile = new SevenZFile(channel)) {
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
while (sevenZFile.getNextEntry() != null) {
|
||||
int n;
|
||||
while ((n = sevenZFile.read(buffer)) > -1) {
|
||||
out.write(buffer, 0, n);
|
||||
}
|
||||
}
|
||||
return out.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("SevenZ decompress error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
io.seata.compressor.sevenz.SevenZCompressor
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.sevenz;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* the SevenZ Compressor test
|
||||
*
|
||||
* @author ph3636
|
||||
*/
|
||||
public class SevenZCompressorTest {
|
||||
|
||||
@Test
|
||||
public void testCompressAndDecompress() {
|
||||
SevenZCompressor compressor = new SevenZCompressor();
|
||||
byte[] bytes = "aa".getBytes();
|
||||
bytes = compressor.compress(bytes);
|
||||
bytes = compressor.decompress(bytes);
|
||||
Assertions.assertEquals(new String(bytes), "aa");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.sevenz;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
/**
|
||||
* the SevenZ Util test
|
||||
*
|
||||
* @author ph3636
|
||||
*/
|
||||
public class SevenZUtilTest {
|
||||
|
||||
@Test
|
||||
public void test_compress() {
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
SevenZUtil.compress(null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_decompress() {
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
SevenZUtil.decompress(null);
|
||||
});
|
||||
}
|
||||
}
|
||||
62
compressor/seata-compressor-all/pom.xml
Normal file
62
compressor/seata-compressor-all/pom.xml
Normal file
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 1999-2019 Seata.io Group.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-compressor</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>seata-compressor-all</artifactId>
|
||||
<name>seata-compressor-all ${project.version}</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-compressor-gzip</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-compressor-7z</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-compressor-bzip2</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-compressor-zip</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-compressor-lz4</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-compressor-deflater</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
43
compressor/seata-compressor-bzip2/pom.xml
Normal file
43
compressor/seata-compressor-bzip2/pom.xml
Normal file
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 1999-2019 Seata.io Group.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-compressor</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>seata-compressor-bzip2</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>seata-compressor-bzip2 ${project.version}</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.ant</groupId>
|
||||
<artifactId>ant</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.bzip2;
|
||||
|
||||
import io.seata.common.loader.LoadLevel;
|
||||
import io.seata.core.compressor.Compressor;
|
||||
|
||||
/**
|
||||
* the BZip2 Compressor
|
||||
*
|
||||
* @author ph3636
|
||||
*/
|
||||
@LoadLevel(name = "BZIP2")
|
||||
public class BZip2Compressor implements Compressor {
|
||||
|
||||
@Override
|
||||
public byte[] compress(byte[] bytes) {
|
||||
return BZip2Util.compress(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decompress(byte[] bytes) {
|
||||
return BZip2Util.decompress(bytes);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.bzip2;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.tools.bzip2.CBZip2InputStream;
|
||||
import org.apache.tools.bzip2.CBZip2OutputStream;
|
||||
|
||||
/**
|
||||
* the BZip2 Util
|
||||
*
|
||||
* @author ph3636
|
||||
*/
|
||||
public class BZip2Util {
|
||||
|
||||
private static final int BUFFER_SIZE = 8192;
|
||||
|
||||
public static byte[] compress(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
throw new NullPointerException("bytes is null");
|
||||
}
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
try (CBZip2OutputStream bzip2 = new CBZip2OutputStream(bos)) {
|
||||
bzip2.write(bytes);
|
||||
bzip2.finish();
|
||||
return bos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("BZip2 compress error", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] decompress(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
throw new NullPointerException("bytes is null");
|
||||
}
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
|
||||
try (CBZip2InputStream bzip2 = new CBZip2InputStream(bis)) {
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int n;
|
||||
while ((n = bzip2.read(buffer)) > -1) {
|
||||
out.write(buffer, 0, n);
|
||||
}
|
||||
return out.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("BZip2 decompress error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
io.seata.compressor.bzip2.BZip2Compressor
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.bzip2;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* the BZip2 Compressor test
|
||||
*
|
||||
* @author ph3636
|
||||
*/
|
||||
public class BZip2CompressorTest {
|
||||
|
||||
@Test
|
||||
public void testCompressAndDecompress() {
|
||||
BZip2Compressor compressor = new BZip2Compressor();
|
||||
byte[] bytes = "aa".getBytes();
|
||||
bytes = compressor.compress(bytes);
|
||||
bytes = compressor.decompress(bytes);
|
||||
Assertions.assertEquals(new String(bytes), "aa");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.bzip2;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* the BZip2 Util test
|
||||
*
|
||||
* @author ph3636
|
||||
*/
|
||||
public class BZip2UtilTest {
|
||||
|
||||
@Test
|
||||
public void test_compress() {
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
BZip2Util.compress(null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_decompress() {
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
BZip2Util.decompress(null);
|
||||
});
|
||||
}
|
||||
}
|
||||
39
compressor/seata-compressor-deflater/pom.xml
Normal file
39
compressor/seata-compressor-deflater/pom.xml
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 1999-2019 Seata.io Group.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-compressor</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>seata-compressor-deflater</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>seata-compressor-deflater ${project.version}</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.deflater;
|
||||
|
||||
import io.seata.common.loader.LoadLevel;
|
||||
import io.seata.core.compressor.Compressor;
|
||||
|
||||
/**
|
||||
* @author dongzl
|
||||
*/
|
||||
@LoadLevel(name = "DEFLATER")
|
||||
public class DeflaterCompressor implements Compressor {
|
||||
|
||||
@Override
|
||||
public byte[] compress(byte[] bytes) {
|
||||
return DeflaterUtil.compress(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decompress(byte[] bytes) {
|
||||
return DeflaterUtil.decompress(bytes);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.deflater;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.zip.Deflater;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
/**
|
||||
* @author dongzl
|
||||
*/
|
||||
public class DeflaterUtil {
|
||||
|
||||
private DeflaterUtil() {
|
||||
|
||||
}
|
||||
|
||||
private static final int BUFFER_SIZE = 8192;
|
||||
|
||||
public static byte[] compress(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
throw new NullPointerException("bytes is null");
|
||||
}
|
||||
int lenght = 0;
|
||||
Deflater deflater = new Deflater();
|
||||
deflater.setInput(bytes);
|
||||
deflater.finish();
|
||||
byte[] outputBytes = new byte[BUFFER_SIZE];
|
||||
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
|
||||
while (!deflater.finished()) {
|
||||
lenght = deflater.deflate(outputBytes);
|
||||
bos.write(outputBytes, 0, lenght);
|
||||
}
|
||||
deflater.end();
|
||||
return bos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Deflater compress error", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] decompress(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
throw new NullPointerException("bytes is null");
|
||||
}
|
||||
int length = 0;
|
||||
Inflater inflater = new Inflater();
|
||||
inflater.setInput(bytes);
|
||||
byte[] outputBytes = new byte[BUFFER_SIZE];
|
||||
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();) {
|
||||
while (!inflater.finished()) {
|
||||
length = inflater.inflate(outputBytes);
|
||||
if (length == 0) {
|
||||
break;
|
||||
}
|
||||
bos.write(outputBytes, 0, length);
|
||||
}
|
||||
inflater.end();
|
||||
return bos.toByteArray();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Deflater decompress error", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
io.seata.compressor.deflater.DeflaterCompressor
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.deflater;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author dongzl
|
||||
*/
|
||||
public class DeflaterCompressorTest {
|
||||
|
||||
@Test
|
||||
public void testCompressAndDecompress() {
|
||||
DeflaterCompressor compressor = new DeflaterCompressor();
|
||||
byte[] bytes = "seata".getBytes();
|
||||
bytes = compressor.compress(bytes);
|
||||
bytes = compressor.decompress(bytes);
|
||||
Assertions.assertEquals(new String(bytes), "seata");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.deflater;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author dongzl
|
||||
*/
|
||||
public class DeflaterUtilTest {
|
||||
|
||||
@Test
|
||||
public void test_compress() {
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
DeflaterUtil.compress(null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_decompress() {
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
DeflaterUtil.decompress(null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_compressEqualDecompress() {
|
||||
byte[] compress = DeflaterUtil.compress("seata".getBytes());
|
||||
byte[] decompress = DeflaterUtil.decompress(compress);
|
||||
Assertions.assertEquals("seata", new String(decompress));
|
||||
}
|
||||
|
||||
}
|
||||
39
compressor/seata-compressor-gzip/pom.xml
Normal file
39
compressor/seata-compressor-gzip/pom.xml
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 1999-2019 Seata.io Group.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-compressor</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>seata-compressor-gzip</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>seata-compressor-gzip ${project.version}</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.gzip;
|
||||
|
||||
import io.seata.common.loader.LoadLevel;
|
||||
import io.seata.core.compressor.Compressor;
|
||||
|
||||
/**
|
||||
* @author jsbxyyx
|
||||
*/
|
||||
@LoadLevel(name = "GZIP")
|
||||
public class GzipCompressor implements Compressor {
|
||||
|
||||
@Override
|
||||
public byte[] compress(byte[] bytes) {
|
||||
return GzipUtil.compress(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decompress(byte[] bytes) {
|
||||
return GzipUtil.decompress(bytes);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.gzip;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
/**
|
||||
* @author jsbxyyx
|
||||
*/
|
||||
public class GzipUtil {
|
||||
|
||||
private GzipUtil() {
|
||||
|
||||
}
|
||||
|
||||
private static final int BUFFER_SIZE = 8192;
|
||||
|
||||
public static byte[] compress(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
throw new NullPointerException("bytes is null");
|
||||
}
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
try (GZIPOutputStream gzip = new GZIPOutputStream(out)) {
|
||||
gzip.write(bytes);
|
||||
gzip.flush();
|
||||
gzip.finish();
|
||||
return out.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("gzip compress error", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] decompress(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
throw new NullPointerException("bytes is null");
|
||||
}
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
try (GZIPInputStream gunzip = new GZIPInputStream(new ByteArrayInputStream(bytes))) {
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int n;
|
||||
while ((n = gunzip.read(buffer)) > -1) {
|
||||
out.write(buffer, 0, n);
|
||||
}
|
||||
return out.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("gzip decompress error", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
io.seata.compressor.gzip.GzipCompressor
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.gzip;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author jsbxyyx
|
||||
*/
|
||||
public class GzipCompressorTest {
|
||||
|
||||
@Test
|
||||
public void testCompressAndDecompress() {
|
||||
GzipCompressor compressor = new GzipCompressor();
|
||||
byte[] bytes = "aa".getBytes();
|
||||
bytes = compressor.compress(bytes);
|
||||
bytes = compressor.decompress(bytes);
|
||||
Assertions.assertEquals(new String(bytes), "aa");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.gzip;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
* @author jsbxyyx
|
||||
*/
|
||||
public class GzipUtilTest {
|
||||
|
||||
@Test
|
||||
public void test_compress() {
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
GzipUtil.compress(null);
|
||||
});
|
||||
|
||||
byte[] compress = GzipUtil.compress("aa".getBytes());
|
||||
int head = ((int) compress[0] & 0xff) | ((compress[1] << 8) & 0xff00);
|
||||
Assertions.assertEquals(GZIPInputStream.GZIP_MAGIC, head);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_decompress() {
|
||||
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
GzipUtil.decompress(null);
|
||||
});
|
||||
|
||||
Assertions.assertThrows(RuntimeException.class, () -> {
|
||||
GzipUtil.decompress(new byte[0]);
|
||||
});
|
||||
|
||||
Assertions.assertThrows(RuntimeException.class, () -> {
|
||||
byte[] bytes = {0x1, 0x2};
|
||||
GzipUtil.decompress(bytes);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_compressEqualDecompress() {
|
||||
|
||||
byte[] compress = GzipUtil.compress("aa".getBytes());
|
||||
|
||||
byte[] decompress = GzipUtil.decompress(compress);
|
||||
|
||||
Assertions.assertEquals("aa", new String(decompress));
|
||||
}
|
||||
|
||||
}
|
||||
42
compressor/seata-compressor-lz4/pom.xml
Normal file
42
compressor/seata-compressor-lz4/pom.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 1999-2019 Seata.io Group.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-compressor</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>seata-compressor-lz4</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>seata-compressor-lz4 ${project.version}</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.lz4</groupId>
|
||||
<artifactId>lz4-java</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.lz4;
|
||||
|
||||
import io.seata.common.loader.LoadLevel;
|
||||
import io.seata.core.compressor.Compressor;
|
||||
|
||||
/**
|
||||
* the Lz4 Compressor
|
||||
*
|
||||
* @author diguage
|
||||
*/
|
||||
@LoadLevel(name = "LZ4")
|
||||
public class Lz4Compressor implements Compressor {
|
||||
@Override
|
||||
public byte[] compress(byte[] bytes) {
|
||||
return Lz4Util.compress(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decompress(byte[] bytes) {
|
||||
return Lz4Util.decompress(bytes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.lz4;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.jpountz.lz4.LZ4BlockInputStream;
|
||||
import net.jpountz.lz4.LZ4BlockOutputStream;
|
||||
import net.jpountz.lz4.LZ4Compressor;
|
||||
import net.jpountz.lz4.LZ4Factory;
|
||||
import net.jpountz.lz4.LZ4FastDecompressor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* the Lz4 Util
|
||||
*
|
||||
* @author diguage
|
||||
*/
|
||||
public class Lz4Util {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Lz4Util.class);
|
||||
private static final int ARRAY_SIZE = 1024;
|
||||
|
||||
public static byte[] compress(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
throw new NullPointerException("bytes is null");
|
||||
}
|
||||
LZ4Compressor compressor = LZ4Factory.fastestInstance().fastCompressor();
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try (LZ4BlockOutputStream lz4BlockOutputStream
|
||||
= new LZ4BlockOutputStream(outputStream, ARRAY_SIZE, compressor)) {
|
||||
lz4BlockOutputStream.write(bytes);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("compress bytes error", e);
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
public static byte[] decompress(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
throw new NullPointerException("bytes is null");
|
||||
}
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(ARRAY_SIZE);
|
||||
|
||||
LZ4FastDecompressor decompressor = LZ4Factory.fastestInstance().fastDecompressor();
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
|
||||
try (LZ4BlockInputStream decompressedInputStream
|
||||
= new LZ4BlockInputStream(inputStream, decompressor)) {
|
||||
int count;
|
||||
byte[] buffer = new byte[ARRAY_SIZE];
|
||||
while ((count = decompressedInputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, count);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("decompress bytes error", e);
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
io.seata.compressor.lz4.Lz4Compressor
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.lz4;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author diguage
|
||||
*/
|
||||
|
||||
public class Lz4CompressorTest {
|
||||
@Test
|
||||
public void testCompressAndDecompress() {
|
||||
Lz4Compressor compressor = new Lz4Compressor();
|
||||
String content = "a0123456789";
|
||||
byte[] bytes = content.getBytes();
|
||||
bytes = compressor.compress(bytes);
|
||||
byte[] result = compressor.decompress(bytes);
|
||||
Assertions.assertEquals(new String(result), content);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.lz4;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author diguage
|
||||
*/
|
||||
class Lz4UtilTest {
|
||||
@Test
|
||||
public void testCompress() {
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
Lz4Util.compress(null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecompress() {
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
Lz4Util.decompress(null);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
39
compressor/seata-compressor-zip/pom.xml
Normal file
39
compressor/seata-compressor-zip/pom.xml
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 1999-2019 Seata.io Group.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-compressor</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>seata-compressor-zip</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>seata-compressor-zip ${project.version}</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>seata-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.zip;
|
||||
|
||||
import io.seata.common.loader.LoadLevel;
|
||||
import io.seata.core.compressor.Compressor;
|
||||
|
||||
/**
|
||||
* the Zip Compressor
|
||||
*
|
||||
* @author ph3636
|
||||
*/
|
||||
@LoadLevel(name = "ZIP")
|
||||
public class ZipCompressor implements Compressor {
|
||||
|
||||
@Override
|
||||
public byte[] compress(byte[] bytes) {
|
||||
return ZipUtil.compress(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decompress(byte[] bytes) {
|
||||
return ZipUtil.decompress(bytes);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.zip;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
* the Zip Util
|
||||
*
|
||||
* @author ph3636
|
||||
*/
|
||||
public class ZipUtil {
|
||||
|
||||
private static final int BUFFER_SIZE = 8192;
|
||||
|
||||
public static byte[] compress(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
throw new NullPointerException("bytes is null");
|
||||
}
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
try (ZipOutputStream zip = new ZipOutputStream(out)) {
|
||||
ZipEntry entry = new ZipEntry("zip");
|
||||
entry.setSize(bytes.length);
|
||||
zip.putNextEntry(entry);
|
||||
zip.write(bytes);
|
||||
zip.closeEntry();
|
||||
return out.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Zip compress error", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] decompress(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
throw new NullPointerException("bytes is null");
|
||||
}
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
try (ZipInputStream zip = new ZipInputStream(new ByteArrayInputStream(bytes))) {
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
while (zip.getNextEntry() != null) {
|
||||
int n;
|
||||
while ((n = zip.read(buffer)) > -1) {
|
||||
out.write(buffer, 0, n);
|
||||
}
|
||||
}
|
||||
return out.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Zip decompress error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
io.seata.compressor.zip.ZipCompressor
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.zip;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* the Zip Compressor test
|
||||
*
|
||||
* @author ph3636
|
||||
*/
|
||||
public class ZipCompressorTest {
|
||||
|
||||
@Test
|
||||
public void testCompressAndDecompress() {
|
||||
ZipCompressor compressor = new ZipCompressor();
|
||||
byte[] bytes = "aa".getBytes();
|
||||
bytes = compressor.compress(bytes);
|
||||
bytes = compressor.decompress(bytes);
|
||||
Assertions.assertEquals(new String(bytes), "aa");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 1999-2019 Seata.io Group.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.seata.compressor.zip;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
/**
|
||||
* the Zip Util test
|
||||
*
|
||||
* @author ph3636
|
||||
*/
|
||||
public class ZipUtilTest {
|
||||
|
||||
@Test
|
||||
public void test_compress() {
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
ZipUtil.compress(null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_decompress() {
|
||||
Assertions.assertThrows(NullPointerException.class, () -> {
|
||||
ZipUtil.decompress(null);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user