public void resetState() throws IOException { output.flush(); output = new BlockCompressedOutputStream(out, null); }
/** * Writes b.length bytes from the specified byte array to this output stream. The general contract for write(b) * is that it should have exactly the same effect as the call write(b, 0, b.length). * @param bytes the data */ @Override public void write(final byte[] bytes) throws IOException { write(bytes, 0, bytes.length); }
@Override public long getPosition() { return getFilePointer(); }
BlockCompressedOutputStream writer = new BlockCompressedOutputStream(outFile); long filePosition= writer.getFilePointer(); String line = lin.next(); GtfLine gtf= new GtfLine(line.split("\t")); writer.write(line.getBytes()); writer.write('\n'); indexCreator.addFeature(gtf, filePosition); filePosition = writer.getFilePointer(); writer.flush(); writer.close(); throw new RuntimeException("Index file exists: " + tbi); Index index = indexCreator.finalizeIndex(writer.getFilePointer()); index.writeBasedOnFeatureFile(outFile); writer.close();
public BCFStoppableOutputStream(boolean startStopped, OutputStream out) { super(new BlockCompressedOutputStream(out, null)); origOut = out; stopped = startStopped; }
private List<String> writeTempBlockCompressedFileForInflaterTest( final File tempFile ) throws IOException { final List<String> linesWritten = new ArrayList<>(); try ( final BlockCompressedOutputStream bcos = new BlockCompressedOutputStream(tempFile, 5) ) { String s = "Hi, Mom!\n"; bcos.write(s.getBytes()); //Call 1 linesWritten.add(s); s = "Hi, Dad!\n"; bcos.write(s.getBytes()); //Call 2 linesWritten.add(s); bcos.flush(); final StringBuilder sb = new StringBuilder(BlockCompressedStreamConstants.DEFAULT_UNCOMPRESSED_BLOCK_SIZE * 2); s = "1234567890123456789012345678901234567890123456789012345678901234567890\n"; while ( sb.length() <= BlockCompressedStreamConstants.DEFAULT_UNCOMPRESSED_BLOCK_SIZE ) { sb.append(s); linesWritten.add(s); } bcos.write(sb.toString().getBytes()); //Call 3 } return linesWritten; }
@Test(groups = "broken") public void testDevNull() throws Exception { final BlockCompressedOutputStream bcos = new BlockCompressedOutputStream("/dev/null"); bcos.write("Hi, Mom!".getBytes()); bcos.close(); }
private long populateMultiBlockCompressedFile(final File tempBlockCompressedFile) throws IOException { long sentinelLineOffset = -1; try (BlockCompressedOutputStream bcos = new BlockCompressedOutputStream(tempBlockCompressedFile)) { // write lines until we exceed the size of the first block (block address != 0) do { bcos.write("Write this line enough times to exceed the size or a compressed block\n".getBytes()); } while (BlockCompressedFilePointerUtil.getBlockAddress(bcos.getFilePointer()) == 0); sentinelLineOffset = bcos.getFilePointer(); // write a terminating line that is guaranteed to not be in the first block bcos.write(sentinelLine.getBytes()); } return sentinelLineOffset; } }
public void finish() throws IOException { output.flush(); }
BlockCompressedOutputStream.setDefaultCompressionLevel(COMPRESSION_LEVEL); BlockCompressedOutputStream.setDefaultDeflaterFactory(new IntelDeflaterFactory()); .collect(Collectors.joining(" ")); final boolean usingIntelDeflater = (BlockCompressedOutputStream.getDefaultDeflaterFactory() instanceof IntelDeflaterFactory && ((IntelDeflaterFactory)BlockCompressedOutputStream.getDefaultDeflaterFactory()).usingIntelDeflater()); final boolean usingIntelInflater = (BlockGunzipper.getDefaultInflaterFactory() instanceof IntelInflaterFactory && ((IntelInflaterFactory)BlockGunzipper.getDefaultInflaterFactory()).usingIntelInflater());
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")); }
/** * Writes len bytes from the specified byte array starting at offset off to this output stream. The general * contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; * element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation. * * @param bytes the data * @param startIndex the start offset in the data * @param numBytes the number of bytes to write */ @Override public void write(final byte[] bytes, int startIndex, int numBytes) throws IOException { assert(numUncompressedBytes < uncompressedBuffer.length); while (numBytes > 0) { final int bytesToWrite = Math.min(uncompressedBuffer.length - numUncompressedBytes, numBytes); System.arraycopy(bytes, startIndex, uncompressedBuffer, numUncompressedBytes, bytesToWrite); numUncompressedBytes += bytesToWrite; startIndex += bytesToWrite; numBytes -= bytesToWrite; assert(numBytes >= 0); if (numUncompressedBytes == uncompressedBuffer.length) { deflateBlock(); } } }
BlockCompressedOutputStream writer = new BlockCompressedOutputStream(bgzfOut); long filePosition= writer.getFilePointer(); writer.write((line + "\n").getBytes()); filePosition = writer.getFilePointer(); continue; writer.write(line.getBytes()); writer.write('\n'); filePosition = writer.getFilePointer(); } catch(Exception e){ if(e.getMessage().contains("added out sequence of order") || e.getMessage().contains("Features added out of order")){ writer.close(); throw new InvalidRecordException(); writer.flush(); Index index = indexCreator.finalizeIndex(writer.getFilePointer()); index.writeBasedOnFeatureFile(bgzfOut); writer.close(); CloserUtil.close(lin);
public BGZFCompressionOutputStream(OutputStream out) throws IOException { super(out); this.output = new BlockCompressedOutputStream(out, null); }
final BlockCompressedOutputStream blockOut = new BlockCompressedOutputStream(out, (Path)null); blockOut.write(blockContents, firstNonHeaderByteIndex, blockContents.length - firstNonHeaderByteIndex); blockOut.flush();
private static File getValidCompressedFile() throws IOException { final File tmpCompressedFile = File.createTempFile("test.", ".bgzf"); tmpCompressedFile.deleteOnExit(); final BlockCompressedOutputStream os = new BlockCompressedOutputStream(tmpCompressedFile); os.write("Hi, Mom!\n".getBytes()); os.close(); return tmpCompressedFile; }
public void finish() throws IOException { output.flush(); }
BlockCompressedOutputStream.setDefaultCompressionLevel(COMPRESSION_LEVEL); BlockCompressedOutputStream.setDefaultDeflaterFactory(new IntelDeflaterFactory()); .collect(Collectors.joining(" ")); final boolean usingIntelDeflater = (BlockCompressedOutputStream.getDefaultDeflaterFactory() instanceof IntelDeflaterFactory && ((IntelDeflaterFactory)BlockCompressedOutputStream.getDefaultDeflaterFactory()).usingIntelDeflater()); final boolean usingIntelInflater = (BlockGunzipper.getDefaultInflaterFactory() instanceof IntelInflaterFactory && ((IntelInflaterFactory)BlockGunzipper.getDefaultInflaterFactory()).usingIntelInflater());
/** * Writes len bytes from the specified byte array starting at offset off to this output stream. The general * contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; * element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation. * * @param bytes the data * @param startIndex the start offset in the data * @param numBytes the number of bytes to write */ @Override public void write(final byte[] bytes, int startIndex, int numBytes) throws IOException { assert(numUncompressedBytes < uncompressedBuffer.length); while (numBytes > 0) { final int bytesToWrite = Math.min(uncompressedBuffer.length - numUncompressedBytes, numBytes); System.arraycopy(bytes, startIndex, uncompressedBuffer, numUncompressedBytes, bytesToWrite); numUncompressedBytes += bytesToWrite; startIndex += bytesToWrite; numBytes -= bytesToWrite; assert(numBytes >= 0); if (numUncompressedBytes == uncompressedBuffer.length) { deflateBlock(); } } }
final BlockCompressedOutputStream bcos = new BlockCompressedOutputStream(f, 5, myDeflaterFactory); String s = "Hi, Mom!\n"; bcos.write(s.getBytes()); //Call 1 linesWritten.add(s); s = "Hi, Dad!\n"; bcos.write(s.getBytes()); //Call 2 linesWritten.add(s); bcos.flush(); final StringBuilder sb = new StringBuilder(BlockCompressedStreamConstants.DEFAULT_UNCOMPRESSED_BLOCK_SIZE * 2); s = "1234567890123456789012345678901234567890123456789012345678901234567890\n"; linesWritten.add(s); bcos.write(sb.toString().getBytes()); //Call 3 bcos.close(); final BlockCompressedInputStream bcis = new BlockCompressedInputStream(f); final BufferedReader reader = new BufferedReader(new InputStreamReader(bcis));