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