com.ning.compress.lzf.parallel.BlockManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of compress-lzf Show documentation
Show all versions of compress-lzf Show documentation
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.
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);
}
}
}