Search in sources :

Example 81 with JarInputStream

use of java.util.jar.JarInputStream in project drools by kiegroup.

the class VerifierMapBackedClassLoaderTest method testCheckResources.

@Test
public void testCheckResources() throws Exception {
    ArrayList<JarInputStream> jarInputStreams = new ArrayList<JarInputStream>();
    jarInputStreams.add(new JarInputStream(Verifier.class.getResourceAsStream("model.jar")));
    VerifierMapBackedClassLoader verifierMapBackedClassLoader = new VerifierMapBackedClassLoader(jarInputStreams);
    assertNotNull(verifierMapBackedClassLoader.getStore().containsKey("org.test.Person"));
    assertNotNull(verifierMapBackedClassLoader.getStore().containsKey("org.test.Rambo"));
    assertNotNull(verifierMapBackedClassLoader.getStore().containsKey("org.test.Pet"));
}
Also used : JarInputStream(java.util.jar.JarInputStream) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 82 with JarInputStream

use of java.util.jar.JarInputStream in project Payara by payara.

the class HTTPInputArchive method entryNames.

/**
 * Returns a collection containing the names of all entries in the
 * archive.
 *
 * @return
 * @throws IOException
 */
private synchronized Collection<String> entryNames() throws IOException {
    if (cachedEntryNames == null) {
        /*
             * We have to build the cache first.
             */
        cachedEntryNames = new ArrayList<String>();
        final JarInputStream jis = new JarInputStream(archiveURL.openStream());
        JarEntry entry;
        try {
            while ((entry = jis.getNextJarEntry()) != null) {
                cachedEntryNames.add(entry.getName());
            }
        } finally {
            jis.close();
        }
    }
    return cachedEntryNames;
}
Also used : JarInputStream(java.util.jar.JarInputStream) JarEntry(java.util.jar.JarEntry)

Example 83 with JarInputStream

use of java.util.jar.JarInputStream in project drools by kiegroup.

the class VerifierTest method testFactTypesFromJar.

@Test
public void testFactTypesFromJar() {
    VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
    // Check that the builder works.
    assertFalse(vBuilder.hasErrors());
    assertEquals(0, vBuilder.getErrors().size());
    Verifier verifier = vBuilder.newVerifier();
    try {
        JarInputStream jar = new JarInputStream(this.getClass().getResourceAsStream("model.jar"));
        verifier.addObjectModel(jar);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    verifier.addResourcesToVerify(new ClassPathResource("imports.drl", Verifier.class), ResourceType.DRL);
    assertFalse(verifier.hasErrors());
    assertEquals(0, verifier.getErrors().size());
    boolean works = verifier.fireAnalysis();
    assertTrue(works);
    VerifierReport result = verifier.getResult();
    Collection<ObjectType> objectTypes = result.getVerifierData().getAll(VerifierComponentType.OBJECT_TYPE);
    assertNotNull(objectTypes);
    assertEquals(3, objectTypes.size());
    Collection<Field> fields = result.getVerifierData().getAll(VerifierComponentType.FIELD);
    assertNotNull(fields);
    assertEquals(10, fields.size());
}
Also used : ObjectType(org.drools.verifier.components.ObjectType) Field(org.drools.verifier.components.Field) JarInputStream(java.util.jar.JarInputStream) VerifierReport(org.drools.verifier.data.VerifierReport) VerifierBuilder(org.drools.verifier.builder.VerifierBuilder) IOException(java.io.IOException) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Test(org.junit.Test)

Example 84 with JarInputStream

use of java.util.jar.JarInputStream in project Payara by payara.

the class Archivist method performOptionalPkgDependenciesCheck.

/**
 * Perform Optional packages dependencies checking on an archive
 */
public boolean performOptionalPkgDependenciesCheck(ReadableArchive archive) throws IOException {
    boolean dependenciesSatisfied = true;
    Manifest m = archive.getManifest();
    if (m != null) {
        dependenciesSatisfied = InstalledLibrariesResolver.resolveDependencies(m, archive.getURI().getSchemeSpecificPart());
    }
    // now check my libraries.
    Vector<String> libs = getLibraries(archive);
    if (libs != null) {
        for (String libUri : libs) {
            JarInputStream jis = null;
            try {
                jis = new JarInputStream(archive.getEntry(libUri));
                m = jis.getManifest();
                if (m != null) {
                    if (!InstalledLibrariesResolver.resolveDependencies(m, libUri)) {
                        dependenciesSatisfied = false;
                    }
                }
            } finally {
                if (jis != null)
                    jis.close();
            }
        }
    }
    return dependenciesSatisfied;
}
Also used : JarInputStream(java.util.jar.JarInputStream) Manifest(java.util.jar.Manifest)

Example 85 with JarInputStream

use of java.util.jar.JarInputStream in project Payara by payara.

the class JarFile method setupEntryCertificates.

void setupEntryCertificates(JarEntry entry) {
    // happening that often.
    try {
        JarInputStream inputStream = new JarInputStream(getData().getInputStream(ResourceAccess.ONCE));
        try {
            java.util.jar.JarEntry certEntry = inputStream.getNextJarEntry();
            while (certEntry != null) {
                inputStream.closeEntry();
                if (entry.getName().equals(certEntry.getName())) {
                    setCertificates(entry, certEntry);
                }
                setCertificates(getJarEntry(certEntry.getName()), certEntry);
                certEntry = inputStream.getNextJarEntry();
            }
        } finally {
            inputStream.close();
        }
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) IOException(java.io.IOException)

Aggregations

JarInputStream (java.util.jar.JarInputStream)185 JarEntry (java.util.jar.JarEntry)82 IOException (java.io.IOException)73 FileInputStream (java.io.FileInputStream)66 Manifest (java.util.jar.Manifest)56 File (java.io.File)48 InputStream (java.io.InputStream)45 ZipEntry (java.util.zip.ZipEntry)34 JarOutputStream (java.util.jar.JarOutputStream)29 Test (org.junit.Test)29 FileOutputStream (java.io.FileOutputStream)26 ByteArrayInputStream (java.io.ByteArrayInputStream)24 URL (java.net.URL)20 ArrayList (java.util.ArrayList)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 OutputStream (java.io.OutputStream)14 JarFile (java.util.jar.JarFile)14 BufferedInputStream (java.io.BufferedInputStream)11 Attributes (java.util.jar.Attributes)11 HashSet (java.util.HashSet)9