code: private int calcNewSize(int latestSize)
      {
          // Let's grow segments by 50%, when over 8k
          int incr = (latestSize < 8000) ? latestSize : (latestSize >> 1);
          int size = latestSize + incr;
          // but let's not create too big chunks
          return Math.min(size, MAX_SEGMENT_LENGTH);
      }
docs: Method used to determine size of the next segment to
  allocate to contain textual content.