All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ning.compress.lzf.parallel.BlockManager Maven / Gradle / Ivy

Go to download

Compression codec for LZF encoding for particularly encoding/decoding, with reasonable compression. Compressor is basic Lempel-Ziv codec, without Huffman (deflate/gzip) or statistical post-encoding. See "http://oldhome.schmorp.de/marc/liblzf.html" for more on original LZF package.

There is a newer version: 1.1.2
Show newest version
package com.ning.compress.lzf.parallel;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * @author Cédrik LIME
 */
class BlockManager {
    /* used as a blocking Stack (FIFO) */
    private final BlockingDeque blockPool;

    public BlockManager(int blockPoolSize, int blockSize) {
//        log.debug("Using block pool size of " + blockPoolSize);
        blockPool = new LinkedBlockingDeque(blockPoolSize);
        for (int i = 0; i < blockPoolSize; ++i) {
            blockPool.addFirst(new byte[blockSize]);
        }
    }

    public byte[] getBlockFromPool() {
        byte[] block = null;
        try {
            block = blockPool.takeFirst();
        } catch (InterruptedException e) {
        	throw new RuntimeException(e);
        }
        return block;
    }

    public void releaseBlockToPool(byte[] block) {
        assert ! blockPool.contains(block);
//        Arrays.fill(block, (byte)0);
        try {
            blockPool.putLast(block);
        } catch (InterruptedException e) {
        	throw new RuntimeException(e);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy