public int readBytes(long index, byte[] buffer, int offset, int length) throws IOException {
		ensureBounds(index, 0);
		length = (int) Math.min(currentLength - index, length);

		int totalBytesRead = 0;
		while (length > 0) {
			Buffer fileBuffer = getBufferFor(index);
			int ofs = fileBuffer.getBufferOffset(index);
			int bytesToReadFromThisBuffer = Math.min(fileBuffer.len - ofs, length);
			System.arraycopy(fileBuffer.bytes, ofs, buffer, totalBytesRead,
				bytesToReadFromThisBuffer);

			length -= bytesToReadFromThisBuffer;
			index += bytesToReadFromThisBuffer;
			totalBytesRead += bytesToReadFromThisBuffer;
		}
		return totalBytesRead;
	}
Read bytes at the specified index into the given byte array.
<p>
See {@link InputStream#read(byte[], int, int)}.

@param index file offset to start reading
@param buffer byte array that will receive the bytes
@param offset offset inside the byte array to place the bytes
@param length number of bytes to read
@return number of actual bytes read
@throws IOException if error
Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/FileByteProvider.java