Example usage for java.util.zip ZipEntry getName

List of usage examples for java.util.zip ZipEntry getName

Introduction

In this page you can find the example usage for java.util.zip ZipEntry getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of the entry.

Usage

From source file:com.joliciel.talismane.machineLearning.linearsvm.LinearSVMModel.java

@SuppressWarnings("unchecked")
@Override//from   ww  w.  j  av a2  s. c  o  m
protected boolean loadDataFromStream(InputStream inputStream, ZipEntry zipEntry) {
    try {
        boolean loaded = true;
        if (zipEntry.getName().equals("featureIndexMap.obj")) {
            ObjectInputStream in = new ObjectInputStream(inputStream);
            featureIndexMap = (Map<String, Integer>) in.readObject();
        } else if (zipEntry.getName().equals("outcomes.obj")) {
            ObjectInputStream in = new ObjectInputStream(inputStream);
            outcomes = (List<String>) in.readObject();
        } else {
            loaded = false;
        }
        return loaded;
    } catch (ClassNotFoundException e) {
        LogUtils.logError(LOG, e);
        throw new RuntimeException(e);
    } catch (IOException e) {
        LogUtils.logError(LOG, e);
        throw new RuntimeException(e);
    }
}

From source file:jeffaschenk.tomcat.instance.generator.builders.TomcatInstanceBuilderHelper.java

/**
 * unZip Archive//from www  .  j a v a2  s.  c o  m
 *
 * @param zipFilePath  input zip file
 * @param outputFolder zip file output folder
 */
protected static void unZipArchive(GenerationLogger GENERATION_LOGGER, String zipFilePath, String outputFolder)
        throws IOException {
    /**
     * Create Output Directory, but should already Exist.
     */
    File folder = new File(outputFolder);
    if (!folder.exists()) {
        folder.mkdir();
    }
    ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
    ZipEntry entry = zipIn.getNextEntry();
    // iterates over entries in the zip file
    while (entry != null) {
        String filePath = outputFolder + File.separator + entry.getName();
        if (!entry.isDirectory()) {
            // if the entry is a file, extracts it
            extractFile(GENERATION_LOGGER, zipIn, filePath);
        } else {
            // if the entry is a directory, make the directory
            File dir = new File(filePath);
            dir.mkdir();
        }
        zipIn.closeEntry();
        entry = zipIn.getNextEntry();
    }
    zipIn.close();
}

From source file:com.wakatime.eclipse.plugin.Dependencies.java

private void unzip(String zipFile, File outputDir) throws IOException {
    if (!outputDir.exists())
        outputDir.mkdirs();/*from w w w.j a v  a 2  s  .co  m*/

    byte[] buffer = new byte[1024];
    ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile));
    ZipEntry ze = zis.getNextEntry();

    while (ze != null) {
        String fileName = ze.getName();
        File newFile = new File(outputDir, fileName);

        if (ze.isDirectory()) {
            // WakaTime.log("Creating directory: "+newFile.getParentFile().getAbsolutePath());
            newFile.mkdirs();
        } else {
            // WakaTime.log("Extracting File: "+newFile.getAbsolutePath());
            FileOutputStream fos = new FileOutputStream(newFile.getAbsolutePath());
            int len;
            while ((len = zis.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
            }
            fos.close();
        }

        ze = zis.getNextEntry();
    }

    zis.closeEntry();
    zis.close();
}

From source file:com.ibm.liberty.starter.ProjectZipConstructor.java

public void initializeMap() throws IOException {
    System.out.println("Entering method ProjectZipConstructor.initializeMap()");
    InputStream skeletonIS = this.getClass().getClassLoader().getResourceAsStream(SKELETON_JAR_FILENAME);
    ZipInputStream zis = new ZipInputStream(skeletonIS);
    ZipEntry ze;
    while ((ze = zis.getNextEntry()) != null) {
        String path = ze.getName();
        int length = 0;
        byte[] bytes = new byte[1024];
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        while ((length = zis.read(bytes)) != -1) {
            baos.write(bytes, 0, length);
        }/*from  ww  w  . jav  a  2  s  .  com*/
        putFileInMap(path, baos.toByteArray());
    }
    zis.close();
}

From source file:com.flexive.tests.disttools.DistPackageTest.java

