Example usage for java.util.zip ZipEntry getTime

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

Introduction

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

Prototype

public long getTime() 

Source Link

Document

Returns the last modification time of the entry.

Usage

From source file:org.sonar.updatecenter.deprecated.Plugin.java

public static Plugin extractMetadata(File file) throws IOException {
    JarFile jar = new JarFile(file);
    ZipEntry entry = jar.getEntry("META-INF/MANIFEST.MF");
    long timestamp = entry.getTime();
    Manifest manifest = jar.getManifest();
    jar.close();//from w ww.  j av a  2s.com

    Attributes attributes = manifest.getMainAttributes();
    String pluginKey = attributes.getValue("Plugin-Key");
    Plugin plugin = new Plugin(pluginKey);
    plugin.setName(attributes.getValue("Plugin-Name"));
    plugin.setVersion(attributes.getValue("Plugin-Version"));
    plugin.setRequiredSonarVersion(attributes.getValue("Sonar-Version"));
    plugin.setHomepage(attributes.getValue("Plugin-Homepage"));
    plugin.setDate(timestamp);
    return plugin;
}

From source file:org.sakaiproject.kernel.util.FileUtil.java

public static void unpack(InputStream source, File destination) throws IOException {
    ZipInputStream zin = new ZipInputStream(source);
    ZipEntry zipEntry = null;
    FileOutputStream fout = null;
    try {/*from   w  w  w . j a  v  a 2 s .  c o m*/
        byte[] buffer = new byte[4096];
        while ((zipEntry = zin.getNextEntry()) != null) {

            long ts = zipEntry.getTime();
            // the zip entry needs to be a full path from the
            // searchIndexDirectory... hence this is correct

            File f = new File(destination, zipEntry.getName());
            LOG.info("         Unpack " + f.getAbsolutePath());
            f.getParentFile().mkdirs();

            if (!zipEntry.isDirectory()) {
                fout = new FileOutputStream(f);
                int len;
                while ((len = zin.read(buffer)) > 0) {
                    fout.write(buffer, 0, len);
                }
                zin.closeEntry();
                fout.close();
            }
            f.setLastModified(ts);
        }
    } finally {
        try {
            fout.close();
        } catch (Exception ex) {
            LOG.warn("Exception closing file output stream", ex);
        }
        try {
            zin.close();
        } catch (Exception ex) {
            LOG.warn("Exception closing file input stream", ex);
        }
    }
}

From source file:com.alibaba.antx.util.ZipUtil.java

/**
 * /*  w ww .j  a v  a2 s . c  o  m*/
 *
 * @param todir     
 * @param zipStream ?
 * @param zipEntry  zip
 * @param overwrite ?
 * @throws IOException Zip?
 */
protected static void extractFile(File todir, InputStream zipStream, ZipEntry zipEntry, boolean overwrite)
        throws IOException {
    String entryName = zipEntry.getName();
    Date entryDate = new Date(zipEntry.getTime());
    boolean isDirectory = zipEntry.isDirectory();
    File targetFile = FileUtil.getFile(todir, entryName);

    if (!overwrite && targetFile.exists() && targetFile.lastModified() >= entryDate.getTime()) {
        log.debug("Skipping " + targetFile + " as it is up-to-date");
        return;
    }

    log.info("expanding " + entryName + " to " + targetFile);

    if (isDirectory) {
        targetFile.mkdirs();
    } else {
        File dir = targetFile.getParentFile();

        dir.mkdirs();

        byte[] buffer = new byte[8192];
        int length = 0;
        OutputStream ostream = null;

        try {
            ostream = new BufferedOutputStream(new FileOutputStream(targetFile), 8192);

            while ((length = zipStream.read(buffer)) >= 0) {
                ostream.write(buffer, 0, length);
            }
        } finally {
            if (ostream != null) {
                try {
                    ostream.close();
                } catch (IOException e) {
                }
            }
        }
    }

    targetFile.setLastModified(entryDate.getTime());
}

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

private static Map<String, FileResource> makeMemoryFileMapFromZipInput(final byte[] content)
        throws IOException {
    final ZipInputStream stream = new ZipInputStream(new ByteArrayInputStream(content));
    final Map<String, FileResource> memoryMap = new HashMap<>();

    ZipEntry entry;
    while ((entry = stream.getNextEntry()) != null) {
        if (!entry.isDirectory()) {
            final String name = entry.getName();
            final long lastModified = entry.getTime();
            final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            IOUtils.copy(stream, byteArrayOutputStream);
            final byte[] contents = byteArrayOutputStream.toByteArray();
            memoryMap.put(name, new MemoryFileResource(name, contents, lastModified));
            LOGGER.trace("discovered file in configured resource bundle: " + entry.getName());
        }// w  w  w.ja v a  2 s . c  om
    }
    return memoryMap;
}

From source file:hudson.plugins.simpleupdatesite.HPI.java

public static HPI loadHPI(File file) throws IOException {
    JarFile jarFile = new JarFile(file);
    try {/*  w ww. j  a va2s. c o m*/
        ZipEntry entry = jarFile.getEntry("META-INF/MANIFEST.MF");
        HPI hpi = new HPI();
        hpi.init(jarFile.getManifest().getMainAttributes(), entry.getTime());
        return hpi;
    } finally {
        jarFile.close();
    }
}

