/** * Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. * If no byte is available because the end of the stream has been reached, the value -1 is returned. * This method blocks until input data is available, the end of the stream is detected, or an exception is thrown. * @return the next byte of data, or -1 if the end of the stream is reached. */ public int read() throws IOException { return (available() > 0) ? (mCurrentBlock[mCurrentOffset++] & 0xFF) : -1; }
/** * Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. * If no byte is available because the end of the stream has been reached, the value -1 is returned. * This method blocks until input data is available, the end of the stream is detected, or an exception is thrown. * @return the next byte of data, or -1 if the end of the stream is reached. */ @Override public int read() throws IOException { return (available() > 0) ? (mCurrentBlock.mBlock[mCurrentOffset++] & 0xFF) : -1; }
/** * Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. * If no byte is available because the end of the stream has been reached, the value -1 is returned. * This method blocks until input data is available, the end of the stream is detected, or an exception is thrown. * @return the next byte of data, or -1 if the end of the stream is reached. */ @Override public int read() throws IOException { return (available() > 0) ? (mCurrentBlock.mBlock[mCurrentOffset++] & 0xFF) : -1; }
/** * Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. * If no byte is available because the end of the stream has been reached, the value -1 is returned. * This method blocks until input data is available, the end of the stream is detected, or an exception is thrown. * @return the next byte of data, or -1 if the end of the stream is reached. */ @Override public int read() throws IOException { return (available() > 0) ? (mCurrentBlock.getUncompressedBlock()[mCurrentOffset++] & 0xFF) : -1; }
final int originalLength = length; while (length > 0) { final int available = available(); if (available == 0) {
final int originalLength = length; while (length > 0) { final int available = available(); if (available == 0) {
final int originalLength = length; while (length > 0) { final int available = available(); if (available == 0) {
final int originalLength = length; while (length > 0) { final int available = available(); if (available == 0) {
/** * Read up to <code>len</code> bytes from the stream, but no further than the end of the * compressed block. If at the end of the block then no bytes will be read and a return * value of -2 will be returned; on the next call to read, bytes from the next block * will be returned. This is the same contract as CBZip2InputStream in Hadoop. * @return int The return value greater than 0 are the bytes read. A value * of -1 means end of stream while -2 represents end of block. */ private int readWithinBlock(byte[] b, int off, int len) throws IOException { if (input.endOfBlock()) { final int available = input.available(); // this will read the next block, if there is one processedPosition = input.getPosition() >> 16; if (available == 0) { // end of stream return -1; } return END_OF_BLOCK; } // return up to end of block (at most) int available = input.available(); return input.read(b, off, Math.min(available, len)); }
/** * Read up to <code>len</code> bytes from the stream, but no further than the end of the * compressed block. If at the end of the block then no bytes will be read and a return * value of -2 will be returned; on the next call to read, bytes from the next block * will be returned. This is the same contract as CBZip2InputStream in Hadoop. * @return int The return value greater than 0 are the bytes read. A value * of -1 means end of stream while -2 represents end of block. */ private int readWithinBlock(byte[] b, int off, int len) throws IOException { if (input.endOfBlock()) { final int available = input.available(); // this will read the next block, if there is one processedPosition = input.getPosition() >> 16; if (available == 0) { // end of stream return -1; } return END_OF_BLOCK; } // return up to end of block (at most) int available = input.available(); return input.read(b, off, Math.min(available, len)); }
/** * Read up to <code>len</code> bytes from the stream, but no further than the end of the * compressed block. If at the end of the block then no bytes will be read and a return * value of -2 will be returned; on the next call to read, bytes from the next block * will be returned. This is the same contract as CBZip2InputStream in Hadoop. * @return int The return value greater than 0 are the bytes read. A value * of -1 means end of stream while -2 represents end of block. */ private int readWithinBlock(byte[] b, int off, int len) throws IOException { if (input.endOfBlock()) { final int available = input.available(); // this will read the next block, if there is one processedPosition = input.getPosition() >> 16; if (available == 0) { // end of stream return -1; } return END_OF_BLOCK; } // return up to end of block (at most) int available = input.available(); return input.read(b, off, Math.min(available, len)); }
public static void main(String[] args) throws IOException { Params params = new Params(); JCommander jc = new JCommander(params); jc.parse(args); for (File file : params.files) { log.info("Indexing file: " + file.getAbsolutePath()); BlockCompressedInputStream bcis = new BlockCompressedInputStream(new SeekableFileStream(file)); bcis.available(); BGZF_FastaIndexer mli = new BGZF_FastaIndexer(bcis); PrintWriter writer = new PrintWriter(file.getAbsolutePath() + ".fai"); FAIDX_FastaIndexEntry e; while (!writer.checkError() && (e = mli.readNext()) != null) writer.println(e); writer.close(); } }
@Test public void available_should_return_number_of_bytes_left_in_current_block() throws Exception { try (BlockCompressedInputStream stream = new BlockCompressedInputStream(BLOCK_COMPRESSED)) { for (int i = 0; i < BLOCK_UNCOMPRESSED_END_POSITIONS[0]; i++) { Assert.assertEquals(stream.available(), BLOCK_UNCOMPRESSED_END_POSITIONS[0] - i); stream.read(); } } }
mLastBlockLength = 0; readBlock(); available = available();
validatingInputStream.available();
mCurrentBlock = nextBlock(getBufferForReuse(mCurrentBlock)); mCurrentOffset = 0; available = available();
mCurrentBlock = nextBlock(getBufferForReuse(mCurrentBlock)); mCurrentOffset = 0; available = available();
mStreamOffset = compressedOffset; readBlock(); available = available();
int available = bcis2.available(); Assert.assertFalse(bcis2.endOfBlock(), "Should not be at end of block"); Assert.assertTrue(available > 0);