com.aliyun.datahub.client.impl.compress.ZstdCompressor Maven / Gradle / Ivy
The newest version!
package com.aliyun.datahub.client.impl.compress;
import com.aliyun.datahub.client.model.CompressType;
import com.github.luben.zstd.RecyclingBufferPool;
import com.github.luben.zstd.ZstdInputStream;
import com.github.luben.zstd.ZstdOutputStream;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class ZstdCompressor extends Compressor {
public ZstdCompressor() {
super(CompressType.ZSTD);
}
@Override
public void compress(InputStream inputStream, OutputStream outputStream) throws IOException {
try (ZstdOutputStream zos = new ZstdOutputStream(outputStream, RecyclingBufferPool.INSTANCE)) {
IOUtils.copy(inputStream, zos);
}
}
@Override
public void decompress(InputStream inputStream, OutputStream outputStream, int oriSize) throws IOException {
try (ZstdInputStream zis = new ZstdInputStream(inputStream, RecyclingBufferPool.INSTANCE)) {
IOUtils.copy(zis, outputStream);
}
}
@Override
public InputStream decompress(InputStream inputStream, int oriSize) throws IOException {
return new ZstdInputStream(inputStream, RecyclingBufferPool.INSTANCE);
}
}