org.apache.lucene.benchmark.byTask.utils

## Class StringBufferReader

- java.lang.Object
- - java.io.Reader
  - - org.apache.lucene.benchmark.byTask.utils.StringBufferReader

- All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.lang.Readable

      public class StringBufferReader
      extends java.io.Reader

  Implements a `Reader` over a `StringBuffer` instance. Although one can use `StringReader` by passing it `StringBuffer.toString()`, it is better to use this class, as it doesn't mark the passed-in `StringBuffer` as shared (which will cause inner char[] allocations at the next append() attempt).
  Notes:
  - This implementation assumes the underlying `StringBuffer` is not changed during the use of this `Reader` implementation.
  - This implementation is thread-safe.
  - The implementation looks very much like `StringReader` (for the right reasons).
  - If one wants to reuse that instance, then the following needs to be done:

         StringBuffer sb = new StringBuffer("some text");
         Reader reader = new StringBufferReader(sb);
         ... read from reader - don't close it ! ...
         sb.setLength(0);
         sb.append("some new text");
         reader.reset();
         ... read the new string from the reader ...

- - ### Field Summary

    - ### Fields inherited from class java.io.Reader

      `lock`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StringBufferReader(java.lang.StringBuffer sb)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `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(java.lang.StringBuffer 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

    - #### StringBufferReader

          public StringBufferReader(java.lang.StringBuffer sb)

  - ### Method Detail

    - #### close

          public void close()

      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Specified by:
        `close` in class `java.io.Reader`

    - #### mark

          public void mark(int readAheadLimit)
                    throws java.io.IOException

      Mark the present position in the stream. Subsequent calls to reset() will reposition the stream to this point.
      Overrides:
        `mark` in class `java.io.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 StringBuffer, there is no actual limit, so this argument must not be negative, but is otherwise ignored.
      Throws:
        `java.lang.IllegalArgumentException` - If readAheadLimit is < 0
        `java.io.IOException` - If an I/O error occurs

    - #### markSupported

          public boolean markSupported()

      Overrides:
        `markSupported` in class `java.io.Reader`

    - #### read

          public int read()
                   throws java.io.IOException

      Overrides:
        `read` in class `java.io.Reader`
      Throws:
        `java.io.IOException`

    - #### read

          public int read(char[] cbuf,
                          int off,
                          int len)
                   throws java.io.IOException

      Specified by:
        `read` in class `java.io.Reader`
      Throws:
        `java.io.IOException`

    - #### ready

          public boolean ready()
                        throws java.io.IOException

      Overrides:
        `ready` in class `java.io.Reader`
      Throws:
        `java.io.IOException`

    - #### reset

          public void reset()
                     throws java.io.IOException

      Overrides:
        `reset` in class `java.io.Reader`
      Throws:
        `java.io.IOException`

    - #### set

          public void set(java.lang.StringBuffer sb)

    - #### skip

          public long skip(long ns)
                    throws java.io.IOException

      Overrides:
        `skip` in class `java.io.Reader`
      Throws:
        `java.io.IOException`

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