Example usage for java.util.zip ZipEntry getSize

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

Introduction

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

Prototype

public long getSize() 

Source Link

Document

Returns the uncompressed size of the entry data.

Usage

From source file:com.googlecode.android_scripting.ZipExtractorTask.java

private long getOriginalSize(ZipFile file) {
    Enumeration<? extends ZipEntry> entries = file.entries();
    long originalSize = 0l;
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        if (entry.getSize() >= 0) {
            originalSize += entry.getSize();
        }/* w w w .j  ava  2 s.co  m*/
    }
    return originalSize;
}

From source file:ZipFileViewer.java

public Object getValueAt(int row, int col) {
    ZipEntry zipEntry = (ZipEntry) (m_zipEntries.get(row));
    switch (col) {
    case NAME://  ww  w. j  a  v  a 2 s. c  o m
        return zipEntry.getName();
    case SIZE:
        if (zipEntry.isDirectory()) {
            return "";
        } else {
            return String.valueOf(zipEntry.getSize() / 1000) + " KB";
        }
    case COMP_SIZE:
        if (zipEntry.isDirectory()) {
            return "";
        } else {
            return String.valueOf(zipEntry.getCompressedSize() / 1000) + " KB";
        }
    case TYPE:
        if (zipEntry.isDirectory()) {
            return "Directory";
        } else {
            return "File";
        }
    case LAST_MODI:
        return String.valueOf(new Date(zipEntry.getTime()));
    }
    return new String();
}

From source file:com.genericworkflownodes.knime.nodes.io.outputfile.OutputFileNodeModel.java

/**
 * {@inheritDoc}// www  .  j  av  a 2 s . c  om
 */
@Override
protected void loadInternals(final File internDir, final ExecutionMonitor exec)
        throws IOException, CanceledExecutionException {
    ZipFile zip = new ZipFile(new File(internDir, "loadeddata"));

    @SuppressWarnings("unchecked")
    Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zip.entries();

    int BUFFSIZE = 2048;
    byte[] BUFFER = new byte[BUFFSIZE];

    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();

        if (entry.getName().equals("rawdata.bin")) {
            int size = (int) entry.getSize();
            byte[] data = new byte[size];
            InputStream in = zip.getInputStream(entry);
            int len;
            int totlen = 0;
            while ((len = in.read(BUFFER, 0, BUFFSIZE)) >= 0) {
                System.arraycopy(BUFFER, 0, data, totlen, len);
                totlen += len;
            }
            this.data = new String(data);
        }
    }
    zip.close();
}

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);
}

From source file:org.pentaho.reporting.libraries.repository.zip.ZipContentLocation.java

private void updateMetaData(final ZipEntry zipEntry) {
    this.comment = zipEntry.getComment();
    this.size = zipEntry.getSize();
    this.time = zipEntry.getTime();
}

From source file:org.cloudfoundry.client.lib.archive.AbstractApplicationArchiveTest.java

@Test
@Ignore// ww w . j  av a2 s .  co  m
public void shouldAdaptEntries() throws Exception {
    Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
    while (zipEntries.hasMoreElements()) {
        ZipEntry zipEntry = zipEntries.nextElement();
        ApplicationArchive.Entry archiveEntry = archiveEntries.remove(zipEntry.getName());
        assertThat(archiveEntry, is(notNullValue()));
        assertThat(archiveEntry.getSize(), is(zipEntry.getSize()));
        assertThat(archiveEntry.isDirectory(), is(zipEntry.isDirectory()));
    }
    assertThat(archiveEntries.size(), is(0));
}

From source file:com.github.jknack.amd4j.ClosureMinifier.java

/**
 * Build the default list of google closure external variable files.
 * Taken from: com.google.javascript.jscomp.CommandLineRunner
 *
 * @return a mutable list of source files.
 * @throws IOException On error when working with externs.zip
 *//*from   w  w w  .  j a v  a  2 s .  co  m*/
