Fix CompressedObjectStrategy LZFCompressor to ignore error on close of ResourceHolder

This commit is contained in:
Charles Allen 2014-11-21 10:49:43 -08:00
parent f8ce68565b
commit fc9a54ea48
1 changed files with 43 additions and 44 deletions

View File

@ -46,8 +46,7 @@ public class CompressedObjectStrategy<T extends Buffer> implements ObjectStrateg
public static enum CompressionStrategy public static enum CompressionStrategy
{ {
LZF((byte) 0x0) LZF((byte) 0x0) {
{
@Override @Override
public Decompressor getDecompressor() public Decompressor getDecompressor()
{ {
@ -61,8 +60,7 @@ public class CompressedObjectStrategy<T extends Buffer> implements ObjectStrateg
} }
}, },
LZ4((byte) 0x1) LZ4((byte) 0x1) {
{
@Override @Override
public Decompressor getDecompressor() public Decompressor getDecompressor()
{ {
@ -75,8 +73,7 @@ public class CompressedObjectStrategy<T extends Buffer> implements ObjectStrateg
return LZ4Compressor.defaultCompressor; return LZ4Compressor.defaultCompressor;
} }
}, },
UNCOMPRESSED((byte) 0xFF) UNCOMPRESSED((byte) 0xFF) {
{
@Override @Override
public Decompressor getDecompressor() public Decompressor getDecompressor()
{ {
@ -212,13 +209,15 @@ public class CompressedObjectStrategy<T extends Buffer> implements ObjectStrateg
@Override @Override
public byte[] compress(byte[] bytes) public byte[] compress(byte[] bytes)
{ {
LZFChunk chunk = null;
try (final ResourceHolder<ChunkEncoder> encoder = CompressedPools.getChunkEncoder()) { try (final ResourceHolder<ChunkEncoder> encoder = CompressedPools.getChunkEncoder()) {
LZFChunk chunk = encoder.get().encodeChunk(bytes, 0, bytes.length); chunk = encoder.get().encodeChunk(bytes, 0, bytes.length);
return chunk.getData();
} }
catch (IOException e) { catch (IOException e) {
throw Throwables.propagate(e); // Silently Ignore if error on close
} }
// IOException should be on ResourceHolder.close(), not encodeChunk, so this *should* never be null
return null == chunk ? null : chunk.getData();
} }
} }