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

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

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

7.9 Thread Safety<br />

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

The LittleEndianInputStream class is not perfectly thread-safe. Consider the readInt()<br />

method:<br />

public int readInt() throws <strong>IO</strong>Exception {<br />

}<br />

int byte1 = in.read();<br />

int byte2 = in.read();<br />

int byte3 = in.read();<br />

int byte4 = in.read();<br />

if (byte4 == -1 || byte3 == -1 || byte2 == -1 || byte1 == -1) {<br />

throw new EOFException();<br />

}<br />

return (byte4

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

Saved successfully!

Ooh no, something went wrong!