@Override
	public int read(byte[] b, int off, int len) throws IndexOutOfBoundsException, IOException {
		if (offset == buffer.length()) {
			return -1;
		}
		len = Math.min(available(), len);
		buffer.get(offset, b, off, len);
		offset += len;
		return len;
	}
An input stream backed by a database chained buffer
Ghidra/Debug/ProposedUtils/src/main/java/ghidra/util/database/DBBufferInputStream.java