19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

720 Chapter 19 Binary I/O<br />

BufferedInputStream<br />

Program<br />

BufferedOutputStream<br />

Program<br />

A block<br />

of data<br />

Buffer<br />

Read<br />

individual<br />

data<br />

A block<br />

of data<br />

Buffer<br />

Write<br />

individual<br />

data<br />

(a)<br />

(b)<br />

FIGURE 19.11<br />

Buffer I/O places data in a buffer for fast processing.<br />

BufferedInputStream/BufferedOutputStream does not contain new methods. All the<br />

methods in BufferedInputStream/BufferedOutputStream are inherited from the<br />

InputStream/OutputStream classes. BufferedInputStream/BufferedOutputStream<br />

manages a buffer behind the scene and au<strong>to</strong>matically reads/writes data from/<strong>to</strong> disk on<br />

demand.<br />

You can wrap a BufferedInputStream/BufferedOutputStream on any<br />

InputStream/OutputStream using the construc<strong>to</strong>rs shown in Figures 19.12 and 19.13.<br />

java.io.InputStream<br />

java.io.FilterInputStream<br />

java.io.BufferedInputStream<br />

+BufferedInputStream(in: InputStream)<br />

+BufferedInputStream(in: InputStream, bufferSize: int)<br />

Creates a BufferedInputStream from an<br />

InputStream object.<br />

Creates a BufferedInputStream from an<br />

InputStream object with specified buffer size.<br />

FIGURE 19.12<br />

BufferedInputStream buffers an input stream.<br />

java.io.OutputStream<br />

java.io.FilterOutputStream<br />

java.io.BufferedOutputStream<br />

+BufferedOutputStream(out: OutputStream)<br />

+BufferedOutputStream(out: OutputStream, bufferSize: int)<br />

Creates a BufferedOutputStream from an<br />

OutputStream object.<br />

Creates a BufferedOutputStream from an<br />

OutputStream object with specified size.<br />

FIGURE 19.13<br />

BufferedOutputStream buffers an output stream.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!