@Test(groups = "dist")
public void basicDistPackageAnalysis() throws IOException {
    final ZipFile file = getDistFile();

    // parse zipfile entries, extract names
    final Enumeration<? extends ZipEntry> entries = file.entries();
    final List<String> entryNames = new ArrayList<String>();
    while (entries.hasMoreElements()) {
        final ZipEntry entry = entries.nextElement();
        entryNames.add(entry.getName());
    }/*from   w w  w  . j  a  v a 2  s .c o  m*/

    // first check some mandatory files
    for (String requiredEntry : new String[] {
            // flexive JAR distribution
            "/lib/flexive-ant.jar", "/lib/flexive-ejb.jar", "/lib/flexive-extractor.jar",
            "/lib/flexive-shared.jar", "/lib/flexive-sqlParser.jar", "/lib/flexive-web-shared.jar",

            // basic build files
            "/build.xml", "/build.project.xml", "/build.component.xml", "/database.properties",

            // basic plugins
            "/applications/flexive-plugin-jsf-core.jar", }) {
        Assert.assertTrue(entryNames.contains("flexive-dist" + requiredEntry));
    }
}

From source file:com.thoughtworks.go.util.ZipUtil.java

public String getFileContentInsideZip(ZipInputStream zipInputStream, String file) throws IOException {
    ZipEntry zipEntry = zipInputStream.getNextEntry();
    while (zipEntry != null) {
        if (new File(zipEntry.getName()).getName().equals(file)) {
            return IOUtils.toString(zipInputStream, UTF_8);
        }/*from ww w .j  ava 2 s. c  om*/
        zipEntry = zipInputStream.getNextEntry();
    }
    return null;
}

From source file:com.googlecode.jsfFlex.shared.tasks.sdk.UnzipTask.java

protected void performTask() {

    BufferedOutputStream bufferOutputStream = null;
    ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(_file));
    ZipEntry entry;

    try {/* w  w w.  j  a va  2 s .com*/

        while ((entry = zipInputStream.getNextEntry()) != null) {

            ensureDirectoryExists(entry.getName(), entry.isDirectory());

            bufferOutputStream = new BufferedOutputStream(new FileOutputStream(_dest + entry.getName()),
                    BUFFER_SIZE);
            int currRead = 0;
            byte[] dataRead = new byte[BUFFER_SIZE];

            while ((currRead = zipInputStream.read(dataRead, 0, BUFFER_SIZE)) != -1) {
                bufferOutputStream.write(dataRead, 0, currRead);
            }
            bufferOutputStream.flush();
            bufferOutputStream.close();
        }

        _log.debug("UnzipTask performTask has been completed with " + toString());
    } catch (IOException ioExcept) {
        StringBuilder errorMessage = new StringBuilder();
        errorMessage.append("Error in Unzip's performTask with following fields \n");
        errorMessage.append(toString());
        throw new ComponentBuildException(errorMessage.toString(), ioExcept);
    } finally {
        try {
            zipInputStream.close();
            if (bufferOutputStream != null) {
                bufferOutputStream.close();
            }
        } catch (IOException innerIOExcept) {
            _log.info("Error while closing the streams within UnzipTask's finally block");
        }
    }

}

From source file:fi.mikuz.boarder.gui.ZipImporter.java

private void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException {

    File outputFile = new File(outputDir, entry.getName());

    if (entry.isDirectory()) {
        createDir(outputFile);//from w ww  . j a v  a2  s. c  o  m
        return;
    }

    if (!outputFile.getParentFile().exists()) {
        createDir(outputFile.getParentFile());
    }

    log = "Extracting: " + entry.getName() + "\n" + log;
    postMessage("Please wait\n\n" + log);
    Log.d(TAG, "Extracting: " + entry);
    BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry));
    BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));

    try {
        IOUtils.copy(inputStream, outputStream);
    } finally {
        outputStream.close();
        inputStream.close();
    }

}

From source file:ClassFinder.java

/**
 * <P>Iterates through the files in a zip looking for files that may be
 * classes. This is not recursive as zip's in zip's are not searched by the
 * classloader either.</p>//ww  w. ja  v a 2 s.co  m
 *
 * @param file The ZipFile to be searched
 */
protected void processZip(ZipFile file) {
    Enumeration files = file.entries();

    while (files.hasMoreElements()) {
        Object tfile = files.nextElement();
        ZipEntry child = (ZipEntry) tfile;
        if (child.getName().endsWith(".class")) {
            addClassName(getClassName(child.getName()));

            this.foundClasses++;
        }
    }
}

From source file:be.fedict.eid.pkira.blm.model.contracts.CertificateTest.java

protected void validateNextZipEntry(ZipFile zipFile, String fileName, String expectedText) throws IOException {
    ZipEntry entry = zipFile.getEntry(fileName);

    byte[] expectedBytes = expectedText.getBytes();
    byte[] actualBytes = new byte[expectedBytes.length];
    zipFile.getInputStream(entry).read(actualBytes);

    assertEquals(entry.getName(), fileName);
    assertEquals(entry.getSize(), expectedBytes.length);
    assertEquals(actualBytes, expectedBytes);
}