| 43 | private static final int MAX_PER_KIND = 32; |
| 44 | |
| 45 | public static CompressionCodec getCodec(CompressionKind kind) { |
| 46 | if (kind == CompressionKind.NONE) return null; |
| 47 | CompressionCodec codec = null; |
| 48 | List<CompressionCodec> codecList = POOL.get(kind); |
| 49 | if (codecList != null) { |
| 50 | synchronized (codecList) { |
| 51 | if (!codecList.isEmpty()) { |
| 52 | codec = codecList.remove(codecList.size() - 1); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | if (codec == null) { |
| 57 | codec = WriterImpl.createCodec(kind); |
| 58 | LOG.debug("Got brand-new codec {}", kind); |
| 59 | } else { |
| 60 | LOG.debug("Got recycled codec"); |
| 61 | } |
| 62 | return codec; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns the codec to the pool or closes it, suppressing exceptions. |