org.apache.lucene.benchmark.byTask.utils
Class StringBuilderReader

java.lang.Object
  extended by java.io.Reader
      extended by org.apache.lucene.benchmark.byTask.utils.StringBuilderReader
All Implemented Interfaces:
Closeable, Readable

public class StringBuilderReader
extends Reader

Implements a Reader over a StringBuilder instance. Although one can use StringReader by passing it StringBuilder.toString(), it is better to use this class, as it doesn't mark the passed-in StringBuilder as shared (which will cause inner char[] allocations at the next append() attempt).
Notes:


Field Summary
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
StringBuilderReader(StringBuilder sb)
           
 
Method Summary
 void close()
           
 void mark(int readAheadLimit)
          Mark the present position in the stream.
 boolean markSupported()
           
 int read()
           
 int read(char[] cbuf, int off, int len)
           
 boolean ready()
           
 void reset()
           
 void set(StringBuilder sb)
           
 long skip(long ns)
           
 
Methods inherited from class java.io.Reader
read, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringBuilderReader

public StringBuilderReader(StringBuilder sb)
Method Detail

close

public void close()
Specified by:
close in interface Closeable
Specified by:
close in class Reader

mark

public void mark(int readAheadLimit)
          throws IOException
Mark the present position in the stream. Subsequent calls to reset() will reposition the stream to this point.

Overrides:
mark in class Reader
Parameters:
readAheadLimit - Limit on the number of characters that may be read while still preserving the mark. Because the stream's input comes from a StringBuilder, there is no actual limit, so this argument must not be negative, but is otherwise ignored.
Throws:
IllegalArgumentException - If readAheadLimit is < 0
IOException - If an I/O error occurs

markSupported

public boolean markSupported()
Overrides:
markSupported in class Reader

read

public int read()
         throws IOException
Overrides:
read in class Reader
Throws:
IOException

read

public int read(char[] cbuf,
                int off,
                int len)
         throws IOException
Specified by:
read in class Reader
Throws:
IOException

ready

public boolean ready()
              throws IOException
Overrides:
ready in class Reader
Throws:
IOException

reset

public void reset()
           throws IOException
Overrides:
reset in class Reader
Throws:
IOException

set

public void set(StringBuilder sb)

skip

public long skip(long ns)
          throws IOException
Overrides:
skip in class Reader
Throws:
IOException


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.