Example usage for java.util.zip ZipFile OPEN_READ

List of usage examples for java.util.zip ZipFile OPEN_READ

Introduction

In this page you can find the example usage for java.util.zip ZipFile OPEN_READ.

Prototype

int OPEN_READ

To view the source code for java.util.zip ZipFile OPEN_READ.

Click Source Link

Document

Mode flag to open a zip file for reading.

Usage

From source file:com.izforge.izpack.compiler.CompilerConfig.java

private IXMLElement readRefPackData(String refFileName, boolean isselfcontained) throws CompilerException {
    File refXMLFile = new File(refFileName);
    if (!refXMLFile.isAbsolute()) {
        refXMLFile = new File(compilerData.getBasedir(), refFileName);
    }/* w  w w. j a v  a 2  s  .  com*/
    if (!refXMLFile.canRead()) {
        throw new CompilerException("Invalid file: " + refXMLFile);
    }

    InputStream specin;

    if (isselfcontained) {
        if (!refXMLFile.getAbsolutePath().endsWith(".zip")) {
            throw new CompilerException(
                    "Invalid file: " + refXMLFile + ". Selfcontained files can only be of type zip.");
        }
        ZipFile zip;
        try {
            zip = new ZipFile(refXMLFile, ZipFile.OPEN_READ);
            ZipEntry specentry = zip.getEntry("META-INF/izpack.xml");
            specin = zip.getInputStream(specentry);
        } catch (IOException e) {
            throw new CompilerException("Error reading META-INF/izpack.xml in " + refXMLFile);
        }
    } else {
        try {
            specin = new FileInputStream(refXMLFile.getAbsolutePath());
        } catch (FileNotFoundException e) {
            throw new CompilerException("FileNotFoundException exception while reading refXMLFile");
        }
    }

    IXMLParser refXMLParser = new XMLParser();
    // We get it
    IXMLElement refXMLData = refXMLParser.parse(specin, refXMLFile.getAbsolutePath());

    // Now checked the loaded XML file for basic syntax
    // We check it
    if (!"installation".equalsIgnoreCase(refXMLData.getName())) {
        assertionHelper.parseError(refXMLData, "this is not an IzPack XML installation file");
    }
    if (!CompilerData.VERSION.equalsIgnoreCase(xmlCompilerHelper.requireAttribute(refXMLData, "version"))) {
        assertionHelper.parseError(refXMLData, "the file version is different from the compiler version");
    }

    // Read the properties and perform replacement on the rest of the tree
    substituteProperties(refXMLData);

    // call addResources to add the referenced XML resources to this installation
    addResources(refXMLData);

    try {
        specin.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return refXMLData;
}