private long segmentAtByteOffset(final long findBytePos, final long workingLowerSegment,
                                     final long workingUpperSegment, final boolean lowerBound) throws IOException {
        // Get the mid point
        long midPointSegment = (workingLowerSegment + workingUpperSegment) / 2;
        long midPointBytePos = byteOffset(midPointSegment);

        // Case 1 Match
        if (findBytePos == midPointBytePos) {
            // We need to test for empty segments here
            if (lowerBound) {
                // Skip back over any empty segments
                long prevMidPointBytePos;
                while ((midPointSegment > 0)
                        && (prevMidPointBytePos = byteOffset(midPointSegment - 1)) == midPointBytePos) {
                    midPointSegment--;
                    midPointBytePos = prevMidPointBytePos;
                }
            } else {
                // Skip forward over any empty segments
                long nextMidPointBytePos;
                while ((midPointSegment + 1 < totalSegmentCount)
                        && (nextMidPointBytePos = byteOffset(midPointSegment + 1, false)) == midPointBytePos) {
                    midPointSegment++;
                    midPointBytePos = nextMidPointBytePos;
                }
            }
            return midPointSegment;
        }

        // Case 2 Our mid point is too High
        if (findBytePos < midPointBytePos) {
            // Scan the lower half
            return segmentAtByteOffset(findBytePos, workingLowerSegment, midPointSegment, lowerBound);
        }

        // Case 3 Our mid point is too Low but we can't seek any more ... best
        // match we are going to get
        if (midPointSegment + 1 >= workingUpperSegment) {
            return midPointSegment;
        }
        return segmentAtByteOffset(findBytePos, midPointSegment, workingUpperSegment, lowerBound);

    }
Perform a search for a segment given a byte offset.
stroom-data/stroom-data-store-impl-fs/src/main/java/stroom/data/store/impl/fs/RASegmentInputStream.java