01: /**
02: * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03: */package net.sourceforge.pmd;
04:
05: import java.io.IOException;
06: import java.io.InputStream;
07: import java.util.zip.ZipEntry;
08: import java.util.zip.ZipFile;
09:
10: /**
11: * DataSource implementation to read data from an entry
12: * in a zip or jar file.
13: */
14: public class ZipDataSource implements DataSource {
15: private ZipFile zipFile;
16: private ZipEntry zipEntry;
17:
18: /**
19: * @param zipFile the ZipFile
20: * @param zipEntry the ZipEntry containing the file to read
21: */
22: public ZipDataSource(ZipFile zipFile, ZipEntry zipEntry) {
23: this .zipFile = zipFile;
24: this .zipEntry = zipEntry;
25: }
26:
27: public InputStream getInputStream() throws IOException {
28: return zipFile.getInputStream(zipEntry);
29: }
30:
31: public String getNiceFileName(boolean shortNames,
32: String inputFileName) {
33: // FIXME: this could probably be done better
34: return zipFile.getName() + ":" + zipEntry.getName();
35: }
36: }
|