BufferedOutputStream Java Help

BufferedOutputStream 

added flush( ) method that is used to ensure that data buffers are physically written to  the actual output device. Since the point of a BufferedOutputStream is to improve performance’ by reducing the number of times the system actually writes data, you may need to call flush ) to cause any data that is in the buffer to get written .

. Unlike buffered Input, buffering output does not provide additional functionality.
Buffers for output in Java are there to increase performance. Here are the two available constructors:

BufferedOutputStream(OutputStreanl outputStream)
3uffered Outpt,ltStr~am(OutputStream OutputStream, int bufSize)

The first form creates a buffered stream using a buffer of 512 bytes. In the second form, the size of the buffer is passed in bufSize.

PushbackinputStream

One of the novel uses of buffering is the Jmp rncn lation of pushback. Pushback is used, on an input stream to allow a byte to be read and then returned (that is pushed  back) to the stream. The PushbackinputStream class implements this idea. It provides; a mechanism to peek at what is coming from an input stream without disrupting it. PushbackinputStream has the following constructors:

PushbackInputStream(inputStream illuStrent)
PushbackinputStream inputstream input, int numBytes)
The first form creates a stream object that allows one byte to be retumed  the mput stream. The second form creates a stream that has a pushback bulfer that is “u”,Bytes long. This allows multiple bytes to be returned to the Inputstream.

Beyond the familiar methods of InputStream, PushbackinputStream unread( ), shown here:

void unread(int ell)
void unread (byte buffer[
void unread(byte buffer, int offset, int numChars)

Tile first form pushes back the low order byte of cI,. This will be the n (1 byte Htm By a subsequent call to read(). The second form  returnS willie bytes 11 buJJer.The third form pushes back bytes beginning at offset from buffer. An IOException will be’ thrown if there is-an attempt to return a byte when the pushback buffer is full Java2 makes a small change to pushbackInputStream it now implements the skip method.

Here is an example that shows how .l’programming language parser might use.PushbackinputStream and unready () to deal with the difference between the operator for comparison and the  operator for assignment:

PuPushbackinputStreamIQ the side effect of invalidating the mark( ) or reset () methods of tire InputStream used to create it. Use markSupported( ) to check any team on which you are,going to use mark( )/reset( ).

JavaHelpOnline.com

  • Feel free to send us an inquiry, we will reply back in hours.
 

Verification

Posted on September 17, 2014 in Input/output: Exploring java.io

Share the Story

About the Author

Back to Top