ZipDataSource.java :  » Code-Analyzer » pmd-4.2rc1 » net » sourceforge » pmd » Java Open Source

Java Open Source » Code Analyzer » pmd 4.2rc1 
pmd 4.2rc1 » net » sourceforge » pmd » ZipDataSource.java
/**
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 */
package net.sourceforge.pmd;

import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/**
 * DataSource implementation to read data from an entry
 * in a zip or jar file.
 */
public class ZipDataSource implements DataSource {
    private ZipFile zipFile;
    private ZipEntry zipEntry;

    /**
     * @param zipFile  the ZipFile
     * @param zipEntry the ZipEntry containing the file to read
     */
    public ZipDataSource(ZipFile zipFile, ZipEntry zipEntry) {
        this.zipFile = zipFile;
        this.zipEntry = zipEntry;
    }

    public InputStream getInputStream() throws IOException {
        return zipFile.getInputStream(zipEntry);
    }

    public String getNiceFileName(boolean shortNames, String inputFileName) {
        // FIXME: this could probably be done better
        return zipFile.getName() + ":" + zipEntry.getName();
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.