private void copyBlockData(OutputBlockStream outputBlockStream, InputStream in)
			throws IOException, EOFException {

		if (compressed) {
			in = new InflaterInputStream(in);
		}

		int blocksRemaining = getBlockCount();

		byte[] bytes = new byte[getBlockSize() + 4]; // include space for index
		while (blocksRemaining > 0) {
			int total = 0;
			while (total < bytes.length) {
				int readlen = in.read(bytes, total, bytes.length - total);
				if (readlen < 0) {
					throw new EOFException("unexpected end of stream");
				}
				total += readlen;
			}

			BufferFileBlock block = new BufferFileBlock(bytes);
			outputBlockStream.writeBlock(block);
			--blocksRemaining;
		}
		if (compressed && in.read() != -1) {
			// failed to properly exhaust compressed stream
			throw new IOException("expected end of compressed stream");
		}
	}
<code>ClientInputBlockStream</code> provides the client-side of an
OutputBlockStream which wraps an optionally compressed socket output
stream
Ghidra/Features/GhidraServer/src/main/java/ghidra/server/stream/RemoteOutputBlockStreamHandle.java