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

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

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

import com.aliyun.datahub.client.model.CompressType;

import java.io.*;

public abstract class Compressor {
    private CompressType type;

    protected Compressor(CompressType type) {
        this.type = type;
    }

    public CompressType getType() {
        return type;
    }

    public byte[] compress(byte[] input) throws IOException {
        return compress(input, 0, input.length);
    }

    public byte[] compress(byte[] input, int offset, int length) throws IOException {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ByteArrayInputStream inputStream = new ByteArrayInputStream(input, offset, length);
        compress(inputStream, outputStream);
        return outputStream.toByteArray();
    }

    public byte[] decompress(byte[] input, int oriSize) throws IOException {
        return decompress(input, 0, input.length, oriSize);
    }

    public byte[] decompress(byte[] input, int offset, int length, int oriSize) throws IOException {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ByteArrayInputStream inputStream = new ByteArrayInputStream(input, offset, length);
        decompress(inputStream, outputStream, oriSize);
        return outputStream.toByteArray();
    }

    public abstract void compress(InputStream inputStream, OutputStream outputStream) throws IOException;

    public abstract void decompress(InputStream inputStream, OutputStream outputStream, int oriSize) throws IOException;

    public abstract InputStream decompress(InputStream inputStream, int oriSize) throws IOException;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy