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:Main.java

public static void main(String[] args) throws Exception {
    String zipname = "data.zip";
    ZipFile zipFile = new ZipFile(zipname);
    Enumeration enumeration = zipFile.entries();
    while (enumeration.hasMoreElements()) {
        ZipEntry zipEntry = (ZipEntry) enumeration.nextElement();
        System.out.println(zipEntry.getTime());
    }/*from w w  w .j a v a 2  s  .  c  o  m*/
}

From source file:MainClass.java

public static void main(String[] args) {

    try {/*from w  w  w  . jav  a  2 s .c o  m*/
        ZipFile zf = new ZipFile("your.zip");
        Enumeration e = zf.entries();
        while (e.hasMoreElements()) {
            ZipEntry ze = (ZipEntry) e.nextElement();
            String name = ze.getName();
            Date lastModified = new Date(ze.getTime());
            long uncompressedSize = ze.getSize();
            long compressedSize = ze.getCompressedSize();

            System.out.println(name);
            System.out.println(lastModified);
            System.out.println(uncompressedSize);
            System.out.println(compressedSize);

        }
    } catch (IOException ex) {
        System.err.println(ex);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ZipFile zf = new ZipFile("your.zip");
    Enumeration e = zf.entries();
    while (e.hasMoreElements()) {
        ZipEntry ze = (ZipEntry) e.nextElement();
        String name = ze.getName();

        Date lastModified = new Date(ze.getTime());
        long uncompressedSize = ze.getSize();
        long compressedSize = ze.getCompressedSize();

        int method = ze.getMethod();

        if (method == ZipEntry.STORED) {
            System.out.println(name + " was stored at " + lastModified);
            System.out.println("with a size of  " + uncompressedSize + " bytes");
        } else if (method == ZipEntry.DEFLATED) {
            System.out.println(name + " was deflated at " + lastModified);
            System.out.println("from  " + uncompressedSize + " bytes to " + compressedSize
                    + " bytes, a savings of " + (100.0 - 100.0 * compressedSize / uncompressedSize) + "%");
        } else {/*from   www.  ja va  2  s  .  c o  m*/
            System.out.println(name + " was compressed at " + lastModified);
            System.out.println("from  " + uncompressedSize + " bytes to " + compressedSize
                    + " bytes, a savings of " + (100.0 - 100.0 * compressedSize / uncompressedSize) + "%");
        }
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileInputStream fis = new FileInputStream(args[0]);
    ZipInputStream zis = new ZipInputStream(fis);

    ZipEntry ze;
    while ((ze = zis.getNextEntry()) != null)
        System.out.println(/*ww w  .  ja va2 s  . c o m*/
                ze.getName() + "  [" + ze.getSize() + "]  [" + new Date(ze.getTime()).toString() + "]");
}

From source file:ZipReader.java

public static void main(String[] args) throws Exception {
    ZipInputStream zis = null;/*from   w ww .j a  va 2  s  . c o  m*/

    FileInputStream fis = new FileInputStream(args[0]);
    zis = new ZipInputStream(fis);

    ZipEntry ze;

    while ((ze = zis.getNextEntry()) != null)
        System.out.println(
                ze.getName() + "  [" + ze.getSize() + "]  [" + new Date(ze.getTime()).toString() + "]");
}

From source file:MainClass.java

public static void main(String[] args) {

    try {//from   w  w  w . j a va  2 s .  co m
        ZipFile zf = new ZipFile("your.zip");
        Enumeration e = zf.entries();
        while (e.hasMoreElements()) {
            ZipEntry ze = (ZipEntry) e.nextElement();
            String name = ze.getName();

            Date lastModified = new Date(ze.getTime());
            long uncompressedSize = ze.getSize();
            long compressedSize = ze.getCompressedSize();

            int method = ze.getMethod();

            if (method == ZipEntry.STORED) {
                System.out.println(name + " was stored at " + lastModified);
                System.out.println("with a size of  " + uncompressedSize + " bytes");
            } else if (method == ZipEntry.DEFLATED) {
                System.out.println(name + " was deflated at " + lastModified);
                System.out.println("from  " + uncompressedSize + " bytes to " + compressedSize
                        + " bytes, a savings of " + (100.0 - 100.0 * compressedSize / uncompressedSize) + "%");
            } else {
                System.out.println(name + " was compressed using an unrecognized method at " + lastModified);
                System.out.println("from  " + uncompressedSize + " bytes to " + compressedSize
                        + " bytes, a savings of " + (100.0 - 100.0 * compressedSize / uncompressedSize) + "%");
            }
        }
    } catch (IOException ex) {
        System.err.println(ex);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ZipFile zf = new ZipFile("a.zip");
    Enumeration e = zf.entries();
    while (e.hasMoreElements()) {
        ZipEntry ze = (ZipEntry) e.nextElement();
        String name = ze.getName();

        long uncompressedSize = ze.getSize();
        long compressedSize = ze.getCompressedSize();
        long crc = ze.getCrc();
        int method = ze.getMethod();
        String comment = ze.getComment();

        System.out.println(name + " was stored at " + new Date(ze.getTime()));
        if (method == ZipEntry.STORED) {
            System.out.println("with a size of  " + uncompressedSize + " bytes");
        } else if (method == ZipEntry.DEFLATED) {
            System.out.println("from " + uncompressedSize + " bytes to " + compressedSize);
        } else {//from w  ww.  ja va 2s  .  com
            System.out.println("from " + uncompressedSize + " bytes to " + compressedSize);
        }
        System.out.println("Its CRC is " + crc);
        if (comment != null && !comment.equals("")) {
            System.out.println(comment);
        }
        if (ze.isDirectory()) {
            System.out.println(name + " is a directory");
        }
    }
}

From source file:Main.java

public static String getBuildTimestamp(Activity activity) {
    String s = "";
    try {/*from  w ww. j  a  v a2  s  .c o  m*/
        ApplicationInfo ai = activity.getPackageManager().getApplicationInfo(activity.getPackageName(), 0);
        ZipFile zf = new ZipFile(ai.sourceDir);
        ZipEntry ze = zf.getEntry("classes.dex");
        long time = ze.getTime();
        s = SimpleDateFormat.getInstance().format(new java.util.Date(time));
        zf.close();
    } catch (Exception e) {
    }
    return s;
}

From source file:com.skwas.cordova.appinfo.AppInfo.java

public static long getBuildDate(Context context) {

    ZipFile zf = null;//  w  ww . java 2s  . c  o  m
    try {
        ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0);
        zf = new ZipFile(ai.sourceDir);
        ZipEntry ze = zf.getEntry("classes.dex");
        long time = ze.getTime();
        return time;

    } catch (Exception e) {
    }

    finally {
        try {
            if (zf != null)
                zf.close();
        } catch (IOException e) {
        }
    }

    return 0l;
}

From source file:Utils.java

/**
 * unpack a segment from a zip//ww w. j  a v  a 2 s. c  o  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;

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

        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);
    }
    fout.close();
}