Skip to Content

PushbackInputStream

Java PushbackInputStream provides ability to push back or unread bytes read from another input stream object. PushbackInputStream works with another input stream in conjunction.

PushbackInputStream class has two internal protected fields. One is "buf" which is buffer and another is "pos" which maintains the position within the "buf" from which the next byte will be read.

PushbackInputStream class provides unread method which actually does the unreading the byte(s).

unread method is overloaded and there are 3 below given versions
1) void unread(int b)
unreads/pushes back single byte by copying it in the front of the buffer.

2) void unread(byte[] b)
unreads/pushes back array of byte by copying it in the front of the buffer.

3) void unread(byte[] b, int offset, int length)
unreads/pushes back portion of byte array by copying it in the front of the buffer.