From source file:de.micromata.genome.gdbfs.FileSystemUtils.java

/**
 * Copy from zip.//  ww  w. j a v  a  2s .  c o m
 *
 * @param ze the ze
 * @param zin the zin
 * @param target the target
 */
public static void copyFromZip(ZipEntry ze, ZipInputStream zin, FsObject target) {
    String name = ze.getName();
    name = normalizeZipName(name);
    ze.getTime();
    if (name.endsWith("/") == true) {
        String fqName = mergeDirNames(target.getName(), name);
        fqName = fqName.substring(0, fqName.length() - 1);
        if (target.getFileSystem().existsForWrite(fqName) == true) {
            return;
        }
        target.getFileSystem().mkdirs(fqName);
    } else {
        String fqName = mergeDirNames(target.getName(), name);
        String pd = AbstractFileSystem.getParentDirString(fqName);
        if (target.getFileSystem().exists(pd) == false) {
            target.getFileSystem().mkdirs(pd);
        }
        target.getFileSystem().writeBinaryFile(fqName, zin, true);
    }
}

From source file:org.envirocar.app.util.Util.java

/**
 * method to get the current version//w w  w  . j a  va 2  s  .c  o m
 * 
 */
public static String getVersionString(Context ctx) {
    StringBuilder out = new StringBuilder("Version ");
    try {
        out.append(getVersionStringShort(ctx));
        out.append(" (");
        out.append(ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0).versionCode);
        out.append("), ");
    } catch (NameNotFoundException e) {
        logger.warn(e.getMessage(), e);
    }
    try {
        ApplicationInfo ai = ctx.getPackageManager().getApplicationInfo(ctx.getPackageName(), 0);
        ZipFile zf = new ZipFile(ai.sourceDir);
        ZipEntry ze = zf.getEntry("classes.dex");
        long time = ze.getTime();
        out.append(SimpleDateFormat.getInstance().format(new java.util.Date(time)));
        zf.close();
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
    }

    return out.toString();
}

From source file:org.sakaiproject.portal.charon.test.PortalTestFileUtils.java

/**
 * unpack a segment from a zip/*from  w ww  .  j a v  a2s  .com*/
 * 
 * @param addsi
 * @param packetStream
 * @param version
 */
public static void unpack(InputStream source, File destination) throws IOException {
    ZipInputStream zin = new ZipInputStream(source);
    ZipEntry zipEntry = null;
    FileOutputStream fout = null;
    try {
        byte[] buffer = new byte[4096];
        while ((zipEntry = zin.getNextEntry()) != null) {

            long ts = zipEntry.getTime();
            // the zip entry needs to be a full path from the
            // searchIndexDirectory... hence this is correct

            File f = new File(destination, zipEntry.getName());
            if (log.isDebugEnabled())
                log.debug("         Unpack " + f.getAbsolutePath());
            f.getParentFile().mkdirs();

            fout = new FileOutputStream(f);
            int len;
            while ((len = zin.read(buffer)) > 0) {
                fout.write(buffer, 0, len);
            }
            zin.closeEntry();
            fout.close();
            f.setLastModified(ts);
        }
    } finally {
        try {
            fout.close();
        } catch (Exception ex) {
        }
    }
}

From source file:org.cloudfoundry.client.lib.SampleProjects.java

private static void unpackZip(ZipFile zipFile, File unpackDir) throws IOException {
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        File destination = new File(unpackDir.getAbsolutePath() + "/" + entry.getName());
        if (entry.isDirectory()) {
            destination.mkdirs();/*w w w.j a va  2s  .c  o m*/
        } else {
            destination.getParentFile().mkdirs();
            FileCopyUtils.copy(zipFile.getInputStream(entry), new FileOutputStream(destination));
        }
        if (entry.getTime() != -1) {
            destination.setLastModified(entry.getTime());
        }
    }
}

From source file:org.sakaiproject.search.util.FileUtils.java

/**
 * unpack a segment from a zip//from  w  w w . j  a  va2s . co m
 * 
 * @param addsi
 * @param packetStream
 * @param version
 */
public static void unpack(InputStream source, File destination) throws IOException {
    ZipInputStream zin = new ZipInputStream(source);
    ZipEntry zipEntry = null;
    FileOutputStream fout = null;
    try {
        byte[] buffer = new byte[4096];
        while ((zipEntry = zin.getNextEntry()) != null) {

            long ts = zipEntry.getTime();
            // the zip entry needs to be a full path from the
            // searchIndexDirectory... hence this is correct

            File f = new File(destination, zipEntry.getName());
            if (log.isDebugEnabled())
                log.debug("         Unpack " + f.getAbsolutePath());
            if (!f.getParentFile().exists()) {
                if (!f.getParentFile().mkdirs()) {
                    log.warn("unpack(): Failed to create parent folder: " + f.getParentFile().getPath());
                }
            }

            fout = new FileOutputStream(f);
            int len;
            while ((len = zin.read(buffer)) > 0) {
                fout.write(buffer, 0, len);
            }
            zin.closeEntry();
            fout.close();
            if (!f.setLastModified(ts)) {
                log.warn("upack(): failes to set modified date on " + f.getPath());
            }
        }
    } finally {
        try {
            fout.close();
        } catch (Exception ex) {
            log.warn("Exception closing file output stream", ex);
        }
    }
}