@Override public int available() throws IOException { if (uncompressedCursor < uncompressedLimit) { return uncompressedLimit - uncompressedCursor; } else { if (hasNextChunk()) { return uncompressedLimit - uncompressedCursor; } else { return 0; } } } }
/** * Reads up to len bytes of data from the input stream into an array of * bytes. */ /* (non-Javadoc) * @see java.io.InputStream#read(byte[], int, int) */ @Override public int read(byte[] b, int byteOffset, int byteLength) throws IOException { int writtenBytes = 0; for (; writtenBytes < byteLength; ) { if (uncompressedCursor >= uncompressedLimit) { if (hasNextChunk()) { continue; } else { return writtenBytes == 0 ? -1 : writtenBytes; } } int bytesToWrite = Math.min(uncompressedLimit - uncompressedCursor, byteLength - writtenBytes); System.arraycopy(uncompressed, uncompressedCursor, b, byteOffset + writtenBytes, bytesToWrite); writtenBytes += bytesToWrite; uncompressedCursor += bytesToWrite; } return writtenBytes; }
/** * Reads the next byte of uncompressed 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. */ /* (non-Javadoc) * @see java.io.InputStream#read() */ @Override public int read() throws IOException { if (uncompressedCursor < uncompressedLimit) { return uncompressed[uncompressedCursor++] & 0xFF; } else { if (hasNextChunk()) { return read(); } else { return -1; } } }
/** * Read uncompressed data into the specified array * * @param array * @param byteOffset * @param byteLength * @return written bytes * @throws IOException */ public int rawRead(Object array, int byteOffset, int byteLength) throws IOException { int writtenBytes = 0; for (; writtenBytes < byteLength; ) { if (uncompressedCursor >= uncompressedLimit) { if (hasNextChunk()) { continue; } else { return writtenBytes == 0 ? -1 : writtenBytes; } } int bytesToWrite = Math.min(uncompressedLimit - uncompressedCursor, byteLength - writtenBytes); Snappy.arrayCopy(uncompressed, uncompressedCursor, bytesToWrite, array, byteOffset + writtenBytes); writtenBytes += bytesToWrite; uncompressedCursor += bytesToWrite; } return writtenBytes; }
return hasNextChunk();