Home : Course Map : Chapter 9 : Java :
Sources, Destinations, and Filters
JavaTech
Course Map
Chapter 9

Introduction
Overview
Streams
Wrappers,Buffers
Console I/O
  Text Output 
     Demo 1

  Formatter/printf()
     Demo 2

  Tex 2t Input
     Demo 3

  Scanner
     
Demo 4
File Class
  File I/O
  File Output-Text
     Demo 5

  Formatter to File
     Demo 6

  File Input - Text
    Demo 7

  Scanner - Files
     Demo 8

  File I/O - Binary
     Demo 9
   Demo 10
File Chooser Dialog
  Demo 11

Character Codes
  Demo 12
   Demo13
Object I/O
Types to Bytes
Stream Filters
Other I/O Topics
Exercises

    Supplements
Character I/O
  Demo 1   Demo 2
Random Access
  Demo 3
ZIP/GZIP Streams
  Demo 4
Piped Streams
  Demo 5
NIO Framework
More NIO
  Demo 6

     About JavaTech
     Codes List
     Exercises
     Feedback
     References
     Resources
     Tips
     Topic Index
     Course Guide
     What's New

I/O stream classes can represent sources of input data and destinations for output data. We saw, for example, that disk files become sources via FileInputStream and a byte array can become the destination of a stream via the ByteArrayOutputStream class.

We emphasized that wrapper classes add greater functionality to the streams they contain. However, you can also look at the wrapper classes as filters. A stream filter monitors, transforms, or is some way processes the data as the stream flows through it on the way from a source to a destination. The BufferedInputStream and BufferedOutputStream classes, for example, hold data in buffers until they are full before letting the data out. They extend the classes named FilterInputStream and FilterOutputStream, respectively.

The class heirarchy diagram shown in the Java I/O Overview shows the subclasses of the FilterInputStream and FilterOutputStream. The FilterInputStream class wraps an InputStream object passed via its constructor:

protected FilterInputStream (InputStream in_stream)

The FilterInputStream class overrides all of the same methods in InputStream but they simply invoke the corresponding methods in the in_stream object. The FilterInputStream does nothing itself and is meant to be extended. A subclass overrides some or all of the methods to carry out the desired action on the data. For example, BufferedInputStream overrides all but one of the read() methods in FilterInputStream. Similarly, FilterOutputStream is intended to be subclassed by a class such as BufferedOutputStream that overrides some or all of its methods to carry out operations on the outgoing data.

Java I/O can be somewhat overwhelming at first but it allows for a great deal of modularity and high level abstraction that can actually bring clarity to program design. The concepts of sources, destinations, and filters helps especially to make sense of the large number of classes in Java I/O.

We discuss in Chapter 9: Tech how to make histograms into stream sources and stream destinations and how to filter data going to a histogram.

References & Web Resources

Latest update: Nov. 14, 2004

              Tech
Histogram I/O
Hist I/O - Get/Set
  Demo 1
Hist I/O - Objects
  Demo 2
HistogramStream
  Demo 3
Filtering Data
  Demo 4
Exercises

           Physics
Physics Model
Simulation Design
Physics Simulator
  Demo 1
Experiment Design
Experiment Sim.
  Demo 2
Analysis
Expt. + Analysis
  Demo 3
Exercises

  Part I Part II Part III
Java Core 1  2  3  4  5  6  7  8  9  10  11  12 13 14 15 16 17
18 19 20
21
22 23 24
Supplements

1  2  3  4  5  6  7  8  9  10  11  12

Tech 1  2  3  4  5  6  7  8  9  10  11  12
Physics 1  2  3  4  5  6  7  8  9  10  11  12

Java is a trademark of Sun Microsystems, Inc.