List of usage examples for java.util.zip ZipEntry getCrc
public long getCrc()
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.getCrc()); }/*w w w . j a v a2s . c om*/ }
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(); long crc = ze.getCrc(); System.out.println("Its CRC is " + crc); String comment = ze.getComment(); if (comment != null && !comment.equals("")) { System.out.println(comment); }//from w ww . ja v a 2 s . c om if (ze.isDirectory()) { System.out.println(name + " is a directory"); } } }
From source file:MainClass.java
public static void main(String[] args) { try {/*from ww w. ja va2 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(); long crc = ze.getCrc(); System.out.println("Its CRC is " + crc); String comment = ze.getComment(); if (comment != null && !comment.equals("")) { System.out.println(comment); } if (ze.isDirectory()) { System.out.println(name + " is a directory"); } } } 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 w w . j a v a 2 s . c om*/ 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
/** * Check is classes.dex file has modified * // www . java 2 s . co m * @author : sWX293372 * @version: 1.0 * @return boolean if the classes.dex is modified then return true, else * return true * @createTime : 2016-5-9 */ public static boolean checkCRC(Context context, long crc) { boolean isModified = true; try { ZipFile zipFile = new ZipFile(context.getPackageCodePath()); ZipEntry entry = zipFile.getEntry("classes.dex"); if (crc == entry.getCrc()) { isModified = false; } } catch (IOException e) { isModified = true; e.printStackTrace(); } return isModified; }
From source file:com.taobao.android.builder.tools.zip.ZipUtils.java
public static void addFileAndDirectoryToZip(File output, File srcDir, Map<String, ZipEntry> zipEntryMethodMap) throws Exception { if (output.isDirectory()) { throw new IOException("This is a directory!"); }/* ww w . jav a2 s .c om*/ if (!output.getParentFile().exists()) { output.getParentFile().mkdirs(); } if (!output.exists()) { output.createNewFile(); } List fileList = getSubFiles(srcDir); ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(output)); ZipEntry ze = null; byte[] buf = new byte[1024]; int readLen = 0; for (int i = 0; i < fileList.size(); i++) { File f = (File) fileList.get(i); ze = new ZipEntry(getAbsFileName(srcDir.getPath(), f)); ze.setSize(f.length()); ze.setTime(f.lastModified()); if (zipEntryMethodMap != null) { ZipEntry originEntry = zipEntryMethodMap.get(f.getAbsolutePath()); if (originEntry != null) { ze.setCompressedSize(originEntry.getCompressedSize()); ze.setCrc(originEntry.getCrc()); ze.setMethod(originEntry.getMethod()); } } zos.putNextEntry(ze); InputStream is = new BufferedInputStream(new FileInputStream(f)); while ((readLen = is.read(buf, 0, 1024)) != -1) { zos.write(buf, 0, readLen); } is.close(); } zos.close(); }
From source file:org.ambraproject.article.service.XslIngestArchiveProcessor.java
/** * Generate a description for a single zip-entry. * * @param ze the zip entry to describe. * @param buf the buffer to place the description into *//* w ww . ja v a2 s. c o m*/ private static void entry2xml(ZipEntry ze, StringBuilder buf) { buf.append("<ZipEntry name=\"").append(attrEscape(ze.getName())).append("\""); if (ze.isDirectory()) buf.append(" isDirectory=\"true\""); if (ze.getCrc() >= 0) buf.append(" crc=\"").append(ze.getCrc()).append("\""); if (ze.getSize() >= 0) buf.append(" size=\"").append(ze.getSize()).append("\""); if (ze.getCompressedSize() >= 0) buf.append(" compressedSize=\"").append(ze.getCompressedSize()).append("\""); if (ze.getTime() >= 0) buf.append(" time=\"").append(ze.getTime()).append("\""); if (ze.getComment() != null || ze.getExtra() != null) { buf.append(">\n"); if (ze.getComment() != null) buf.append("<Comment>").append(xmlEscape(ze.getComment())).append("</Comment>\n"); if (ze.getExtra() != null) buf.append("<Extra>").append(base64Encode(ze.getExtra())).append("</Extra>\n"); buf.append("</ZipEntry>\n"); } else { buf.append("/>\n"); } }
From source file:io.gromit.geolite2.geonames.CountryFinder.java
/** * Read countries.//from w w w .ja va 2s . co m * * @param countriesLocationUrl the countries location url * @return the country finder */ private CountryFinder readCountries(String countriesLocationUrl) { ZipInputStream zipis = null; try { zipis = new ZipInputStream(new URL(countriesLocationUrl).openStream(), Charset.forName("UTF-8")); ZipEntry zipEntry = zipis.getNextEntry(); logger.info("reading " + zipEntry.getName()); if (crc == zipEntry.getCrc()) { logger.info("skipp, same CRC"); return this; } CsvParserSettings settings = new CsvParserSettings(); settings.setSkipEmptyLines(true); settings.trimValues(true); CsvFormat format = new CsvFormat(); format.setDelimiter('\t'); format.setLineSeparator("\n"); format.setCharToEscapeQuoteEscaping('\0'); format.setQuote('\0'); settings.setFormat(format); CsvParser parser = new CsvParser(settings); List<String[]> lines = parser.parseAll(new InputStreamReader(zipis, "UTF-8")); for (String[] entry : lines) { Country country = new Country(); country.setIso(entry[0]); country.setIso3(entry[1]); country.setName(entry[2]); country.setCapital(entry[3]); country.setContinent(entry[4]); country.setCurrencyCode(entry[5]); country.setCurrencyName(entry[6]); country.setPhone(entry[7]); country.setLanguage(StringUtils.substringBefore(entry[8], ",")); country.setGeonameId(NumberUtils.toInt(entry[9])); geonameMap.put(country.getGeonameId(), country); isoMap.put(country.getIso(), country); } } catch (Exception e) { throw new RuntimeException(e); } finally { try { zipis.close(); } catch (Exception e) { } ; } logger.info("loaded " + geonameMap.size() + " countries"); return this; }
From source file:io.gromit.geolite2.geonames.CityFinder.java
/** * Read cities./* w w w. j a va2 s . c o m*/ * * @param citiesLocationUrl the cities location url * @return the city finder */ private CityFinder readCities(String citiesLocationUrl) { ZipInputStream zipis = null; CsvParserSettings settings = new CsvParserSettings(); settings.setSkipEmptyLines(true); settings.trimValues(true); CsvFormat format = new CsvFormat(); format.setDelimiter('\t'); format.setLineSeparator("\n"); format.setComment('\0'); format.setCharToEscapeQuoteEscaping('\0'); format.setQuote('\0'); settings.setFormat(format); CsvParser parser = new CsvParser(settings); try { zipis = new ZipInputStream(new URL(citiesLocationUrl).openStream(), Charset.forName("UTF-8")); ZipEntry zipEntry = zipis.getNextEntry(); logger.info("reading " + zipEntry.getName()); if (crc == zipEntry.getCrc()) { logger.info("skipp, same CRC"); return this; } RTree<City, Geometry> rtreeRead = RTree.create(); List<String[]> lines = parser.parseAll(new InputStreamReader(zipis, "UTF-8")); for (String[] entry : lines) { City city = new City(); city.setGeonameId(Integer.decode(entry[0])); city.setName(entry[1]); try { try { city.setLatitude(Double.valueOf(entry[2])); city.setLongitude(Double.valueOf(entry[3])); rtreeRead = rtreeRead.add(city, Geometries.pointGeographic(city.getLongitude(), city.getLatitude())); } catch (NumberFormatException | NullPointerException e) { } city.setCountryIsoCode(entry[4]); city.setSubdivisionOne(entry[5]); city.setSubdivisionTwo(entry[6]); city.setTimeZone(entry[7]); } catch (ArrayIndexOutOfBoundsException e) { } geonameMap.put(city.getGeonameId(), city); } this.rtree = rtreeRead; logger.info("loaded " + geonameMap.size() + " cities"); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { try { zipis.close(); } catch (Exception e) { } ; } return this; }
From source file:io.gromit.geolite2.geonames.SubdivisionFinder.java
/** * Read countries.//w w w . j a va 2s. c om * * @param subdivisionOneLocationUrl the subdivision one location url * @return the time zone finder */ public SubdivisionFinder readLevelOne(String subdivisionOneLocationUrl) { ZipInputStream zipis = null; try { zipis = new ZipInputStream(new URL(subdivisionOneLocationUrl).openStream(), Charset.forName("UTF-8")); ZipEntry zipEntry = zipis.getNextEntry(); logger.info("reading " + zipEntry.getName()); if (crc1 == zipEntry.getCrc()) { logger.info("skipp, same CRC"); return this; } CsvParserSettings settings = new CsvParserSettings(); settings.setSkipEmptyLines(true); settings.trimValues(true); CsvFormat format = new CsvFormat(); format.setDelimiter('\t'); format.setLineSeparator("\n"); format.setCharToEscapeQuoteEscaping('\0'); format.setQuote('\0'); settings.setFormat(format); CsvParser parser = new CsvParser(settings); List<String[]> lines = parser.parseAll(new InputStreamReader(zipis, "UTF-8")); for (String[] entry : lines) { Subdivision subdivision = new Subdivision(); subdivision.setId(entry[0]); subdivision.setName(entry[1]); subdivision.setGeonameId(NumberUtils.toInt(entry[2])); idOneMap.put(subdivision.getId(), subdivision); geonameIdMap.put(subdivision.getGeonameId(), subdivision); } logger.info("loaded " + lines.size() + " subdivisions level 1"); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { try { zipis.close(); } catch (Exception e) { } ; } return this; }