// 
// Decompiled by Procyon v0.6.0
// 

package com.github.luben.zstd;

import com.github.luben.zstd.util.Native;
import java.nio.ByteBuffer;

public class ZstdDictDecompress extends SharedDictBase
{
    private long nativePtr;
    private ByteBuffer sharedDict;
    
    private native void init(final byte[] p0, final int p1, final int p2);
    
    private native void initDirect(final ByteBuffer p0, final int p1, final int p2, final int p3);
    
    private native void free();
    
    public ByteBuffer getByReferenceBuffer() {
        return this.sharedDict;
    }
    
    public ZstdDictDecompress(final byte[] array) {
        this(array, 0, array.length);
    }
    
    public ZstdDictDecompress(final byte[] array, final int n, final int n2) {
        this.nativePtr = 0L;
        this.sharedDict = null;
        this.init(array, n, n2);
        if (this.nativePtr == 0L) {
            throw new IllegalStateException("ZSTD_createDDict failed");
        }
        this.storeFence();
    }
    
    public ZstdDictDecompress(final ByteBuffer byteBuffer) {
        this(byteBuffer, false);
    }
    
    public ZstdDictDecompress(final ByteBuffer sharedDict, final boolean b) {
        this.nativePtr = 0L;
        this.sharedDict = null;
        final int n = sharedDict.limit() - sharedDict.position();
        if (!sharedDict.isDirect()) {
            throw new IllegalArgumentException("dict must be a direct buffer");
        }
        if (n < 0) {
            throw new IllegalArgumentException("dict cannot be empty.");
        }
        this.initDirect(sharedDict, sharedDict.position(), n, b ? 1 : 0);
        if (this.nativePtr == 0L) {
            throw new IllegalStateException("ZSTD_createDDict failed");
        }
        if (b) {
            this.sharedDict = sharedDict;
        }
        this.storeFence();
    }
    
    @Override
    void doClose() {
        if (this.nativePtr != 0L) {
            this.free();
            this.nativePtr = 0L;
            this.sharedDict = null;
        }
    }
    
    static {
        Native.load();
    }
}
