java.io

Class PushbackReader

Implemented Interfaces:
Closeable, Readable

public class PushbackReader
extends FilterReader

A character-stream reader that allows characters to be pushed back into the stream.
Since:
JDK1.1

Field Summary

Fields inherited from class java.io.FilterReader

in

Fields inherited from class java.io.Reader

lock

Constructor Summary

PushbackReader(Reader in)
Create a new pushback reader with a one-character pushback buffer.
PushbackReader(Reader in, int size)
Create a new pushback reader with a pushback buffer of the given size.

Method Summary

void
close()
Close the stream.
void
mark(int readAheadLimit)
Mark the present position in the stream.
boolean
markSupported()
Tell whether this stream supports the mark() operation, which it does not.
int
read()
Read a single character.
int
read(cbuf[] , int off, int len)
Read characters into a portion of an array.
boolean
ready()
Tell whether this stream is ready to be read.
void
reset()
Reset the stream.
long
skip(long n)
Skip characters.
void
unread(cbuf[] )
Push back an array of characters by copying it to the front of the pushback buffer.
void
unread(cbuf[] , int off, int len)
Push back a portion of an array of characters by copying it to the front of the pushback buffer.
void
unread(int c)
Push back a single character.

Methods inherited from class java.io.FilterReader

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

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

PushbackReader

public PushbackReader(Reader in)
Create a new pushback reader with a one-character pushback buffer.
Parameters:
in - The reader from which characters will be read
Usages and Demos :

View More Examples of PushbackReader(Reader in)
   1:     else
   2:       in = new PushbackReader(inputReader);
   3: 
   4:     this.position = 0;
   5:     this.tokens = new ArrayList();

View Full Code Here
   1:         FileReader fr = new FileReader (f);
   2:         PushbackReader pb = new PushbackReader(fr);
   3:         Lexer lex = new Lexer(pb);
   4:         
   5:         return new Parser(lex);        

