Errata

Java I/O

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
PDF Page 60
The "in = connection.getInputStream( );" source code

The "in" variable is not defined.

Oleg Bogriakov  Mar 28, 2014 
Printed Page 90,91
chapter 6 code example DecimalFilter.java and HexFilter.java

These two examples in fill() method that implement from class DumpFilter, but buf field in the class DumpFilter marked private so that subclass can't see it, as well as index field in the class DumpFilter.

Anonymous   
Printed Page 100
9.3. Communicating Between Threads Using Piped Streams

FibonacciDriver class must be wrong.It's the same as FibonacciConsumer.class

Anonymous   
Printed Page 131
Skipping Bytes section

The description of DataInputStream.skipBytes(int n) applies to the original specification and would have been valid for Java 1.0 and Java 1.1. However, from Java 1.2 onward the specification has changed, such that the method does not guarantee to skip over all (or any) of the requested bytes and it guarantees not to throw an EOFException. The actual number of bytes skipped is returned.

Benjamin Morgan  Jan 20, 2018 
Printed Page 138
readShort method

Due to the bit shift operator having lower precedence than the addition operator, an extra pair of brackets is required. The line:

return (short) (((byte2 << 24) >>> 16) + (byte1 << 24) >>> 24);

should read:

return (short) (((byte2 << 24) >>> 16) + ((byte1 << 24) >>> 24));

Otherwise, the final >>> 24 operation is applied to byte2 as well as byte 1; this results in the most-significant byte read from the InputStream being discarded, as it suffers a net right-shift of 16 bits from its initial position at bits 0-7, rather than the required left-shift of 8 bits.

Benjamin Morgan  Jan 16, 2018 
Printed Page 138
readByte method

The signature of the method should not include an argument.

public byte readByte(int b) throws IOException

should read:

public byte readByte() throws IOException

Benjamin Morgan  Jan 16, 2018 
Printed Page 140
skipBytes method

The implementation of skipBytes is fundamentally flawed, in that it will loop forever if the skip method returns zero:

for (int i = 0; i < n; i += (int) skip(n - i));

This flaw is masked if the LittleEndianInputStream is chained to a FileInputStream, because FileInputStream will happily skip beyond the end of the file and never return zero. Chain it to a ByteArrayInputStream instead and your application will hang if you try to skip beyond the end of its underlying byte array.

Benjamin Morgan  Jan 19, 2018 
Printed Page 157
Example 9-5

The FibonacciDriver example contains the FibonacciConsumer code.

Anonymous   
Printed Page 166
Subsection "Checking the state of a deflater"

The text should perhaps mention that (at least according to the Java 5/6 API) the methods getBytesRead() and getBytesWritten() are preferred over getTotalIn() and getTotalOut(), as they return a long rather than an int and thus can handle larger files.

Anonymous   
Printed Page 170
Subsection "Checking the state of an inflater"

The text should perhaps mention that (at least according to the Java 5/6 API) the methods getBytesRead() and getBytesWritten() are preferred over getTotalIn() and getTotalOut(), as they return a long rather than an int and thus can handle larger files.

Anonymous   
Printed Page 178
1st paragraph

"The ZipFile class contains two constructors." must be "The ZipFile class contains three constructors."

Anonymous   
Printed Page 183
Last paragraph before the section "The ZipOutputStream Class"

In addition to the six setter methods mentioned in the text, there is a method setCompressedSize() for setting the size of the compressed entry data.

Anonymous   
Printed Page 212
Method signatures after the 1st paragraph

While the text states that the signatures for the two unpack() methods of the Pack200 class are

public void unpack(File in, OutputStream out) throws IOException
public void unpack(InputStream in, OutputStream out) throws IOException

they are in fact

public void unpack(File in, JarOutputStream out) throws IOException
public void unpack(InputStream in, JarOutputStream out) throws IOException

Anonymous   
Printed Page 223
Table 12-1

For SHA-1 and SHA-256, "documents of less than 264 bits" should read "documents of less than 2⁶⁴ bits".

Benjamin Morgan  Feb 04, 2018 
Printed Page 226
Creating Message Digests

The third constructor, added in Java 1.4, has been omitted.

Benjamin Morgan  Feb 05, 2018 
Printed Page 283
Final sentence

SerializableZipFile was Example 13-3, not 13-6.

Benjamin Morgan  Feb 16, 2018 
Printed Page 285
3rd paragraph

"The main() method tests the program by serializing and deserializing a SerializableVector ..."

must be

"The main() method tests the program by serializing and deserializing a SerializableList ..."

Anonymous   
Printed Page 285
4th paragraph

Sample output of 5th line (between null and 9) must be "Element 5",
but it's printed as "Element 1".

Anonymous   
Printed Page 315
Example 14-2 Class NIODuplicator

Main method contains an infinite while loop. This is due to the failure to test whether more data needs to be written before invoking the compact() method on the buffer object. Automatically, invoking compact() without testing, ends up in resetting the position pointer to 0 and limit pointer to capacity which causes the 2nd test condition in the while loop (buffer.hasRemaining()) to always return true.

