View Javadoc

    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;
    7   import java.io.InputStream;
    8   import java.util.zip.ZipEntry;
    9   import java.util.zip.ZipFile;
    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 zipFile;
    17      private ZipEntry zipEntry;
    18
    19      /***
    20       * @param zipFile  the ZipFile
    21       * @param zipEntry the ZipEntry containing the file to read
    22       */
    23      public ZipDataSource(ZipFile zipFile, ZipEntry zipEntry) {
    24          this.zipFile = zipFile;
    25          this.zipEntry = zipEntry;
    26      }
    27
    28      public InputStream getInputStream() throws IOException {
    29          return zipFile.getInputStream(zipEntry);
    30      }
    31
    32      public String getNiceFileName(boolean shortNames, String inputFileName) {
    33          // FIXME: this could probably be done better
    34          return zipFile.getName() + ":" + zipEntry.getName();
    35      }
    36  }