List of usage examples for org.apache.commons.compress.archivers.jar JarArchiveEntry JarArchiveEntry
public JarArchiveEntry(JarEntry entry) throws ZipException
From source file:org.springframework.boot.loader.tools.JarWriter.java
/** * Write a nested library./* w ww . ja v a 2 s.c om*/ * @param destination the destination of the library * @param library the library * @throws IOException if the write fails */ public void writeNestedLibrary(String destination, Library library) throws IOException { File file = library.getFile(); JarArchiveEntry entry = new JarArchiveEntry(destination + library.getName()); entry.setTime(getNestedLibraryTime(file)); new CrcAndSize(file).setupStoredEntry(entry); writeEntry(entry, new InputStreamEntryWriter(new FileInputStream(file), true), new LibraryUnpackHandler(library)); }
From source file:org.springframework.boot.loader.tools.JarWriter.java
/** * Write the required spring-boot-loader classes to the JAR. * @param loaderJarResourceName the name of the resource containing the loader classes * to be written//from ww w . j ava 2 s . c om * @throws IOException if the classes cannot be written */ @Override public void writeLoaderClasses(String loaderJarResourceName) throws IOException { URL loaderJar = getClass().getClassLoader().getResource(loaderJarResourceName); try (JarInputStream inputStream = new JarInputStream(new BufferedInputStream(loaderJar.openStream()))) { JarEntry entry; while ((entry = inputStream.getNextJarEntry()) != null) { if (entry.getName().endsWith(".class")) { writeEntry(new JarArchiveEntry(entry), new InputStreamEntryWriter(inputStream, false)); } } } }
From source file:org.springframework.boot.loader.tools.JarWriter.java
/** * Perform the actual write of a {@link JarEntry}. All other write methods delegate to * this one.//from w w w . java 2 s . c o m * @param entry the entry to write * @param entryWriter the entry writer or {@code null} if there is no content * @param unpackHandler handles possible unpacking for the entry * @throws IOException in case of I/O errors */ private void writeEntry(JarArchiveEntry entry, EntryWriter entryWriter, UnpackHandler unpackHandler) throws IOException { String parent = entry.getName(); if (parent.endsWith("/")) { parent = parent.substring(0, parent.length() - 1); entry.setUnixMode(UnixStat.DIR_FLAG | UnixStat.DEFAULT_DIR_PERM); } else { entry.setUnixMode(UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM); } if (parent.lastIndexOf('/') != -1) { parent = parent.substring(0, parent.lastIndexOf('/') + 1); if (!parent.isEmpty()) { writeEntry(new JarArchiveEntry(parent), null, unpackHandler); } } if (this.writtenEntries.add(entry.getName())) { entryWriter = addUnpackCommentIfNecessary(entry, entryWriter, unpackHandler); this.jarOutput.putArchiveEntry(entry); if (entryWriter != null) { entryWriter.write(this.jarOutput); } this.jarOutput.closeArchiveEntry(); } }