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.

Security Issues<br />

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

I don't know if there's one most frequently asked question about <strong>Java</strong> Network Programming,<br />

but there's definitely a most frequent answer, and it applies to this book too. My mistake in<br />

<strong>Java</strong> Network Programming was hiding that answer in the back of a chapter most people<br />

didn't read. Since that very same answer should answer an equal number of questions from<br />

readers of this book, I want to get it out of the way right up front:<br />

<strong>Java</strong>'s security manager prevents almost all the examples and methods discussed in this book<br />

from working in an applet.<br />

This book focuses very much on applications. There is very little that can be done with I/O<br />

from an untrusted applet without running afoul of the security manager. The problem may not<br />

always be obvious—not all web browsers properly report security exceptions—but it is there.<br />

There are some exceptions. Byte array streams and piped streams work without limitation in<br />

applets. Network connections can be made back to the host from whence the applet came (and<br />

only to that host). System.in and System.out may be accessible from some, though not all,<br />

web browsers. And in <strong>Java</strong> 2 and later, there are ways to relax the restrictions on applets so<br />

they get limited access to the filesystem or unlimited access to the network. However, these<br />

are exceptions, not the rule.<br />

If you can make an applet work when run as a standalone application and you cannot get it to<br />

work inside a web browser, the problem is almost certainly a conflict with the browser's<br />

security manager.<br />

Conventions Used in This Book<br />

Italic is used for:<br />

• Filenames (readme.txt )<br />

• Host and domain names (http://www.oreilly.com/)<br />

• URLs (http://metalab.unc.edu/javafaq/)<br />

Constant width is used for:<br />

• Code examples and fragments<br />

• Class, variable, and method names, and <strong>Java</strong> keywords used within the text<br />

Significant code fragments and complete programs are generally placed in a separate<br />

paragraph like this:<br />

InputStream in = new FileInputStream("/etc/mailcap");<br />

When code is presented as fragments rather than complete programs, the existence of the<br />

appropriate import statements should be inferred. For example, in the previous code fragment<br />

you may assume that java.io.InputStream and java.io.FileInputStream were<br />

imported.<br />

9

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

Saved successfully!

Ooh no, something went wrong!