Package com.forgerock.opendj.util
Class SubstringReader
- java.lang.Object
-
- com.forgerock.opendj.util.SubstringReader
-
public class SubstringReader extends Object
A sub-string reader.
-
-
Constructor Summary
Constructors Constructor Description SubstringReader(String s)Creates an instance of SubstringReader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetString()Returns the source string.voidmark()Marks the present position in the stream.intpos()Returns the current position of the reader.charread()Attempts to read a character from the current position.Stringread(int length)Attempts to read a substring of the specified length from the current position.intremaining()Returns the remaining length of the available data.voidreset()Resets the stream to the most recent mark, or to the beginning of the string if it has never been marked.intskipDelims()intskipWhitespaces()Skips the whitespace characters and advances the reader to the next non whitespace character.StringtoString()
-
-
-
Constructor Detail
-
SubstringReader
public SubstringReader(String s)
Creates an instance of SubstringReader.- Parameters:
s- the source of the reader.
-
-
Method Detail
-
getString
public String getString()
Returns the source string.- Returns:
- source string.
-
mark
public void mark()
Marks the present position in the stream. Subsequent calls to reset() will reposition the stream to this point.
-
pos
public int pos()
Returns the current position of the reader.- Returns:
- current position of the reader.
-
read
public char read()
Attempts to read a character from the current position. The caller must ensure that the source string has the data available from the current position.- Returns:
- The character at the current position.
- Throws:
StringIndexOutOfBoundsException- If there is no more data available to read.
-
read
public String read(int length)
Attempts to read a substring of the specified length from the current position. The caller must ensure that the requested length is within the bounds i.e. the requested length from the current position should not exceed the length of the source string.- Parameters:
length- The number of characters to read.- Returns:
- The substring.
- Throws:
StringIndexOutOfBoundsException- If the length exceeds the allowed length.
-
remaining
public int remaining()
Returns the remaining length of the available data.- Returns:
- remaining length.
-
reset
public void reset()
Resets the stream to the most recent mark, or to the beginning of the string if it has never been marked.
-
skipWhitespaces
public int skipWhitespaces()
Skips the whitespace characters and advances the reader to the next non whitespace character.- Returns:
- number of whitespace characters skipped.
-
skipDelims
public int skipDelims()
-
-