private RawResult extractDataRangeAsHex(final SourceLocation sourceLocation,
                                            final InputStream inputStream,
                                            final String encoding,
                                            final long streamSizeBytes,
                                            final DataType dataType) throws IOException {

        final DataRange dataRange = sourceLocation.getOptDataRange()
                .orElseGet(() -> DataRange.fromCharOffset(0));

        final HexDump hexDump = getHexDump(inputStream, dataRange, encoding, streamSizeBytes);

        if (!hexDump.isEmpty()) {
            // Dump is not empty at this point so Optional::get is ok
            final HexDumpLine firstLine = hexDump.getFirstLine().get();
            final HexDumpLine lastLine = hexDump.getLastLine().get();
            // This is the char offset of the hex dump not the actual data
            // so calculate it from the number of hex dump chars on each line.
            final long fromCharOffset = Math.max(
                    0,
                    ((long) (firstLine.getLineNo() - 1) * HexDump.MAX_CHARS_PER_DUMP_LINE)); // -1 for count => offset
            final long toCharOffset = fromCharOffset + hexDump.getDumpCharCount() - 1; //-1 for count => offset

            final DataRange requestedHighlight = sourceLocation.getHighlights() != null
                                                 && !sourceLocation.getHighlights().isEmpty()
                    ? sourceLocation.getHighlights().get(0)
                    : null;
            final List<DataRange> actualHighlights = calculateHexDumpHighlights(requestedHighlight);

            final SourceLocation.Builder sourceLocationBuilder = SourceLocation.builder(sourceLocation.getMetaId())
                    .withPartIndex(sourceLocation.getPartIndex())
                    .withChildStreamType(sourceLocation.getOptChildType()
                            .orElse(null))
                    .withHighlight(actualHighlights) // pass the modified highlight back
                    .withDataRange(DataRange.builder()
                            .fromCharOffset(fromCharOffset)
                            .toCharOffset(toCharOffset)
                            .fromByteOffset(hexDump.getByteOffsetRange().getFrom())
                            .toByteOffset(hexDump.getByteOffsetRange().getTo() - 1) // ex to inc
                            .fromLocation(DefaultLocation.of(firstLine.getLineNo(), 1))
                            .toLocation(DefaultLocation.of(lastLine.getLineNo(), lastLine.getDumpLineCharCount()))
                            .withLength(hexDump.getDumpCharCount())
                            .build());

            final RawResult rawResult = new RawResult(
                    sourceLocationBuilder.build(),
                    hexDump.getHexDumpAsStr(),
                    0,
                    DisplayMode.HEX);

            rawResult.setTotalCharacterCount(Count.exactly(hexDump.getDumpCharCount()));
            final long totalBytes = DataType.SEGMENTED.equals(dataType)
                    ? hexDump.getDumpByteCount()
                    : streamSizeBytes;
            rawResult.setTotalBytes(totalBytes);
            return rawResult;
        } else {
            return new RawResult(
                    null,
                    "## No Data ##",
                    0,
                    DisplayMode.HEX);
        }
    }
How big our buffers are. This should always be a multiple of 8.
stroom-data/stroom-data-store-impl/src/main/java/stroom/data/store/impl/DataFetcher.java