package de.samaflost.commons_compress;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
import org.apache.commons.compress.utils.IOUtils;
import org.openjdk.jmh.annotations.Benchmark;

public class BZip2CompressionBenchmark {

    private static final byte[] SMALL_FILE;

    static {
        try {
            try (InputStream in = BZip2CompressionBenchmark.class.getResourceAsStream("/bla.tar")) {
                SMALL_FILE = IOUtils.toByteArray(in);
            }
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }

    @Benchmark
    public void compressSmallFile() throws IOException {
        try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
             BZip2CompressorOutputStream bout = new BZip2CompressorOutputStream(baos);
             ByteArrayInputStream in = new ByteArrayInputStream(SMALL_FILE)) {
            IOUtils.copy(in, bout);
        }
    }

}

@@ -163,16 +163,37 @@
 tStream;
+%0Aimport java.net.URL;
 %0A%0Aimport
@@ -264,24 +264,103 @@
 tputStream;%0A
+import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;%0A
 import org.a
@@ -529,16 +529,61 @@
 LL_FILE;
+%0A    private static final byte%5B%5D BIGGER_FILE;
 %0A%0A    st
@@ -784,143 +784,688 @@
     
-%7D catch (Exception ex) %7B%0A            throw new RuntimeException(ex);%0A        %7D%0A    %7D%0A%0A    @Benchmark%0A    public void compressSmallFile(
+    try (InputStream fromUrl = new URL(%22http://archive.apache.org/dist/commons/compress/source/commons-compress-1.13-src.tar.gz%22)%0A                     .openStream();%0A                 GzipCompressorInputStream gzIn = new GzipCompressorInputStream(fromUrl)) %7B%0A                BIGGER_FILE = IOUtils.toByteArray(gzIn);%0A            %7D%0A        %7D catch (Exception ex) %7B%0A            throw new RuntimeException(ex);%0A        %7D%0A    %7D%0A%0A    @Benchmark%0A    public void compressSmallFile() throws IOException %7B%0A        compress(SMALL_FILE);%0A    %7D%0A%0A    @Benchmark%0A    public void compressBiggerFile() throws IOException %7B%0A        compress(BIGGER_FILE);%0A    %7D%0A%0A    private void compress(byte%5B%5D data
 ) th
@@ -1705,26 +1705,20 @@
 tStream(
-SMALL_FILE
+data
 )) %7B%0A   

test with a bigger file to compress