code: private Segment currentSegment() {
      Segment segment = segments.currentSegment();
      if (segment.isFull()) {
        segments.currentSegment().flush();
        segment = segments.nextSegment();
      }
      return segment;
    }
docs: Checks whether we need to roll over to a new segment.