int (InputStream input, int offset) { int requestedBlock = offset / Xxh3Impl.getBlockLength(); int positionInBuffer = offset % Xxh3Impl.getBlockLength(); if (requestedBlock == currentBlock) { return positionInBuffer; } else if (requestedBlock > currentBlock) { // If it's the last block we should read the rest stream if (requestedBlock + 1 == totalBlocks) { int remainingBufferSize = totalStreamLength - requestedBlock * Xxh3Impl.getBlockLength(); buffer = new byte[remainingBufferSize]; } try { input.read(buffer); currentBlock++; return positionInBuffer; } catch (IOException e) { throw new RuntimeException(e); } } else { throw new IllegalStateException("Unexpected state at InputStream hashing"); } }