KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > ZipDataSource


1 /**
2  * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3  */

4 package net.sourceforge.pmd;
5
6 import java.io.IOException JavaDoc;
7 import java.io.InputStream JavaDoc;
8 import java.util.zip.ZipEntry JavaDoc;
9 import java.util.zip.ZipFile JavaDoc;
10
11 /**
12  * DataSource implementation to read data from an entry
13  * in a zip or jar file.
14  */

15 public class ZipDataSource implements DataSource {
16     private ZipFile JavaDoc zipFile;
17     private ZipEntry JavaDoc zipEntry;
18
19     /**
20      * @param zipFile the ZipFile
21      * @param zipEntry the ZipEntry containing the file to read
22      */

23     public ZipDataSource(ZipFile JavaDoc zipFile, ZipEntry JavaDoc zipEntry) {
24         this.zipFile = zipFile;
25         this.zipEntry = zipEntry;
26     }
27
28     public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
29         return zipFile.getInputStream(zipEntry);
30     }
31
32     public String JavaDoc getNiceFileName(boolean shortNames, String JavaDoc inputFileName) {
33         // FIXME: this could probably be done better
34
return zipFile.getName() + ":" + zipEntry.getName();
35     }
36 }
37
Popular Tags