Reading Writing Text  «Prev  Next»


Lesson 7Marking and resetting in the Reader class
ObjectiveExamine the methods of the Reader class for marking and resetting.

Marking and Resetting Reader Class

Readers may or may not support marking and resetting, like InputStreams. The markSupported() method returns true if the underlying streams supports marking and resetting, false if it does not.

public boolean markSupported()

public void mark(int readAheadLimit) throws IOException

public void reset() throws IOException

Some input streams allow you to mark a particular position in the stream and then return to it.
Three methods in the java.io.InputStream class handle marking and resetting:
public synchronized void mark(int readLimit)
public synchronized void reset() throws IOException
public boolean markSupported()	

The boolean markSupported() method returns true if this stream supports marking and false if it does not. If marking is not supported, reset() throws an IOException and mark() does nothing. Assuming the stream does support marking, the mark() method places a bookmark at the current position in the stream. You can rewind the stream to this position later with reset() as long as you have not read more than readLimit bytes. There can be only one mark in the stream at any given time. Marking a second location erases the first mark.

Buffered Byte Streams

For the byte-oriented streams, a buffered stream extends a filtered stream class by attaching a memory buffer to the I/O stream. This buffer allows Java to do I/O operations on more than a byte at a time, thereby improving performance. Because the buffer is available, skipping, marking, and resetting of the stream become possible. The buffered byte stream classes are BufferedInputStream and BufferedOutputStream. PushbackInputStream also implements a buffered stream.

CharacterSets Readers - Quiz

Click the Quiz link below to take a brief multiple-choice quiz on characters sets and the Reader class.
CharacterSets Readers - Quiz