private FetchDataResult createDataResult(final String feedName,
                                             final String streamTypeName,
                                             final SegmentInputStream segmentInputStream,
                                             final Set<String> availableChildStreamTypes,
                                             final Source streamSource,
                                             final InputStreamProvider inputStreamProvider,
                                             final FetchDataRequest fetchDataRequest,
                                             final TaskContext taskContext) throws IOException {
        // Read the input stream into a string.
        // If the input stream has multiple segments then we are going to
        // read it in segment mode.

        final DataType dataType = segmentInputStream.count() > 1
                ? DataType.SEGMENTED
                : DataType.NON_SEGMENTED;

        // Get the appropriate encoding for the stream type.
        final String encoding = feedProperties.getEncoding(
                feedName, streamTypeName, fetchDataRequest.getSourceLocation().getChildType());

        final Charset charset = Charset.forName(encoding);

//        LOGGER.info("Size in bytes: {}, avgBytesPerChar: {}, approxChars: {}",
//                ModelStringUtil.formatIECByteSizeString(segmentInputStream.size()),
//                averageBytesPerChar,
//                segmentInputStream.size() / averageBytesPerChar);

        final RawResult rawResult;
        final DisplayMode displayMode = getDisplayModeOrDefault(fetchDataRequest);

        final boolean hasPipeline = fetchDataRequest.getPipeline() != null;
        final SourceLocation sourceLocation;
        if (fetchDataRequest.getSourceLocation().getOptDataRange().isPresent()) {
            sourceLocation = fetchDataRequest.getSourceLocation();
        } else {
            // If no range supplied then use a default one.
            // If there is a pipeline then we need to get all the data then limit the output of that.
            final DataRange newDataRange = hasPipeline
                    ? DataRange.fromCharOffset(0)
                    : DataRange.fromCharOffset(0, sourceConfig.getMaxCharactersPerFetch());
            sourceLocation = fetchDataRequest.getSourceLocation().copy()
                    .withDataRange(newDataRange)
                    .build();
        }

        if (DataType.SEGMENTED.equals(dataType)) {
            rawResult = getSegmentedData(
                    sourceLocation,
                    segmentInputStream,
                    encoding,
                    displayMode,
                    !hasPipeline);
        } else {
            // Non-segmented data
            rawResult = getNonSegmentedData(
                    sourceLocation,
                    segmentInputStream,
                    encoding,
                    displayMode,
                    !hasPipeline);
        }

        // Useful for testing the displaying of errors in the UI
//        if (!feedName.isBlank()) {
//            throw new RuntimeException("Bad things happened. Lorem ipsum dolor sit amet, consectetur adipiscing " +
//                    "elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim " +
//                    "ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " +
//                    "commodo consequat.");
//        }

        // BOM not removed in hex mode (so we can see it)
        if (!DisplayMode.HEX.equals(displayMode)) {
            // We are viewing the data with the BOM removed, so remove the size of the BOM from the
            // total bytes else the progress bar is messed up
            rawResult.setTotalBytes(segmentInputStream.size() - rawResult.byteOrderMarkLength);
        }
        if (rawResult.getTotalCharacterCount() == null) {
            rawResult.setTotalCharacterCount(estimateCharCount(segmentInputStream.size(), charset));
        }

        return buildFetchDataResult(
                feedName,
                streamTypeName,
                availableChildStreamTypes,
                streamSource,
                inputStreamProvider,
                fetchDataRequest,
                dataType,
                rawResult,
                taskContext);
    }
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