/** * Reads the specified number of bytes from a given position within a * stream. This does not change the current offset of the stream and is * thread-safe. * * @param buffer the buffer into which the data is read. * @param length the maximum number of bytes to read. * @param offset the start offset in the data. * @param position the offset from the start of the stream. * @throws IOException if an I/O error occurs. */ public void readFully(long position, byte[] buffer, int offset, int length) throws IOException { checkStream(); IoUtils.readFully(input, position, buffer, offset, length); if (length > 0) { // This operation does not change the current offset of the file decrypt(position, buffer, offset, length); } }
/** * Reads up to the specified number of bytes from a given position within a * stream and return the number of bytes read. This does not change the * current offset of the stream, and is thread-safe. * * @param buffer the buffer into which the data is read. * @param length the maximum number of bytes to read. * @param offset the start offset in the data. * @param position the offset from the start of the stream. * @throws IOException if an I/O error occurs. * @return int the total number of decrypted data bytes read into the * buffer. */ public int read(long position, byte[] buffer, int offset, int length) throws IOException { checkStream(); final int n = input.read(position, buffer, offset, length); if (n > 0) { // This operation does not change the current offset of the file decrypt(position, buffer, offset, n); } return n; }