Example usage for java.util.zip ZipEntry getComment

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

Introduction

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

Prototype

public String getComment() 

Source Link

Document

Returns the comment string for the entry.

Usage

From source file:org.digidoc4j.impl.bdoc.asic.AsicContainerParser.java

protected void parseEntry(ZipEntry entry) {
    String entryName = entry.getName();
    logger.debug("Paring zip entry " + entryName + " with comment: " + entry.getComment());
    if (isMimeType(entryName)) {
        extractMimeType(entry);// w ww.  j  av  a  2s  . co m
    } else if (isManifest(entryName)) {
        extractManifest(entry);
    } else if (isSignaturesFile(entryName)) {
        determineCurrentSignatureFileIndex(entryName);
        extractSignature(entry);
    } else if (isDataFile(entryName)) {
        extractDataFile(entry);
    } else {
        extractAsicEntry(entry);
    }
}

From source file:org.lockss.exporter.FuncZipExporter.java

public List<String> testExport(boolean isCompress, long maxSize, FilenameTranslation xlate,
        boolean excludeDirContent) throws Exception {
    exportDir = getTempDir();//  w  w  w. java  2 s .  c  om
    exportFiles = null;
    ZipExporter exp = new ZipExporter(daemon, sau);
    exp.setDir(exportDir);
    exp.setPrefix("zippre");
    exp.setCompress(isCompress);
    exp.setFilenameTranslation(xlate);
    exp.setExcludeDirNodes(excludeDirContent);
    if (maxSize > 0) {
        exp.setMaxSize(maxSize);
    }
    exp.export();

    int numZipRecords = 0;
    File expFile;
    List<String> urls = new ArrayList<String>();
    while ((expFile = nextExportFile()) != null) {
        ZipFile zip = new ZipFile(expFile);

        Enumeration iter = zip.entries();
        while (iter.hasMoreElements()) {
            ZipEntry rec = null;
            CachedUrl cu = null;
            try {
                rec = (ZipEntry) iter.nextElement();
                String url = rec.getName();
                switch (xlate) {
                case XLATE_NONE:
                    assertMatchesRE("^http://", url);
                    break;
                case XLATE_WINDOWS:
                case XLATE_MAC:
                    // The filenames were translated.  Current windows translation
                    // isn't reversible in general, but we know that the only
                    // windows-illegal character in simulated content is the colon,
                    // so we can reverse it.  If that changes, this test will
                    // break.

                    assertMatchesRE("^http_//", url);
                    url = StringUtil.replaceString(url, "_", ":");
                    break;

                }
                String comment = rec.getComment();
                cu = sau.makeCachedUrl(url);
                //      log.debug("Comp " + hdr.getMimetype() + ": " + url);
                assertTrue("No content in AU: " + url, cu.hasContent());
                urls.add(cu.getUrl());
                InputStream ins = cu.getUnfilteredInputStream();
                assertTrue(StreamUtil.compare(zip.getInputStream(rec), ins));
                assertEquals(cu.getContentSize(), rec.getSize());
                //       assertMatchesRE(cu.getContentType(), comment);
                numZipRecords++;

            } finally {
                AuUtil.safeRelease(cu);
            }
        }

    }
    if (excludeDirContent) {
        assertEquals(auUrls.size() - auDirs.size(), numZipRecords);
    } else {
        assertEquals(auUrls.size(), numZipRecords);
    }
    if (maxSize <= 0) {
        assertEquals(1, exportFiles.length);
    } else {
        assertTrue("Expected more than one export file", exportFiles.length > 1);
    }
    return urls;
}

From source file:org.paxle.core.doc.impl.BasicDocumentFactoryTest.java

public void testStoreMarshalledCommand() throws IOException, ParseException {
    // Create the ZIP file
    final File outFile = File.createTempFile("command", ".zip");
    outFile.deleteOnExit();/*  w  ww  .  ja  va  2s .  c o  m*/
    ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(outFile));

    // creating a test command
    final ICommand cmd = this.createTestCommand();

    // marshal command
    final ZipEntry commandEntry = new ZipEntry("command.xml");
    commandEntry.setComment("command.xml");
    zipOut.putNextEntry(commandEntry);

    final TeeOutputStream out = new TeeOutputStream(System.out, zipOut);
    final Map<String, DataHandler> attachments = this.docFactory.marshal(cmd, out);
    zipOut.closeEntry();

    // write attachments
    if (attachments != null) {
        for (Entry<String, DataHandler> attachment : attachments.entrySet()) {
            final String cid = attachment.getKey();
            final DataHandler data = attachment.getValue();

            final ZipEntry zipEntry = new ZipEntry(cid);
            zipEntry.setComment(data.getName());
            zipOut.putNextEntry(zipEntry);

            IOUtils.copy(data.getInputStream(), zipOut);
            zipOut.closeEntry();
        }
    }
    zipOut.close();
    System.out.println("Command written into file: " + outFile.toString());

    // print content
    final ZipFile zf = new ZipFile(outFile);
    for (Enumeration<? extends ZipEntry> entries = zf.entries(); entries.hasMoreElements();) {
        ZipEntry entry = entries.nextElement();
        System.out.println(entry.getName() + ": " + entry.getComment());
    }
    zf.close();
}

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

