23.07.2013 Views

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

}<br />

}<br />

case SHORT:<br />

in = new ShortFilter(din);<br />

break;<br />

case LONG:<br />

in = new LongFilter(din);<br />

break;<br />

case DOUBLE:<br />

in = new DoubleFilter(din);<br />

break;<br />

case FLOAT:<br />

in = new FloatFilter(din);<br />

break;<br />

default:<br />

}<br />

else {<br />

LittleEndianInputStream lin = new LittleEndianInputStream(in);<br />

switch (mode) {<br />

case HEX:<br />

in = new HexFilter(in);<br />

break;<br />

case DEC:<br />

in = new DecimalFilter(in);<br />

break;<br />

case INT:<br />

in = new LEIntFilter(lin);<br />

break;<br />

case SHORT:<br />

in = new LEShortFilter(lin);<br />

break;<br />

case LONG:<br />

in = new LELongFilter(lin);<br />

break;<br />

case DOUBLE:<br />

in = new LEDoubleFilter(lin);<br />

break;<br />

case FLOAT:<br />

in = new LEFloatFilter(lin);<br />

break;<br />

default:<br />

}<br />

}<br />

StreamCopier.copy(in, out);<br />

in.close();<br />

<strong>Java</strong> I/O<br />

The main() method of this class reads the command-line arguments and uses the switches to<br />

determine the format of the input data. The dump() method reads the mode and the<br />

endianness, selects the appropriate filter, then copies the input onto the output. Table 7.2<br />

shows the command-line switches. Eight of these switches select a particular format. One, -<br />

little, is used to determine the endianness of the data. Since there's no difference between<br />

big-endian and little-endian ASCII, decimal, and hexadecimal dumps, there are a total of 12<br />

different filters used here. Two, the HexFilter and the DecimalFilter, were introduced in<br />

the last chapter. They haven't changed.<br />

126

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

Saved successfully!

Ooh no, something went wrong!