List of usage examples for java.util.jar JarEntry getComment
public String getComment()
From source file:MainClass.java
public static void main(String[] args) throws IOException { JarFile jf = new JarFile(args[0]); Enumeration e = jf.entries(); while (e.hasMoreElements()) { JarEntry je = (JarEntry) e.nextElement(); String name = je.getName(); long crc = je.getCrc(); System.out.println("Its CRC is " + crc); String comment = je.getComment(); if (comment != null && !comment.equals("")) { System.out.println(comment); }/* ww w . j a v a 2 s. c o m*/ if (je.isDirectory()) { System.out.println(name + " is a directory"); } } }
From source file:Main.java
public static void main(String[] args) throws IOException { JarFile jf = new JarFile("a.jar"); Enumeration e = jf.entries(); while (e.hasMoreElements()) { JarEntry je = (JarEntry) e.nextElement(); System.out.println(je.getName()); long uncompressedSize = je.getSize(); long compressedSize = je.getCompressedSize(); long crc = je.getCrc(); int method = je.getMethod(); String comment = je.getComment(); System.out.println(new Date(je.getTime())); System.out.println("from " + uncompressedSize + " bytes to " + compressedSize); if (method == ZipEntry.STORED) { System.out.println("ZipEntry.STORED"); } else if (method == ZipEntry.DEFLATED) { System.out.println(ZipEntry.DEFLATED); }/* w ww. j a v a2s. co m*/ System.out.println("Its CRC is " + crc); System.out.println(comment); System.out.println(je.isDirectory()); Attributes a = je.getAttributes(); if (a != null) { Object[] nameValuePairs = a.entrySet().toArray(); for (int j = 0; j < nameValuePairs.length; j++) { System.out.println(nameValuePairs[j]); } } System.out.println(); } }
From source file:org.apache.pluto.util.assemble.io.JarStreamingAssembly.java
private static JarEntry smartClone(JarEntry originalJarEntry) { final JarEntry newJarEntry = new JarEntry(originalJarEntry.getName()); newJarEntry.setComment(originalJarEntry.getComment()); newJarEntry.setExtra(originalJarEntry.getExtra()); newJarEntry.setMethod(originalJarEntry.getMethod()); newJarEntry.setTime(originalJarEntry.getTime()); //Must set size and CRC for STORED entries if (newJarEntry.getMethod() == ZipEntry.STORED) { newJarEntry.setSize(originalJarEntry.getSize()); newJarEntry.setCrc(originalJarEntry.getCrc()); }/*w ww. ja v a2 s .c o m*/ return newJarEntry; }
From source file:org.apache.sling.maven.bundlesupport.AbstractBundleDeployMojo.java
/** * Change the version in jar//from w w w .j av a 2 s .c om * * @param newVersion * @param file * @return * @throws MojoExecutionException */ protected File changeVersion(File file, String oldVersion, String newVersion) throws MojoExecutionException { String fileName = file.getName(); int pos = fileName.indexOf(oldVersion); fileName = fileName.substring(0, pos) + newVersion + fileName.substring(pos + oldVersion.length()); JarInputStream jis = null; JarOutputStream jos; OutputStream out = null; JarFile sourceJar = null; try { // now create a temporary file and update the version sourceJar = new JarFile(file); final Manifest manifest = sourceJar.getManifest(); manifest.getMainAttributes().putValue("Bundle-Version", newVersion); jis = new JarInputStream(new FileInputStream(file)); final File destJar = new File(file.getParentFile(), fileName); out = new FileOutputStream(destJar); jos = new JarOutputStream(out, manifest); jos.setMethod(JarOutputStream.DEFLATED); jos.setLevel(Deflater.BEST_COMPRESSION); JarEntry entryIn = jis.getNextJarEntry(); while (entryIn != null) { JarEntry entryOut = new JarEntry(entryIn.getName()); entryOut.setTime(entryIn.getTime()); entryOut.setComment(entryIn.getComment()); jos.putNextEntry(entryOut); if (!entryIn.isDirectory()) { IOUtils.copy(jis, jos); } jos.closeEntry(); jis.closeEntry(); entryIn = jis.getNextJarEntry(); } // close the JAR file now to force writing jos.close(); return destJar; } catch (IOException ioe) { throw new MojoExecutionException("Unable to update version in jar file.", ioe); } finally { if (sourceJar != null) { try { sourceJar.close(); } catch (IOException ex) { // close } } IOUtils.closeQuietly(jis); IOUtils.closeQuietly(out); } }
From source file:org.apache.sling.osgi.obr.Repository.java
File spoolModified(InputStream ins) throws IOException { JarInputStream jis = new JarInputStream(ins); // immediately handle the manifest JarOutputStream jos;/*from w w w .jav a 2 s .c o m*/ Manifest manifest = jis.getManifest(); if (manifest == null) { throw new IOException("Missing Manifest !"); } String symbolicName = manifest.getMainAttributes().getValue("Bundle-SymbolicName"); if (symbolicName == null || symbolicName.length() == 0) { throw new IOException("Missing Symbolic Name in Manifest !"); } String version = manifest.getMainAttributes().getValue("Bundle-Version"); Version v = Version.parseVersion(version); if (v.getQualifier().indexOf("SNAPSHOT") >= 0) { String tStamp; synchronized (DATE_FORMAT) { tStamp = DATE_FORMAT.format(new Date()); } version = v.getMajor() + "." + v.getMinor() + "." + v.getMicro() + "." + v.getQualifier().replaceAll("SNAPSHOT", tStamp); manifest.getMainAttributes().putValue("Bundle-Version", version); } File bundle = new File(this.repoLocation, symbolicName + "-" + v + ".jar"); OutputStream out = null; try { out = new FileOutputStream(bundle); jos = new JarOutputStream(out, manifest); jos.setMethod(JarOutputStream.DEFLATED); jos.setLevel(Deflater.BEST_COMPRESSION); JarEntry entryIn = jis.getNextJarEntry(); while (entryIn != null) { JarEntry entryOut = new JarEntry(entryIn.getName()); entryOut.setTime(entryIn.getTime()); entryOut.setComment(entryIn.getComment()); jos.putNextEntry(entryOut); if (!entryIn.isDirectory()) { spool(jis, jos); } jos.closeEntry(); jis.closeEntry(); entryIn = jis.getNextJarEntry(); } // close the JAR file now to force writing jos.close(); } finally { IOUtils.closeQuietly(out); } return bundle; }
From source file:org.jahia.modules.serversettings.portlets.BasePortletHelper.java
static JarEntry cloneEntry(JarEntry originalJarEntry) { final JarEntry newJarEntry = new JarEntry(originalJarEntry.getName()); newJarEntry.setComment(originalJarEntry.getComment()); newJarEntry.setExtra(originalJarEntry.getExtra()); newJarEntry.setMethod(originalJarEntry.getMethod()); newJarEntry.setTime(originalJarEntry.getTime()); // Must set size and CRC for STORED entries if (newJarEntry.getMethod() == ZipEntry.STORED) { newJarEntry.setSize(originalJarEntry.getSize()); newJarEntry.setCrc(originalJarEntry.getCrc()); }/*from ww w.ja v a 2s . c om*/ return newJarEntry; }
From source file:org.springframework.boot.loader.tools.RepackagerTests.java
@Test public void libraries() throws Exception { TestJarFile libJar = new TestJarFile(this.temporaryFolder); libJar.addClass("a/b/C.class", ClassWithoutMainMethod.class, JAN_1_1985); File libJarFile = libJar.getFile(); File libJarFileToUnpack = libJar.getFile(); File libNonJarFile = this.temporaryFolder.newFile(); FileCopyUtils.copy(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }, libNonJarFile); this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class); this.testJarFile.addFile("BOOT-INF/lib/" + libJarFileToUnpack.getName(), libJarFileToUnpack); File file = this.testJarFile.getFile(); libJarFile.setLastModified(JAN_1_1980); Repackager repackager = new Repackager(file); repackager.repackage((callback) -> { callback.library(new Library(libJarFile, LibraryScope.COMPILE)); callback.library(new Library(libJarFileToUnpack, LibraryScope.COMPILE, true)); callback.library(new Library(libNonJarFile, LibraryScope.COMPILE)); });/*from w w w . j a va 2 s. c om*/ assertThat(hasEntry(file, "BOOT-INF/lib/" + libJarFile.getName())).isTrue(); assertThat(hasEntry(file, "BOOT-INF/lib/" + libJarFileToUnpack.getName())).isTrue(); assertThat(hasEntry(file, "BOOT-INF/lib/" + libNonJarFile.getName())).isFalse(); JarEntry entry = getEntry(file, "BOOT-INF/lib/" + libJarFile.getName()); assertThat(entry.getTime()).isEqualTo(JAN_1_1985); entry = getEntry(file, "BOOT-INF/lib/" + libJarFileToUnpack.getName()); assertThat(entry.getComment()).startsWith("UNPACK:"); assertThat(entry.getComment().length()).isEqualTo(47); }
From source file:org.springframework.boot.loader.tools.RepackagerTests.java
@Test public void existingEntryThatMatchesUnpackLibraryIsMarkedForUnpack() throws IOException { File library = createLibrary(); this.testJarFile.addClass("WEB-INF/classes/com/example/Application.class", ClassWithMainMethod.class); this.testJarFile.addFile("WEB-INF/lib/" + library.getName(), library); File source = this.testJarFile.getFile("war"); File dest = this.temporaryFolder.newFile("dest.war"); Repackager repackager = new Repackager(source); repackager.setLayout(new Layouts.War()); repackager.repackage(dest,/*from w w w . jav a 2 s. c o m*/ (callback) -> callback.library(new Library(library, LibraryScope.COMPILE, true))); assertThat(getEntryNames(dest)).containsSubsequence("org/springframework/boot/loader/", "WEB-INF/classes/com/example/Application.class", "WEB-INF/lib/" + library.getName()); JarEntry unpackLibrary = getEntry(dest, "WEB-INF/lib/" + library.getName()); assertThat(unpackLibrary.getComment()).startsWith("UNPACK:"); }