List of usage examples for java.util.zip ZipEntry getComment
public String getComment()
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.getComment()); }//from w ww .j ava 2 s. co m }
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); }// www. ja v a 2 s.co m if (ze.isDirectory()) { System.out.println(name + " is a directory"); } } }
From source file:MainClass.java
public static void main(String[] args) { try {// ww w .j a v a2 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(); 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 va2s .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
public static String getEntryComment(ZipEntry entry) { try {//from w ww . j a va 2 s .co m return new String(entry.getComment().getBytes("GB2312"), "8859_1"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String getEntryComment(ZipEntry entry) throws UnsupportedEncodingException { return new String(entry.getComment().getBytes("GB2312"), "8859_1"); }
From source file:com.diffplug.gradle.ZipMisc.java
/** * Modifies only the specified entries in a zip file. * * @param input a source from a zip file * @param output an output to a zip file * @param toModify a map from path to an input stream for the entries you'd like to change * @param toOmit a set of entries you'd like to leave out of the zip * @throws IOException// www . ja v a 2 s . c o m */ public static void modify(ByteSource input, ByteSink output, Map<String, Function<byte[], byte[]>> toModify, Predicate<String> toOmit) throws IOException { try (ZipInputStream zipInput = new ZipInputStream(input.openBufferedStream()); ZipOutputStream zipOutput = new ZipOutputStream(output.openBufferedStream())) { while (true) { // read the next entry ZipEntry entry = zipInput.getNextEntry(); if (entry == null) { break; } Function<byte[], byte[]> replacement = toModify.get(entry.getName()); if (replacement != null) { byte[] clean = ByteStreams.toByteArray(zipInput); byte[] modified = replacement.apply(clean); // if it's the entry being modified, enter the modified stuff try (InputStream replacementStream = new ByteArrayInputStream(modified)) { ZipEntry newEntry = new ZipEntry(entry.getName()); newEntry.setComment(entry.getComment()); newEntry.setExtra(entry.getExtra()); newEntry.setMethod(entry.getMethod()); newEntry.setTime(entry.getTime()); zipOutput.putNextEntry(newEntry); copy(replacementStream, zipOutput); } } else if (!toOmit.test(entry.getName())) { // if it isn't being modified, just copy the file stream straight-up ZipEntry newEntry = new ZipEntry(entry); newEntry.setCompressedSize(-1); zipOutput.putNextEntry(newEntry); copy(zipInput, zipOutput); } // close the entries zipInput.closeEntry(); zipOutput.closeEntry(); } } }
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 *///from w w w . 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:org.atombeat.xquery.functions.util.GetZipEntries.java
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {//w w w . j a v a2 s . c o m String path = args[0].getStringValue(); ZipFile zf = new ZipFile(path); log.debug(zf.getName()); log.debug(zf.size()); log.debug(zf.hashCode()); ZipEntry e; Enumeration<? extends ZipEntry> entries = zf.entries(); ValueSequence s = new ValueSequence(); for (int i = 0; entries.hasMoreElements(); i++) { log.debug(i); e = entries.nextElement(); log.debug(e.getName()); log.debug(e.getComment()); log.debug(e.isDirectory()); log.debug(e.getCompressedSize()); log.debug(e.getCrc()); log.debug(e.getMethod()); log.debug(e.getSize()); log.debug(e.getTime()); if (!e.isDirectory()) s.add(new StringValue(e.getName())); } return s; } catch (Exception e) { throw new XPathException("error processing zip file: " + e.getLocalizedMessage(), e); } }
From source file:org.broad.igv.feature.genome.GenomeManager.java
/** * Rewrite the {@link Globals#GENOME_ARCHIVE_SEQUENCE_FILE_LOCATION_KEY} property to equal * the specified {@code newSequencePath}. Works by creating a temp file and renaming * * @param targetFile A .genome file, in zip format * @param newSequencePath/*from ww w .j a va 2s .c o m*/ * @return boolean indicating success or failure. * @throws IOException */ static boolean rewriteSequenceLocation(File targetFile, String newSequencePath) throws IOException { ZipFile targetZipFile = new ZipFile(targetFile); boolean success = false; File tmpZipFile = File.createTempFile("tmpGenome", ".zip"); ZipEntry propEntry = targetZipFile.getEntry(Globals.GENOME_ARCHIVE_PROPERTY_FILE_NAME); InputStream propertyInputStream = null; ZipOutputStream zipOutputStream = null; Properties inputProperties = new Properties(); try { propertyInputStream = targetZipFile.getInputStream(propEntry); BufferedReader reader = new BufferedReader(new InputStreamReader(propertyInputStream)); //Copy over property.txt, only replacing a few properties inputProperties.load(reader); inputProperties.put(Globals.GENOME_ARCHIVE_SEQUENCE_FILE_LOCATION_KEY, newSequencePath); inputProperties.put(Globals.GENOME_ARCHIVE_CUSTOM_SEQUENCE_LOCATION_KEY, Boolean.TRUE.toString()); ByteArrayOutputStream propertyBytes = new ByteArrayOutputStream(); PrintWriter propertyFileWriter = new PrintWriter(new OutputStreamWriter(propertyBytes)); inputProperties.store(propertyFileWriter, null); propertyFileWriter.flush(); byte[] newPropertyBytes = propertyBytes.toByteArray(); Enumeration<? extends ZipEntry> entries = targetZipFile.entries(); zipOutputStream = new ZipOutputStream(new FileOutputStream(tmpZipFile)); while (entries.hasMoreElements()) { ZipEntry curEntry = entries.nextElement(); ZipEntry writeEntry = null; if (curEntry.getName().equals(Globals.GENOME_ARCHIVE_PROPERTY_FILE_NAME)) { writeEntry = new ZipEntry(Globals.GENOME_ARCHIVE_PROPERTY_FILE_NAME); writeEntry.setSize(newPropertyBytes.length); zipOutputStream.putNextEntry(writeEntry); zipOutputStream.write(newPropertyBytes); continue; } else { //Because the compressed size can vary, //we generate a new ZipEntry and copy some attributes writeEntry = new ZipEntry(curEntry.getName()); writeEntry.setSize(curEntry.getSize()); writeEntry.setComment(curEntry.getComment()); writeEntry.setTime(curEntry.getTime()); } zipOutputStream.putNextEntry(writeEntry); InputStream tmpIS = null; try { tmpIS = targetZipFile.getInputStream(writeEntry); int bytes = IOUtils.copy(tmpIS, zipOutputStream); log.debug(bytes + " bytes written to " + targetFile); } finally { if (tmpIS != null) tmpIS.close(); } } } catch (Exception e) { tmpZipFile.delete(); throw new RuntimeException(e.getMessage(), e); } finally { if (propertyInputStream != null) propertyInputStream.close(); if (zipOutputStream != null) { zipOutputStream.flush(); zipOutputStream.finish(); zipOutputStream.close(); } zipOutputStream = null; System.gc(); success = true; } //This is a hack. I don't know why it's necessary, //but for some reason the output zip file seems to be corrupt //at least when called from GenomeManager.refreshArchive try { Thread.sleep(1500); } catch (InterruptedException e) { // } //Rename tmp file if (success) { targetFile.delete(); FileUtils.copyFile(tmpZipFile, targetFile); success = targetFile.exists(); tmpZipFile.delete(); } return success; }