java.io

Class StringReader

Implemented Interfaces:
Closeable, Readable

public class StringReader
extends Reader

This class permits a String to be read as a character input stream.

The mark/reset functionality in this class behaves differently than normal. If no mark has been set, then calling the reset() method rewinds the read pointer to the beginning of the String.

Field Summary

Fields inherited from class java.io.Reader

lock

Constructor Summary

StringReader(String buffer)
Create a new StringReader that will read chars from the passed in String.

Method Summary

void
close()
Closes the stream represented by this class, thus freeing system resources.
void
mark(int readAheadLimit)
boolean
markSupported()
int
read()
int
read(char[] b, int off, int len)
boolean
ready()
This method determines if the stream is ready to be read.
void
reset()
Sets the read position in the stream to the previously marked position or to 0 (i.e., the beginning of the stream) if the mark has not already been set.
long
skip(long n)
This method attempts to skip the requested number of chars in the input stream.

Methods inherited from class java.io.Reader

close, mark, markSupported, read, read, read, read, ready, reset, skip

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

StringReader

public StringReader(String buffer)
Create a new StringReader that will read chars from the passed in String. This stream will read from the beginning to the end of the String.
Parameters:
buffer - The String this stream will read from.

Method Details

close

public void close()
Closes the stream represented by this class, thus freeing system resources. In that case that the stream is already in the closed state, this method has no effect.
Specified by:
close in interface Closeable
Overrides:
close in interface Reader

mark

public void mark(int readAheadLimit)
            throws IOException
Overrides:
mark in interface Reader

markSupported

public boolean markSupported()
Overrides:
markSupported in interface Reader

read

public int read()
            throws IOException
Overrides:
read in interface Reader

read

public int read(char[] b,
                int off,
                int len)
            throws IOException

ready

public boolean ready()
            throws IOException
This method determines if the stream is ready to be read. This class is always ready to read and so always returns true, unless close() has previously been called in which case an IOException is thrown.
Overrides:
ready in interface Reader
Returns:
true to indicate that this object is ready to be read.
Throws:
IOException - If the stream is closed.

reset

public void reset()
            throws IOException
Sets the read position in the stream to the previously marked position or to 0 (i.e., the beginning of the stream) if the mark has not already been set.
Overrides:
reset in interface Reader

skip

public long skip(long n)
            throws IOException
This method attempts to skip the requested number of chars in the input stream. It does this by advancing the pos value by the specified number of chars. It this would exceed the length of the buffer, then only enough chars are skipped to position the stream at the end of the buffer. The actual number of chars skipped is returned.
Overrides:
skip in interface Reader
Parameters:
n - The requested number of chars to skip
Returns:
The actual number of chars skipped.

StringReader.java -- permits a String to be read as a character input stream Copyright (C) 1998, 1999, 2000, 2003 Free Software Foundation This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.