protected List<SourceFile> getDefaultExterns() throws IOException {
    ZipInputStream zip = null;
    try {
        InputStream input = CommandLineRunner.class.getResourceAsStream("/externs.zip");
        notNull(input, "The externs.zip file was not found within the closure classpath");

        zip = new ZipInputStream(input);
        Map<String, SourceFile> externsMap = Maps.newHashMap();
        ZipEntry entry = zip.getNextEntry();
        while (entry != null) {
            BufferedInputStream entryStream = new BufferedInputStream(ByteStreams.limit(zip, entry.getSize()));
            externsMap.put(entry.getName(), SourceFile.fromInputStream(
                    // Give the files an odd prefix, so that they do not conflict
                    // with the user's files.
                    "externs.zip//" + entry.getName(), entryStream));
            entry = zip.getNextEntry();
        }

        Preconditions.checkState(externsMap.keySet().equals(Sets.newHashSet(DEFAULT_EXTERNS_NAMES)),
                "Externs zip must match our hard-coded list of externs.");

        // Order matters, so the resources must be added to the result list
        // in the expected order.
        List<SourceFile> externs = Lists.newArrayList();
        for (String key : DEFAULT_EXTERNS_NAMES) {
            externs.add(externsMap.get(key));
        }

        return externs;
    } finally {
        IOUtils.closeQuietly(zip);
    }
}

From source file:org.jumpmind.metl.core.runtime.component.UnZip.java

@Override
public void handle(Message inputMessage, ISendMessageCallback callback, boolean unitOfWorkBoundaryReached) {
    if (inputMessage instanceof TextMessage) {
        List<String> files = ((TextMessage) inputMessage).getPayload();
        ArrayList<String> filePaths = new ArrayList<String>();
        for (String fileName : files) {
            log(LogLevel.INFO, "Preparing to extract file : %s", fileName);
            FileInfo sourceZipFile = sourceDir.listFile(fileName);
            if (mustExist && sourceZipFile == null) {
                throw new IoException(String.format("Could not find file to extract: %s", fileName));
            }/*  ww  w.ja  va 2  s .c  o  m*/
            if (sourceZipFile != null) {
                File unzipDir = new File(LogUtils.getLogDir(), "unzip");
                unzipDir.mkdirs();

                File localZipFile = copyZipLocally(fileName, unzipDir);
                ZipFile zipFile = getNewZipFile(localZipFile);
                InputStream in = null;
                OutputStream out = null;
                try {
                    String targetDirNameResolved = resolveParamsAndHeaders(targetRelativePath, inputMessage);
                    if (targetSubDir) {
                        targetDirNameResolved = targetDirNameResolved + "/"
                                + FilenameUtils.removeExtension(new FileInfo(fileName, false, 0, 0).getName());
                    }
                    for (Enumeration<? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements();) {
                        ZipEntry entry = e.nextElement();
                        if (!entry.isDirectory() && (extractEmptyFiles || entry.getSize() > 0)) {
                            String relativePathToEntry = targetDirNameResolved + "/" + entry.getName();
                            if (overwrite || targetDir.listFile(relativePathToEntry) == null) {
                                info("Unzipping %s", entry.getName());
                                out = targetDir.getOutputStream(relativePathToEntry, false);
                                in = zipFile.getInputStream(entry);
                                IOUtils.copy(in, out);
                                filePaths.add(relativePathToEntry);
                            } else if (!overwrite) {
                                info("Not unzipping %s.  It already exists and the override property is not enabled",
                                        entry.getName());
                            }
                        }
                    }
                } catch (IOException e) {
                    throw new IoException(e);
                } finally {
                    IOUtils.closeQuietly(in);
                    IOUtils.closeQuietly(out);
                    IOUtils.closeQuietly(zipFile);
                    FileUtils.deleteQuietly(localZipFile);
                }
                if (deleteOnComplete) {
                    sourceDir.delete(fileName);
                }

                log(LogLevel.INFO, "Extracted %s", fileName);
                getComponentStatistics().incrementNumberEntitiesProcessed(threadNumber);
            }
        }
        if (filePaths.size() > 0) {
            callback.sendTextMessage(null, filePaths);
        }
    }
}

From source file:password.pwm.http.servlet.resource.ResourceServletService.java

