package com.intel.gkl.compression;

import htsjdk.samtools.util.zip.DeflaterFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.zip.Deflater;

public class IntelDeflaterFactory extends DeflaterFactory {

    private final static Logger logger = LogManager.getLogger(IntelDeflaterFactory.class);
    private boolean usingIntelDeflater;

    public Deflater makeDeflater(final int compressionLevel, final boolean nowrap) {
        boolean intelDeflaterSupported = new IntelDeflater().load();
        if (intelDeflaterSupported) {
            if ((compressionLevel == 1 && nowrap) || compressionLevel != 1) {
                usingIntelDeflater = true;
                return new IntelDeflater(compressionLevel, nowrap);
            }
        }
        logger.warn("IntelDeflater is not supported, using Java.util.zip.Deflater");
        usingIntelDeflater = false;
        return new Deflater(compressionLevel, nowrap);
    }

    public boolean usingIntelDeflater() {
        return usingIntelDeflater;
    }
}

@@ -163,16 +163,37 @@
 ogger;%0A%0A
+import java.io.File;%0A
 import j
@@ -215,16 +215,16 @@
 flater;%0A
-
 %0Apublic 
@@ -407,16 +407,188 @@
 eflater;
+%0A    private File tmpDir;%0A%0A    public IntelDeflaterFactory(File tmpDir) %7B%0A        this.tmpDir = tmpDir;%0A    %7D%0A%0A    public IntelDeflaterFactory() %7B%0A        this(null);%0A    %7D
 %0A%0A    pu
@@ -662,24 +662,24 @@
 n nowrap) %7B%0A
-
         bool
@@ -732,16 +732,22 @@
 ().load(
+tmpDir
 );%0A     

add tmpDir for shared object load