public static byte[] readNBytes(InputStream inputStream, byte[] buffer, int offset, int len) throws IOException {
        int total = 0;
        while (total < len) {
            int r = inputStream.read(buffer, offset + total, len - total);
            if (r == -1) {
                throw new EOFException("End of stream reached before reading all data");
            }
            total += r;
        }
        return buffer;
    }
Reads {@code len} bytes from input stream to buffer.

@param inputStream - source of bytes
@param buffer      - target buffer
@param offset      - target buffer offset
@param len         - number of bytes to read
@return target buffer
@throws IOException
client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java