/** * Note that seek() is not supported if this ctor is used. * @param stream source of bytes */ public BlockCompressedInputStream(final InputStream stream) { this(stream, true, BlockGunzipper.getDefaultInflaterFactory()); }
/** * Determines whether or not the inflater will re-calculated the CRC on the decompressed data * and check it against the value stored in the GZIP header. CRC checking is an expensive * operation and should be used accordingly. */ public void setCheckCrcs(final boolean check) { this.blockGunzipper.setCheckCrcs(check); }
/** * Decompress GZIP-compressed data * @param uncompressedBlock must be big enough to hold decompressed output. * @param compressedBlock compressed data starting at offset 0 * @param compressedLength size of compressed data, possibly less than the size of the buffer. * @return the uncompressed data size. */ public int unzipBlock(byte[] uncompressedBlock, byte[] compressedBlock, int compressedLength) { return unzipBlock(uncompressedBlock, 0, compressedBlock, 0, compressedLength); }
public void initializeCompressionAndDecompression() { // Use the Intel Inflater/Deflater for accelerated BAM reading/writing, if possible: if (! getArguments().useJdkDeflater) { BlockCompressedOutputStream.setDefaultDeflaterFactory(new IntelDeflaterFactory()); } if (! getArguments().useJdkInflater) { BlockGunzipper.setDefaultInflaterFactory(new IntelInflaterFactory()); } final boolean usingIntelDeflater = (BlockCompressedOutputStream.getDefaultDeflaterFactory() instanceof IntelDeflaterFactory && ((IntelDeflaterFactory)BlockCompressedOutputStream.getDefaultDeflaterFactory()).usingIntelDeflater()); logger.info("Deflater: " + (usingIntelDeflater ? "IntelDeflater": "JdkDeflater")); final boolean usingIntelInflater = (BlockGunzipper.getDefaultInflaterFactory() instanceof IntelInflaterFactory && ((IntelInflaterFactory)BlockGunzipper.getDefaultInflaterFactory()).usingIntelInflater()); logger.info("Inflater: " + (usingIntelInflater ? "IntelInflater": "JdkInflater")); }
/** * For providing some arbitrary data source. No additional buffering is * provided, so if the underlying source is not buffered, wrap it in a * SeekableBufferedStream before passing to this ctor. * @param strm source of bytes * @param inflaterFactory {@link InflaterFactory} used by {@link BlockGunzipper} */ public BlockCompressedInputStream(final SeekableStream strm, final InflaterFactory inflaterFactory) { mFile = strm; mStream = null; blockGunzipper = new BlockGunzipper(inflaterFactory); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testSetNullInflaterFactory() { // test catching null InflaterFactory BlockGunzipper.setDefaultInflaterFactory(null); } }
BlockGunzipper.setDefaultInflaterFactory(new IntelInflaterFactory()); final boolean usingIntelInflater = (BlockGunzipper.getDefaultInflaterFactory() instanceof IntelInflaterFactory && ((IntelInflaterFactory)BlockGunzipper.getDefaultInflaterFactory()).usingIntelInflater()); final String msg = String.format( "[%s] Executing as %s@%s on %s %s %s; %s %s; Deflater: %s; Inflater: %s; %s Picard version: %s",
/** * For providing some arbitrary data source. No additional buffering is * provided, so if the underlying source is not buffered, wrap it in a * SeekableBufferedStream before passing to this ctor. * @param strm source of bytes * @param inflaterFactory {@link InflaterFactory} used by {@link BlockGunzipper} */ public BlockCompressedInputStream(final SeekableStream strm, final InflaterFactory inflaterFactory) { mFile = strm; mStream = null; blockGunzipper = new BlockGunzipper(inflaterFactory); }
@Test(dataProvider = "customInflaterInput", singleThreaded = true) public void testCustomInflater(final CheckedExceptionInputStreamSupplier bcisSupplier, final List<String> expectedOutput, final int expectedInflateCalls, final InflaterFactory customDefaultInflaterFactory) throws Exception { // clear inflate call counter in CountingInflater CountingInflater.inflateCalls = 0; // If requested, set the global default InflaterFactory to a custom factory. Otherwise, set it to the default. if ( customDefaultInflaterFactory != null ) { BlockGunzipper.setDefaultInflaterFactory(customDefaultInflaterFactory); } else { BlockGunzipper.setDefaultInflaterFactory(new InflaterFactory()); } try (final BufferedReader reader = new BufferedReader(new InputStreamReader(bcisSupplier.get()))) { String line; for (int i = 0; (line = reader.readLine()) != null; ++i) { // check expected output, if provided if (expectedOutput != null) { Assert.assertEquals(line + "\n", expectedOutput.get(i)); } } } // verify custom inflater was used by checking number of inflate calls Assert.assertEquals(CountingInflater.inflateCalls, expectedInflateCalls, "inflate calls"); // Reset the default InflaterFactory back to the default value BlockGunzipper.setDefaultInflaterFactory(new InflaterFactory()); }
/** * @param url source of bytes */ public BlockCompressedInputStream(final URL url) { this(url, BlockGunzipper.getDefaultInflaterFactory()); }
BlockGunzipper.setDefaultInflaterFactory(new IntelInflaterFactory()); final boolean usingIntelInflater = (BlockGunzipper.getDefaultInflaterFactory() instanceof IntelInflaterFactory && ((IntelInflaterFactory)BlockGunzipper.getDefaultInflaterFactory()).usingIntelInflater()); final String msg = String.format( "[%s] Executing as %s@%s on %s %s %s; %s %s; Deflater: %s; Inflater: %s; %s Picard version: %s",
/** * For providing some arbitrary data source. No additional buffering is * provided, so if the underlying source is not buffered, wrap it in a * SeekableBufferedStream before passing to this ctor. * @param strm source of bytes * @param inflaterFactory {@link InflaterFactory} used by {@link BlockGunzipper} */ public BlockCompressedInputStream(final SeekableStream strm, final InflaterFactory inflaterFactory) { mFile = strm; mStream = null; blockGunzipper = new BlockGunzipper(inflaterFactory); }
/** * Decompress GZIP-compressed data * @param uncompressedBlock must be big enough to hold decompressed output. * @param compressedBlock compressed data starting at offset 0 * @param compressedLength size of compressed data, possibly less than the size of the buffer. * @return the uncompressed data size. */ public int unzipBlock(byte[] uncompressedBlock, byte[] compressedBlock, int compressedLength) { return unzipBlock(uncompressedBlock, 0, compressedBlock, 0, compressedLength); }
/** * Determines whether or not the inflater will re-calculated the CRC on the decompressed data * and check it against the value stored in the GZIP header. CRC checking is an expensive * operation and should be used accordingly. */ public void setCheckCrcs(final boolean check) { this.blockGunzipper.setCheckCrcs(check); }
/** * Use this ctor if you wish to call seek() * @param file source of bytes * @throws IOException */ public BlockCompressedInputStream(final File file) throws IOException { this(file, BlockGunzipper.getDefaultInflaterFactory()); }
/** * Use this ctor if you wish to call seek() * @param file source of bytes * @param inflaterFactory {@link InflaterFactory} used by {@link BlockGunzipper} * @throws IOException */ public BlockCompressedInputStream(final File file, final InflaterFactory inflaterFactory) throws IOException { mFile = new SeekableFileStream(file); mStream = null; blockGunzipper = new BlockGunzipper(inflaterFactory); }
private void inflateBlock(final byte[] compressedBlock, final int compressedLength) throws IOException { final int uncompressedLength = unpackInt32(compressedBlock, compressedLength-4); byte[] buffer = mCurrentBlock; mCurrentBlock = null; if (buffer == null || buffer.length != uncompressedLength) { try { buffer = new byte[uncompressedLength]; } catch (final NegativeArraySizeException e) { throw new RuntimeException("BGZF file has invalid uncompressedLength: " + uncompressedLength, e); } } blockGunzipper.unzipBlock(buffer, compressedBlock, compressedLength); mCurrentBlock = buffer; }
/** * Determines whether or not the inflater will re-calculated the CRC on the decompressed data * and check it against the value stored in the GZIP header. CRC checking is an expensive * operation and should be used accordingly. */ public void setCheckCrcs(final boolean check) { this.blockGunzipper.setCheckCrcs(check); }
/** * @param url source of bytes */ public BlockCompressedInputStream(final URL url) { this(url, BlockGunzipper.getDefaultInflaterFactory()); }
/** * Use this ctor if you wish to call seek() * @param file source of bytes * @param inflaterFactory {@link InflaterFactory} used by {@link BlockGunzipper} * @throws IOException */ public BlockCompressedInputStream(final File file, final InflaterFactory inflaterFactory) throws IOException { mFile = new SeekableFileStream(file); mStream = null; blockGunzipper = new BlockGunzipper(inflaterFactory); }