Use Input/Outputstream classes instead of own implementation

This commit is contained in:
Mark Vainomaa 2018-01-28 21:09:17 +02:00
parent 861dd06286
commit 6c79bf8514
Signed by: mikroskeem
GPG Key ID: 1B3F9523B542D315

View File

@ -1,10 +1,14 @@
package eu.mikroskeem.uurimustoo.algoritmidetest.algoritmid;
import lombok.Getter;
import org.meteogroup.jbrotli.BrotliStreamCompressor;
import org.meteogroup.jbrotli.BrotliStreamDeCompressor;
import org.meteogroup.jbrotli.io.BrotliInputStream;
import org.meteogroup.jbrotli.io.BrotliOutputStream;
import org.meteogroup.jbrotli.libloader.BrotliLibraryLoader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
* @author Mark Vainomaa
*/
@ -16,16 +20,12 @@ public class Brotli extends AbstractAlgorithm {
}
@Override
public byte[] compress(byte[] input) {
BrotliStreamCompressor compressor = new BrotliStreamCompressor();
return compressor.compressArray(input, true);
public OutputStream createCompressor(OutputStream outputStream) throws IOException {
return new BrotliOutputStream(outputStream);
}
@Override
public byte[] decompress(byte[] input) {
BrotliStreamDeCompressor decompressor = new BrotliStreamDeCompressor();
byte[] buf = new byte[8192]; // *sigh*
decompressor.deCompress(input, buf);
return buf;
public InputStream createDecompressor(InputStream inputStream) throws IOException {
return new BrotliInputStream(inputStream);
}
}