/* A novel buffer usage is pushback ). Pushback is used to input the stream to allow the byte to be read and then return (that is, "Push Back") to the stream. The pushbackinputstream class implements this idea. It provides a mechanism to "peat" What is generated by the input stream without being damaged. Pushbackinputstream has two constructors: pushbackinputstream (inputstream) pushbackinputstream (inputstream, int numbytes). The first form creates a stream object that allows a byte to be pushed back to the input stream. The second form creates a push-back buffer stream with a numbytes length buffer. It allows multiple bytes to be pushed back to the input stream. In addition to the same method as inputstream, pushbackinputstream provides the unread () method, which indicates the following: void unread (INT ch) void unread (byte buffer []) void unread (byte buffer, int offset, int numchars) the first form pushes back the low byte of CH, which will be the next byte returned by the subsequent call of the read () method. The second form returns the bytes in the buffer. The third form pushes back the numchars bytes starting from the offset in the buffer. If a byte is returned when the push-back buffer is full, an ioexception is thrown. Java 2 has made some minor changes to pushbackinputstream: it implements the SKIP () method. */
// Demonstrate unread ().
Import java. Io .*;
Class pushbackinputstreamdemo {
Public static void main (string [] ARGs) throws ioexception {
String S = "if (a = 4) A = 0;/N ";
Byte Buf [] = S. getbytes ();
Bytearrayinputstream in = new bytearrayinputstream (BUF );
Pushbackinputstream F = new pushbackinputstream (in );
Int C;
While (C = f. Read ())! =-1 ){
Switch (c ){
Case '= ':
If (C = f. Read () = '){
System. Out. Print (". Eq .");
} Else {
System. Out. Print ("<-");
F. unread (C );
}
Break;
Default:
System. Out. Print (char) C );
Break;
}
}
}
}