Package org.codehaus.groovy.util

# Class CharSequenceReader

java.lang.Object
java.io.Reader
org.codehaus.groovy.util.CharSequenceReader

All Implemented Interfaces:
  `Closeable`, `Serializable`, `AutoCloseable`, `Readable`

public class CharSequenceReader extends Reader implements Serializable
`Reader` implementation that can read from String, StringBuffer, StringBuilder, CharBuffer or GString.

Note: Supports `mark(int)` and `reset()`.

Note: This class is mostly a copy from Commons IO and is intended for internal Groovy usage only. It may be deprecated and removed from Groovy at a faster pace than other classes. If you need this functionality in your Groovy programs, we recommend using the Commons IO equivalent directly.

See Also:
  - Serialized Form

## Field Summary

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

`lock`

## Constructor Summary

Constructors
Constructor
Description
`CharSequenceReader(CharSequence charSequence)`
Construct a new instance with the specified character sequence.

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Close resets the reader back to the start and removes any marked position.
`void`
`mark(int readAheadLimit)`
Mark the current position.
`boolean`
`markSupported()`
Mark is supported (returns true).
`int`
`read()`
Read a single character.
`int`
`read(char[] array, int offset, int length)`
Read the sepcified number of characters into the array.
`void`
`reset()`
Reset the reader to the last marked position (or the beginning if mark has not been called).
`long`
`skip(long n)`
Skip the specified number of characters.
`String`
`toString()`
Return a String representation of the underlying character sequence.

### Methods inherited from class java.io.Reader

`nullReader, read, read, ready, transferTo`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### CharSequenceReader

public CharSequenceReader(CharSequence charSequence)
Construct a new instance with the specified character sequence.

Parameters:
  `charSequence` - The character sequence, may be `null`

## Method Details

### close

public void close()
Close resets the reader back to the start and removes any marked position.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in class `Reader`

### mark

public void mark(int readAheadLimit)
Mark the current position.

Overrides:
  `mark` in class `Reader`
Parameters:
  `readAheadLimit` - ignored

### markSupported

public boolean markSupported()
Mark is supported (returns true).

Overrides:
  `markSupported` in class `Reader`
Returns:
  `true`

### read

public int read()
Read a single character.

Overrides:
  `read` in class `Reader`
Returns:
  the next character from the character sequence or -1 if the end has been reached.

### read

public int read(char[] array, int offset, int length)
Read the sepcified number of characters into the array.

Specified by:
  `read` in class `Reader`
Parameters:
  `array` - The array to store the characters in
  `offset` - The starting position in the array to store
  `length` - The maximum number of characters to read
Returns:
  The number of characters read or -1 if there are no more

### reset

public void reset()
Reset the reader to the last marked position (or the beginning if mark has not been called).

Overrides:
  `reset` in class `Reader`

### skip

public long skip(long n)
Skip the specified number of characters.

Overrides:
  `skip` in class `Reader`
Parameters:
  `n` - The number of characters to skip
Returns:
  The actual number of characters skipped

### toString

public String toString()
Return a String representation of the underlying character sequence.

Overrides:
  `toString` in class `Object`
Returns:
  The contents of the character sequence