Search in sources :

Example 41 with JarEntry

use of java.util.jar.JarEntry in project error-prone by google.

the class FunctionalInterfaceClashTest method addClassToJar.

static void addClassToJar(JarOutputStream jos, Class<?> clazz) throws IOException {
    String entryPath = clazz.getName().replace('.', '/') + ".class";
    try (InputStream is = clazz.getClassLoader().getResourceAsStream(entryPath)) {
        jos.putNextEntry(new JarEntry(entryPath));
        ByteStreams.copy(is, jos);
    }
}
Also used : InputStream(java.io.InputStream) JarEntry(java.util.jar.JarEntry)

Example 42 with JarEntry

use of java.util.jar.JarEntry in project error-prone by google.

the class ReferenceEqualityTest method addClassToJar.

static void addClassToJar(JarOutputStream jos, Class<?> clazz) throws IOException {
    String entryPath = clazz.getName().replace('.', '/') + ".class";
    try (InputStream is = clazz.getClassLoader().getResourceAsStream(entryPath)) {
        jos.putNextEntry(new JarEntry(entryPath));
        ByteStreams.copy(is, jos);
    }
}
Also used : InputStream(java.io.InputStream) JarEntry(java.util.jar.JarEntry)

Example 43 with JarEntry

use of java.util.jar.JarEntry in project spring-boot by spring-projects.

the class BootRunApplicationLauncher method explodeArchive.

private void explodeArchive(File archive) throws IOException {
    FileSystemUtils.deleteRecursively(this.exploded);
    JarFile jarFile = new JarFile(archive);
    Enumeration<JarEntry> entries = jarFile.entries();
    while (entries.hasMoreElements()) {
        JarEntry jarEntry = entries.nextElement();
        File extracted = new File(this.exploded, jarEntry.getName());
        if (jarEntry.isDirectory()) {
            extracted.mkdirs();
        } else {
            FileOutputStream extractedOutputStream = new FileOutputStream(extracted);
            StreamUtils.copy(jarFile.getInputStream(jarEntry), extractedOutputStream);
            extractedOutputStream.close();
        }
    }
    jarFile.close();
}
Also used : FileOutputStream(java.io.FileOutputStream) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 44 with JarEntry

use of java.util.jar.JarEntry in project spring-boot by spring-projects.

the class JarWriter method writeEntries.

void writeEntries(JarFile jarFile, EntryTransformer entryTransformer) throws IOException {
    Enumeration<JarEntry> entries = jarFile.entries();
    while (entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();
        ZipHeaderPeekInputStream inputStream = new ZipHeaderPeekInputStream(jarFile.getInputStream(entry));
        try {
            if (inputStream.hasZipHeader() && entry.getMethod() != ZipEntry.STORED) {
                new CrcAndSize(inputStream).setupStoredEntry(entry);
                inputStream.close();
                inputStream = new ZipHeaderPeekInputStream(jarFile.getInputStream(entry));
            }
            EntryWriter entryWriter = new InputStreamEntryWriter(inputStream, true);
            JarEntry transformedEntry = entryTransformer.transform(entry);
            if (transformedEntry != null) {
                writeEntry(transformedEntry, entryWriter);
            }
        } finally {
            inputStream.close();
        }
    }
}
Also used : JarEntry(java.util.jar.JarEntry)

Example 45 with JarEntry

use of java.util.jar.JarEntry in project spring-boot by spring-projects.

the class JarWriter method writeLoaderClasses.

/**
	 * Write the required spring-boot-loader classes to the JAR.
	 * @param loaderJarResourceName the name of the resource containing the loader classes
	 * to be written
	 * @throws IOException if the classes cannot be written
	 */
@Override
public void writeLoaderClasses(String loaderJarResourceName) throws IOException {
    URL loaderJar = getClass().getClassLoader().getResource(loaderJarResourceName);
    JarInputStream inputStream = new JarInputStream(new BufferedInputStream(loaderJar.openStream()));
    JarEntry entry;
    while ((entry = inputStream.getNextJarEntry()) != null) {
        if (entry.getName().endsWith(".class")) {
            writeEntry(entry, new InputStreamEntryWriter(inputStream, false));
        }
    }
    inputStream.close();
}
Also used : JarInputStream(java.util.jar.JarInputStream) BufferedInputStream(java.io.BufferedInputStream) JarEntry(java.util.jar.JarEntry) URL(java.net.URL)

Aggregations

JarEntry (java.util.jar.JarEntry)594 JarFile (java.util.jar.JarFile)290 File (java.io.File)217 IOException (java.io.IOException)187 InputStream (java.io.InputStream)134 JarOutputStream (java.util.jar.JarOutputStream)112 FileOutputStream (java.io.FileOutputStream)109 FileInputStream (java.io.FileInputStream)92 URL (java.net.URL)87 JarInputStream (java.util.jar.JarInputStream)87 ArrayList (java.util.ArrayList)67 Manifest (java.util.jar.Manifest)58 JarURLConnection (java.net.JarURLConnection)53 Test (org.junit.Test)39 HashSet (java.util.HashSet)31 ZipEntry (java.util.zip.ZipEntry)31 ZipFile (java.util.zip.ZipFile)30 OutputStream (java.io.OutputStream)29 BufferedInputStream (java.io.BufferedInputStream)26 Enumeration (java.util.Enumeration)26