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.

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

so throw a java.lang.UnsupportedOperationException. This is a runtime exception, so<br />

you do not have to catch it.<br />

public abstract JarFile getJarFile() throws <strong>IO</strong>Exception<br />

The getJarEntry() method returns an immutable JarEntry object for the JAR entry<br />

referred to by this URL. You can read the state of this object, but you cannot change it.<br />

Attempts to do so throw a java.lang.UnsupportedOperationException .<br />

public JarEntry getJarEntry() throws <strong>IO</strong>Exception<br />

The getManifest() method returns an immutable Manifest object constructed from the<br />

manifest file in the JAR archive. It returns null if the archive doesn't have a manifest. Again,<br />

you cannot modify this Manifest object, and any attempt to do so will throw an<br />

UnsupportedOperationException.<br />

public Manifest getManifest() throws <strong>IO</strong>Exception<br />

The getAttributes() method returns an Attributes object representing the attributes of<br />

the JAR entry this URL refers to. It returns null if the URL refers to a JAR file rather than a<br />

particular entry. To get the attributes of the entire archive, use the getMainAttributes()<br />

method instead.<br />

public Attributes getAttributes() throws <strong>IO</strong>Exception<br />

public Attributes getMainAttributes() throws <strong>IO</strong>Exception<br />

The getCertificates() method returns an array of java.security.cert.Certificate<br />

objects containing the certificates for the JAR entry this URL refers to (if any). This method<br />

returns null if the URL refers to a JAR file rather than a JAR entry.<br />

public Certificate[] getCertificates() throws <strong>IO</strong>Exception<br />

9.6 File Viewer, Part 4<br />

Because of the nature of filter streams, it is relatively straightforward to add decompression<br />

services to the FileDumper program last seen in Chapter 7. Generally, you'll want to<br />

decompress a file before dumping it. Adding decompression does not require a new dump<br />

filter. Instead, it simply requires passing the file through an inflater input stream before<br />

passing it to one of the dump filters. We'll let the user choose from either gzipped or deflated<br />

files with the command-line switches -gz and -deflate. When one of these switches is seen,<br />

the appropriate inflater input stream is selected; it is an error to select both. Example 9.15,<br />

FileDumper4, demonstrates.<br />

Example 9.15. FileDumper4<br />

import java.io.*;<br />

import java.util.zip.*;<br />

import com.macfaq.io.*;<br />

public class FileDumper4 {<br />

public static final int ASC = 0;<br />

189

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

Saved successfully!

Ooh no, something went wrong!