Java Reference
In-Depth Information
000000c0 4c 49 4e 45 5f 53 45 50 41 52 41 54 4f 52 01 00
LINE_SEPARATOR..
000000d0 12 4c 6a 61 76 61 2f 6c 61 6e 67 2f 53 74 72 69
.Ljava/lang/Stri
000000e0 6e 67 3b 01 00 06 3c 69 6e 69 74 3e 01 00 03 28
ng;...<init>...(
000000f0 29 56 01 00 04 43 6f 64 65 01 00 0f 4c 69 6e 65
)V...Code...Line
FilterOutputStream and FilterInputStream
Filestreamspassbytesunchangedtotheirdestinations.Javaalsosupports
filter streams
that buffer, compress/uncompress, encrypt/decrypt, or otherwise manipulate an input
stream's byte sequence before it reaches its destination.
A
filter output stream
takes the data passed to its
write()
methods (the input
stream), filters it, and writes the filtered data to an underlying output stream, which
mightbeanotherfilteroutputstreamoradestinationoutputstreamsuchasafileoutput
stream.
Filter output streams are created from subclasses of the concrete
FilterOut-
putStream
class,an
OutputStream
subclass.
FilterOutputStream
declares
asingle
FilterOutputStream(OutputStream out)
constructorthatcreatesa
filter output stream built on top of
out
, the underlying output stream.
declare a constructor that passes its
OutputStream
argument to
FilterOut-
putStream
's constructor and override
FilterOutputStream
's
void
write(int b)
method.
Listing 8-9.
Scrambling a stream of bytes
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
class ScrambledOutputStream extends FilterOutputStream
{
private int[] map;
ScrambledOutputStream(OutputStream out, int[] map)