public ZipContentLocation(ZipRepository repository, ZipContentLocation parent, ZipEntry zipEntry) {
    if (repository == null) {
        throw new NullPointerException();
    }/*from w ww.  jav  a  2  s.  c om*/
    if (parent == null) {
        throw new NullPointerException();
    }
    if (zipEntry == null) {
        throw new NullPointerException();
    }

    this.repository = repository;
    this.parent = parent;
    this.entryName = IOUtils.getInstance().getFileName(zipEntry.getName());
    this.comment = zipEntry.getComment();
    this.size = zipEntry.getSize();
    this.time = zipEntry.getTime();
    this.entries = new HashMap();
    this.name = RepositoryUtilities.buildName(this, "/") + '/';
}

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.pentaho.reporting.libraries.repository.zipreader.ZipReadContentLocation.java

public ZipReadContentLocation(ZipReadRepository repository, ZipReadContentLocation parent, ZipEntry zipEntry) {
    if (repository == null) {
        throw new NullPointerException();
    }/*from w ww .ja  v  a  2s  .  c  om*/
    if (parent == null) {
        throw new NullPointerException();
    }
    if (zipEntry == null) {
        throw new NullPointerException();
    }

    this.repository = repository;
    this.parent = parent;
    this.comment = zipEntry.getComment();
    this.size = zipEntry.getSize();
    this.time = zipEntry.getTime();
    this.entries = new HashMap();
    this.entryName = IOUtils.getInstance().getFileName(zipEntry.getName());
    this.name = RepositoryUtilities.buildName(this, "/") + '/';
}

From source file:org.signserver.anttasks.PostProcessModulesTask.java

/**
 * Replacer for the postprocess-jar Ant macro.
 * /*from w w w .j av a2  s .  c  o m*/
 * @param replaceincludes Ant list of all files in the jar to replace in
 * @param src Source jar file
 * @param destfile Destination jar file
 * @param properties Properties to replace from
 * @param self The Task (used for logging)
 * @throws IOException in case of error
 */
protected void replaceInJar(String replaceincludes, String src, String destfile, Map properties, Task self)
        throws IOException {
    try {
        self.log("Replace " + replaceincludes + " in " + src + " to " + destfile, Project.MSG_VERBOSE);

        File srcFile = new File(src);
        if (!srcFile.exists()) {
            throw new FileNotFoundException(srcFile.getAbsolutePath());
        }

        // Expand properties of all files in replaceIncludes
        HashSet<String> replaceFiles = new HashSet<String>();
        String[] rfiles = replaceincludes.split(",");
        for (int i = 0; i < rfiles.length; i++) {
            rfiles[i] = rfiles[i].trim();
        }
        replaceFiles.addAll(Arrays.asList(rfiles));
        self.log("Files to replace: " + replaceFiles, Project.MSG_INFO);

        // Open source zip file
        ZipFile zipSrc = new ZipFile(srcFile);
        ZipOutputStream zipDest = new ZipOutputStream(new FileOutputStream(destfile));

        // For each entry in the source file copy them to dest file and postprocess if necessary
        Enumeration<? extends ZipEntry> entries = zipSrc.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            String name = entry.getName();

            if (entry.isDirectory()) {
                // Just put the directory
                zipDest.putNextEntry(entry);
            } else {
                // If we should postprocess the entry
                if (replaceFiles.contains(name)) {
                    name += (" [REPLACE]");
                    self.log(name, Project.MSG_VERBOSE);

                    // Create a new zip entry for the file
                    ZipEntry newEntry = new ZipEntry(entry.getName());
                    newEntry.setComment(entry.getComment());
                    newEntry.setExtra(entry.getExtra());
                    zipDest.putNextEntry(newEntry);

                    // Read the old document
                    StringBuffer oldDocument = stringBufferFromFile(zipSrc.getInputStream(entry));
                    self.log("Before replace ********\n" + oldDocument.toString() + "\n", Project.MSG_DEBUG);

                    // Do properties substitution
                    StrSubstitutor sub = new StrSubstitutor(properties);
                    StringBuffer newerDocument = commentReplacement(oldDocument, properties);
                    String newDocument = sub.replace(newerDocument);
                    self.log("After replace ********\n" + newDocument.toString() + "\n", Project.MSG_DEBUG);

                    // Write the new document
                    byte[] newBytes = newDocument.getBytes("UTF-8");
                    entry.setSize(newBytes.length);
                    copy(new ByteArrayInputStream(newBytes), zipDest);
                } else {
                    // Just copy the entry to dest zip file
                    name += (" []");
                    self.log(name, Project.MSG_VERBOSE);
                    zipDest.putNextEntry(entry);
                    copy(zipSrc.getInputStream(entry), zipDest);
                }
                zipDest.closeEntry();
            }
        }
        zipSrc.close();
        zipDest.close();
    } catch (IOException ex) {
        throw new BuildException(ex);
    }
}

From source file:org.xmlactions.common.zip.ZipFile.java

public static void copyFiles(ZipFileReader zr, ZipFileWriter zw) throws IOException {
    Vector zipEntries = zr.getZipEntries();
    for (int iLoop = 0; iLoop < zipEntries.size(); iLoop++) {
        ZipEntry ze = (ZipEntry) zipEntries.get(iLoop);
        //log.debug("copying file:" + ze.getName());
        zw.addFile(zr.getInputStream(ze), ze.getName(), ze.getComment());
    }/*from  ww  w .  ja v a 2  s.  c o m*/
}