The readers should also beaware that the first test condition also perputates the infinite loop since bytesRead >= 0 will always be true.

This is due to the fact that the use of the FileInputChannel method read() in this code returns 0 and not -1 when no more data is read.
To get the read() method to return a -1 when no more data is read
will require that the buffer be cleared at some point after the write() method is invoked.

Anonymous   
Printed Page 316
1st paragraph

The statement,
" When the duplicate is created, its position and mark are set to 0 and its limit is set to the capacity, regardless of the position , mark and limit in the orginal buffer."
is false.

The position, mark and limit pointer of the duplicate buffer are initialized to the same values as the original buffer. This can be verified by both testing and by viewing the source code for the undocumented HeapByteBuffer class which extends the ByteBuffer class.

Anonymous   
Printed Page 320
bottom

Some mistakes are in code fragment at page bottom:
[ERR] ByteBuffer buffer = buffer.allocate(8008);
[OK] ByteBuffer buffer = ByteBuffer.allocate(8008);

[ERR] roots.putDouble(i, Math.sqrt(i));
[OK] buffer.putDouble(i, Math.sqrt(i));

Anonymous   
Printed Page 321
1st paragraph

Some mistakes are in code fragment at page top:
[ERR] ByteBuffer buffer = buffer.allocate(1001 * DOUBLE_SIZE);
[OK] ByteBuffer buffer = ByteBuffer.allocate(1001 * DOUBLE_SIZE);

[ERR] roots.putDouble(i* DOUBLE_SIZE, Math.sqrt(i));
[OK] buffer.putDouble(i* DOUBLE_SIZE, Math.sqrt(i));

Anonymous   
Printed Page 348
UDPTimeClient source code, first section of try block.

A timeout is set on the DatagramChannel by invoking the setSoTimeout method on the underlying socket:

socket.setSoTimeout(5000);

However, the read and receive methods in DatagramChannel do not support timeouts, so the above line has no effect. This is the intended behaviour; see https://bugs.java.com/bugdatabase/view_bug.do?bug_id=4614802.

Benjamin Morgan  Mar 12, 2018 
Printed Page 357
second sentence following third code example

Sentence "Should the key become ready again in the future, is it included in the next
set returned by readyKeys()" is incorrect - there is no readyKeys(). readyKeys()
should be selectedKeys() (and really, as I understand it, it's more accurate to state
that it will be returned next next time select() is called.

Anonymous   
Printed Page 366
Just before final paragraph

Copy-and-paste error: the constructor of Pipe.SourceChannel is written as "public abstract static class Pipe.SinkChannel …"

Benjamin Morgan  Mar 14, 2018 
Printed Page 395
first paragraph under "Temporary Files"

"The File class provides two [createTempFile] methods *that create temporary files that exist only as long as the program runs*" (emphasis mine) -> as the author points out further down, there is a separate "deleteOnExit" method that must be called if you want temp files (or any other files) to be deleted on exit.

Anonymous   
Printed Page 395
Top half of page

Copy-and-paste error: the boolean parameters of the Java 6 methods are all named "executable"; two should be named "readable" and two "writable".

Benjamin Morgan  Mar 21, 2018 
Printed Page 397
CWDSpace source code

The first two printed strings end with a tab character, which makes no sense; presumably the three values were originally printed on the same line, separated by tabs, before being changed to one per line.

Benjamin Morgan  Mar 21, 2018 
Printed Page 411
FileTyper source code

The FileTyper class will not print out files that consist of a single line, i.e. files with no line terminator. The following line should be added after the for-loop:

System.out.flush();

Benjamin Morgan  Mar 28, 2018 
Printed Page 419
Paragraph beginning "Suppose you want a file chooser…"

The standard Metal look and feel provides a JFileChooser that does not use mnemonics for approve and cancel. Thus, setting the mnemonic for the Approve button has no effect. Given the likelihood that the reader will execute the book's source code with a Metal look and feel, perhaps this should be pointed out.

Benjamin Morgan  Mar 28, 2018 
Printed Page 421
First sentence

FilenameFilter should be replaced by FileFilter, as used in the rest of the section.

Benjamin Morgan  Mar 29, 2018 
Printed Page 439
actionPerformed method

The following line of code will not compile:

theView.reset();

The class JStreamedTextArea, that theView is an instance of, does not implement or inherit a reset() method. Assuming the goal of this method is to clear the text area between file selections, the following suffices as a replacement:

theView.setText("");

Benjamin Morgan  Apr 28, 2018 
Printed Page 456
Second paragraph

The sentence beginning "Example 19-3 is a slightly more complex program…" actually refers to Example 19-2.

Benjamin Morgan  Apr 30, 2018 
Printed Page 457
Final paragraph before Example 19-3

The sentence beginning "Example 19-5 is a simple program…" actually refers to Example 19-3. The error is repeated on page 458.

Benjamin Morgan  Apr 30, 2018 
Printed Page 472
Paragraph introducing Example 20-2

The text refers to the class as FileConverter rather than its actual name StreamRecoder.

Benjamin Morgan  May 05, 2018