View Full Code Here
   1:     public Lexer( Reader input ) {
   2:         this.input = new PushbackReader(input);
   3:     }
   4: 
   5:     public Lexer( String inputString ) {

View Full Code Here
   1:     public LinebreakPreservingReader(Reader in) {
   2:         this.in = new PushbackReader(in);
   3:     }
   4: 
   5:     public void close() throws IOException {

View Full Code Here
   1:         FileReader fr = new FileReader (f);
   2:         PushbackReader pb = new PushbackReader(fr);
   3:         Lexer lex = new Lexer(pb);
   4:         
   5:         return new Parser(lex);        

View Full Code Here

PushbackReader

public PushbackReader(Reader in,
                      int size)
Create a new pushback reader with a pushback buffer of the given size.
Parameters:
in - The reader from which characters will be read
size - The size of the pushback buffer
Throws:
IllegalArgumentException - if size is <= 0
Usages and Demos :

View More Examples of PushbackReader(Reader in,int size)
   1:         try {
   2:             Lexer lexer = new Lexer(new PushbackReader(in, 1024));
   3:             Parser parser = new Parser(lexer);
   4:             Start root = parser.parse();
   5:             StoryDetailsBuilder builder = new StoryDetailsBuilder();

View Full Code Here
   1:         try {
   2:             Lexer lexer = new Lexer(new PushbackReader(in, 1024));
   3:             Parser parser = new Parser(lexer);
   4:             Start root = parser.parse();
   5:             StoryDetailsBuilder builder = new StoryDetailsBuilder();

View Full Code Here
   1:   public ReadInput(Reader input) {
   2:     this.input = new PushbackReader(input, 1024);
   3:   }
   4:         ...
   5:       FileReader fin = new FileReader(filename);
   6:       this.input = new PushbackReader(fin, 1024);
   7:     } 
   8:     catch (java.io.IOException e) {
   9:       throw new ReadException(e.toString());

View Full Code Here
   1:   public void setReader(Reader r) {
   2:     ir_ = new PushbackReader(r, 4*1024);
   3:     super.setReader(ir_);
   4:   }

View Full Code Here
   1:             InputStreamReader reader = new InputStreamReader( inStream, "UTF-8" );
   2:             this.reader = new PushbackReader(reader, 6);
   3:         }
   4:         catch ( UnsupportedEncodingException exp )
   5:         {

View Full Code Here

Method Details

close

public void close()
            throws IOException
Close the stream.
Specified by:
close in interface Closeable
Overrides:
close in interface FilterReader
Throws:
IOException - If an I/O error occurs
Usages and Demos :

View More Examples of close()
   1:   {
   2:     PushbackReader in;
   3:     StringBuffer accumulator = new StringBuffer();
   4:         ...
   5: 
   6:     if (inputReader instanceof PushbackReader)
   7:         ...
   8:       in = (PushbackReader) inputReader;
   9:     else
  10:         ...
  11: 
  12:     in.close();

View Full Code Here
   1: import java.io.PrintWriter;
   2: import java.io.PushbackReader;
   3: import java.io.StringWriter;
   4:         ...
   5: 
   6:     private PushbackReader reader;
   7:     protected int offset;
   8:         ...
   9:             }
  10:             reader = new PushbackReader(new BufferedReader(inputStreamReader),
  11:                                         2);
  12:         ...
  13:             if (reader != null)
  14:                 reader.close();

View Full Code Here

mark

public void mark(int readAheadLimit)
            throws IOException
Mark the present position in the stream. The mark for class PushbackReader always throws an exception.
Overrides:
mark in interface FilterReader
Throws:
IOException - Always, since mark is not supported

markSupported

public boolean markSupported()
Tell whether this stream supports the mark() operation, which it does not.
Overrides:
markSupported in interface FilterReader

read

public int read()
            throws IOException
Read a single character.
Overrides:
read in interface FilterReader
Returns:
The character read, or -1 if the end of the stream has been reached
Throws:
IOException - If an I/O error occurs
Usages and Demos :

View More Examples of read()
   1: 
   2:     PushbackReader in = new PushbackReader( new StringReader(s) );
   3: 
   4:         ...
   5: 
   6:         while ( Character.isDigit((char)(c = in.read())) )
   7:           number = (number * 10) + c - '0';
   8:         ...
   9: 
  10:         while ( (c = in.read()) != -1 )
  11:         {

View Full Code Here
   1: 
   2:       PushbackReader in = new PushbackReader(
   3:                                            new BufferedReader(
   4:         ...
   5: 
   6:         while(Character.isDigit((char)(c = in.read())))
   7:           number += (char)c;
   8: 

View Full Code Here
   1:   {
   2:     PushbackReader in;
   3:     StringBuffer accumulator = new StringBuffer();
   4:         ...
   5: 
   6:     if (inputReader instanceof PushbackReader)
   7:         ...
   8:       in = (PushbackReader) inputReader;
   9:     else
  10:         ...
  11: 
  12:     while ((cur = in.read()) != -1)

View Full Code Here
   1: import java.io.Reader;
   2: import java.io.PushbackReader;
   3: 
   4:         ...
   5: 
   6:     PushbackReader ir = ir_;

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.PushbackReader;
   3: import java.io.Reader;
   4:         ...
   5: 
   6:     private PushbackReader input;
   7: 
   8:         ...
   9:     public void parse(Reader src) throws IOException {
  10:         this.input = new PushbackReader(src);
  11:         int event = parseNext();
  12:         ...
  13:         int result = FOUND_EOF;
  14:         int first = input.read();

View Full Code Here

read

public int read(cbuf[] ,
                int off,
                int len)
            throws IOException
Read characters into a portion of an array.
Overrides:
read in interface FilterReader
Parameters:
off - Offset at which to start writing characters
len - Maximum number of characters to read
Returns:
The number of characters read, or -1 if the end of the stream has been reached
Throws:
IOException - If an I/O error occurs

ready

public boolean ready()
            throws IOException
Tell whether this stream is ready to be read.
Overrides:
ready in interface FilterReader
Throws:
IOException - If an I/O error occurs
Usages and Demos :

View More Examples of ready()
   1: import java.io.IOException;
   2: import java.io.PushbackReader;
   3: import java.io.Reader;
   4:         ...
   5:     private char[] internalBuffer;
   6:     private PushbackReader internalReader;
   7: 
   8:         ...
   9:         eof = false;
  10:         internalReader = new PushbackReader(reader);
  11:     }
  12:         ...
  13:         {
  14:             return (pos < internalBuffer.length || internalReader.ready());

View Full Code Here
   1: import java.io.PrintWriter;
   2: import java.io.PushbackReader;
   3: import java.io.StringWriter;
   4:         ...
   5: 
   6:     private PushbackReader reader;
   7:     protected int offset;
   8:         ...
   9:             }
  10:             reader = new PushbackReader(new BufferedReader(inputStreamReader),
  11:                                         2);
  12:         ...
  13:         try {
  14:             return reader.ready();

View Full Code Here

reset

public void reset()
            throws IOException
Reset the stream. The reset method of PushbackReader always throws an exception.
Overrides:
reset in interface FilterReader
Throws:
IOException - Always, since reset is not supported

skip

public long skip(long n)
            throws IOException
Skip characters. This method will block until some characters are available, an I/O error occurs, or the end of the stream is reached.
Overrides:
skip in interface FilterReader
Parameters:
n - The number of characters to skip
Returns:
The number of characters actually skipped
Throws:
IllegalArgumentException - If n is negative.
IOException - If an I/O error occurs

unread

public void unread(cbuf[] )
            throws IOException
Push back an array of characters by copying it to the front of the pushback buffer. After this method returns, the next character to be read will have the value cbuf[0], the character after that will have the value cbuf[1], and so forth.
Parameters:
Throws:
IOException - If there is insufficient room in the pushback buffer, or if some other I/O error occurs
Usages and Demos :

View More Examples of unread(cbuf[] )
   1: 
   2:     PushbackReader in = new PushbackReader( new StringReader(s) );
   3: 
   4:     for ( int c; ; )
   5:     {

View Full Code Here
   1: 
   2:       PushbackReader in = new PushbackReader(
   3:                                            new BufferedReader(
   4:                                            new FileReader(input)));

View Full Code Here
   1:   {
   2:     PushbackReader in;
   3:     StringBuffer accumulator = new StringBuffer();
   4:         ...
   5: 
   6:     if (inputReader instanceof PushbackReader)
   7:         ...
   8:       in = (PushbackReader) inputReader;
   9:     else
  10:         ...
  11:       {
  12:         in.unread(c);

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.PushbackReader;
   3: import java.io.Writer;
   4:         ...
   5:     
   6:     public static boolean isRootSupported(PushbackReader aReader)
   7:         throws IOException {
   8:         ...
   9:         }
  10:         aReader.unread(chars);
  11:         return supported;
  12:         ...
  13:         if ( rootFile.exists() ) {
  14:             PushbackReader reader =

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.PushbackReader;
   3: import java.io.Reader;
   4:         ...
   5: 
   6:     private PushbackReader input;
   7: 
   8:         ...
   9:     public void parse(Reader src) throws IOException {
  10:         this.input = new PushbackReader(src);
  11:         int event = parseNext();
  12:         ...
  13:         if (ch == stop) {
  14:             input.unread(ch);

View Full Code Here

unread

public void unread(cbuf[] ,
                   int off,
                   int len)
            throws IOException
Push back a portion of an array of characters by copying it to the front of the pushback buffer. After this method returns, the next character to be read will have the value cbuf[off], the character after that will have the value cbuf[off+1], and so forth.
Parameters:
off - Offset of first character to push back
len - Number of characters to push back
Throws:
IOException - If there is insufficient room in the pushback buffer, or if some other I/O error occurs
Usages and Demos :

View More Examples of unread(cbuf[] ,int off,int len)
   1:   public ReadInput(Reader input) {
   2:     this.input = new PushbackReader(input, 1024);
   3:   }
   4:         ...
   5:       FileReader fin = new FileReader(filename);
   6:       this.input = new PushbackReader(fin, 1024);
   7:     } 
   8:         ...
   9:       if (whiteSpaceBuffered) {
  10:         input.unread(buffer, 0, bufferCount);
  11:         whiteSpaceBuffered = false;
  12:         ...
  13: 
  14:   private String readLine(PushbackReader in) 

View Full Code Here

unread

public void unread(int c)
            throws IOException
Push back a single character.
Parameters:
c - The character to push back
Throws:
IOException - If the pushback buffer is full, or if some other I/O error occurs
Usages and Demos :

View More Examples of unread(int c)
   1: 
   2:     PushbackReader in = new PushbackReader( new StringReader(s) );
   3: 
   4:     for ( int c; ; )
   5:     {

View Full Code Here
   1: 
   2:       PushbackReader in = new PushbackReader(
   3:                                            new BufferedReader(
   4:                                            new FileReader(input)));

View Full Code Here
   1:   {
   2:     PushbackReader in;
   3:     StringBuffer accumulator = new StringBuffer();
   4:         ...
   5: 
   6:     if (inputReader instanceof PushbackReader)
   7:         ...
   8:       in = (PushbackReader) inputReader;
   9:     else
  10:         ...
  11:       {
  12:         in.unread(c);

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.PushbackReader;
   3: import java.io.Writer;
   4:         ...
   5:     
   6:     public static boolean isRootSupported(PushbackReader aReader)
   7:         throws IOException {
   8:         ...
   9:         }
  10:         aReader.unread(chars);
  11:         return supported;
  12:         ...
  13:         if ( rootFile.exists() ) {
  14:             PushbackReader reader =

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.PushbackReader;
   3: import java.io.Reader;
   4:         ...
   5: 
   6:     private PushbackReader input;
   7: 
   8:         ...
   9:     public void parse(Reader src) throws IOException {
  10:         this.input = new PushbackReader(src);
  11:         int event = parseNext();
  12:         ...
  13:         if (ch == stop) {
  14:             input.unread(ch);

View Full Code Here