private String makeResourcePathNonce() throws PwmUnrecoverableException, IOException {
    final boolean enablePathNonce = Boolean.parseBoolean(
            pwmApplication.getConfig().readAppProperty(AppProperty.HTTP_RESOURCES_ENABLE_PATH_NONCE));
    if (!enablePathNonce) {
        return "";
    }/*w  w  w .j  a  v a  2s . c  o m*/

    final Instant startTime = Instant.now();
    final ChecksumOutputStream checksumOs = new ChecksumOutputStream(PwmHashAlgorithm.MD5,
            new NullOutputStream());

    if (pwmApplication.getPwmEnvironment().getContextManager() != null) {
        try {
            final File webInfPath = pwmApplication.getPwmEnvironment().getContextManager()
                    .locateWebInfFilePath();
            if (webInfPath != null && webInfPath.exists()) {
                final File basePath = webInfPath.getParentFile();
                if (basePath != null && basePath.exists()) {
                    final File resourcePath = new File(basePath.getAbsolutePath() + File.separator + "public"
                            + File.separator + "resources");
                    if (resourcePath.exists()) {
                        final List<FileSystemUtility.FileSummaryInformation> fileSummaryInformations = new ArrayList<>();
                        fileSummaryInformations.addAll(FileSystemUtility.readFileInformation(resourcePath));
                        for (final FileSystemUtility.FileSummaryInformation fileSummaryInformation : fileSummaryInformations) {
                            checksumOs.write((fileSummaryInformation.getSha1sum())
                                    .getBytes(PwmConstants.DEFAULT_CHARSET));
                        }
                    }
                }
            }
        } catch (Exception e) {
            LOGGER.error("unable to generate resource path nonce: " + e.getMessage());
        }
    }

    for (final FileResource fileResource : getResourceServletConfiguration().getCustomFileBundle().values()) {
        JavaHelper.copyWhilePredicate(fileResource.getInputStream(), checksumOs, o -> true);
    }

    if (getResourceServletConfiguration().getZipResources() != null) {
        for (final String key : getResourceServletConfiguration().getZipResources().keySet()) {
            final ZipFile value = getResourceServletConfiguration().getZipResources().get(key);
            checksumOs.write(key.getBytes(PwmConstants.DEFAULT_CHARSET));
            for (Enumeration<? extends ZipEntry> zipEnum = value.entries(); zipEnum.hasMoreElements();) {
                final ZipEntry entry = zipEnum.nextElement();
                checksumOs.write(Long.toHexString(entry.getSize()).getBytes(PwmConstants.DEFAULT_CHARSET));
            }
        }
    }

    final String nonce = JavaHelper.byteArrayToHexString(checksumOs.getInProgressChecksum()).toLowerCase();
    LOGGER.debug("completed generation of nonce '" + nonce + "' in "
            + TimeDuration.fromCurrent(startTime).asCompactString());

    final String noncePrefix = pwmApplication.getConfig()
            .readAppProperty(AppProperty.HTTP_RESOURCES_NONCE_PATH_PREFIX);
    return "/" + noncePrefix + nonce;
}

From source file:org.intermine.api.lucene.KeywordSearch.java

private static FSDirectory readFSDirectory(String path, InputStream is)
        throws IOException, FileNotFoundException {
    long time = System.currentTimeMillis();
    final int bufferSize = 2048;
    File directoryPath = new File(path + File.separator + LUCENE_INDEX_DIR);
    LOG.debug("Directory path: " + directoryPath);

    // make sure we start with a new index
    if (directoryPath.exists()) {
        String[] files = directoryPath.list();
        for (int i = 0; i < files.length; i++) {
            LOG.info("Deleting old file: " + files[i]);
            new File(directoryPath.getAbsolutePath() + File.separator + files[i]).delete();
        }/*from   w w  w .j a  v  a2 s.  co  m*/
    } else {
        directoryPath.mkdir();
    }

    ZipInputStream zis = new ZipInputStream(is);
    ZipEntry entry;
    try {
        while ((entry = zis.getNextEntry()) != null) {
            LOG.info("Extracting: " + entry.getName() + " (" + entry.getSize() + " MB)");

            FileOutputStream fos = new FileOutputStream(
                    directoryPath.getAbsolutePath() + File.separator + entry.getName());
            BufferedOutputStream bos = new BufferedOutputStream(fos, bufferSize);

            int count;
            byte[] data = new byte[bufferSize];

            try {
                while ((count = zis.read(data, 0, bufferSize)) != -1) {
                    bos.write(data, 0, count);
                }
            } finally {
                bos.flush();
                bos.close();
            }
        }
    } finally {
        zis.close();
    }

    FSDirectory directory = FSDirectory.open(directoryPath);

    LOG.info("Successfully restored FS directory from database in " + (System.currentTimeMillis() - time)
            + " ms");
    return directory;
}