/** * Returns a new character sequence that is a subsequence of this sequence. * <p> * The returned <code>CharSequence</code> is only guaranteed to be valid as long as no futher operations are performed on this <code>StreamedText</code> object. * Any subsequent method call could invalidate the underlying buffer used by the <code>CharSequence</code>. * * @param begin the begin position, inclusive. * @param end the end position, exclusive. * @return a new character sequence that is a subsequence of this sequence. */ public CharSequence subSequence(final int begin, final int end) { // This has not been benchmarked. It is possible that returning substring(begin,end) results in faster code even though it requires more memory allocation. return getCharBuffer(begin,end); }
/** * Returns a <code>CharBuffer</code> containing the source text of the {@linkplain #getCurrentSegment() current segment}. * <p> * The returned <code>CharBuffer</code> provides a window into the internal <code>char[]</code> buffer including the position and length that spans the * {@linkplain #getCurrentSegment() current segment}. * <p> * For example, the following code writes the source text of the current segment to <code>writer</code>: * <p> * <code>CharBuffer charBuffer=streamedSource.getCurrentSegmentCharBuffer();</code><br /> * <code>writer.write(charBuffer.array(),charBuffer.position(),charBuffer.length());</code> * <p> * This may provide a performance benefit over the standard way of accessing the source text of the current segment, * which is to use the <code>CharSequence</code> interface of the segment directly, or to call {@link Segment#toString()}. * <p> * Because this <code>CharBuffer</code> is a direct window into the internal buffer of the <code>StreamedSource</code>, the contents of the * <code>CharBuffer.array()</code> must not be modified, and the array is only guaranteed to hold the segment source text until the * iterator's <code>hasNext()</code> or <code>next()</code> method is next called. * * @return a <code>CharBuffer</code> containing the source text of the {@linkplain #getCurrentSegment() current segment}. */ public CharBuffer getCurrentSegmentCharBuffer() { return streamedText.getCharBuffer(currentSegment.getBegin(),currentSegment.end); }