chore(project): 添加项目配置文件和忽略规则
- 添加 Babel 配置文件支持 ES6+ 语法转换 - 添加 ESLint 忽略规则和配置文件 - 添加 Git 忽略规则文件 - 添加 Travis CI 配置文件 - 添加 1.4.2 版本变更日志文件 - 添加 Helm 图表辅助模板文件 - 添加 Helm 忽略规则文件
This commit is contained in:
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);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user