All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aliyun.datahub.client.impl.compress.DeflateCompressor Maven / Gradle / Ivy

The newest version!
package com.aliyun.datahub.client.impl.compress;

import com.aliyun.datahub.client.model.CompressType;
import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;

public class DeflateCompressor extends Compressor {

    public DeflateCompressor() {
        super(CompressType.DEFLATE);
    }

    @Override
    public void compress(InputStream inputStream, OutputStream outputStream) throws IOException {
        try (DeflaterOutputStream dos = new DeflaterOutputStream(outputStream)) {
            IOUtils.copy(inputStream, dos);
        }
    }

    @Override
    public void decompress(InputStream inputStream, OutputStream outputStream, int oriSize) throws IOException {
        try (InflaterInputStream iis = new InflaterInputStream(inputStream)) {
            IOUtils.copy(iis, outputStream);
        }
    }

    @Override
    public InputStream decompress(InputStream inputStream, int oriSize) throws IOException {
        return new InflaterInputStream(inputStream);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy