Search in sources :

Example 1 with TempFileProvider

use of org.jboss.vfs.TempFileProvider in project jersey by jersey.

the class VFSSchemeResourceFinderTest method testClassEnumeration.

/**
     * Test case for JERSEY-2197, JERSEY-2175.
     */
@Test
public void testClassEnumeration() throws Exception {
    // Count actual entries.
    int actualEntries = 0;
    try (JarFile jarFile = new JarFile(jaxRsApiPath)) {
        final Enumeration<JarEntry> entries = jarFile.entries();
        while (entries.hasMoreElements()) {
            final JarEntry entry = entries.nextElement();
            if (entry.getName().endsWith(".class")) {
                actualEntries++;
            }
        }
    }
    // Scan entries using VFS scanner.
    final VirtualFile mountDir = VFS.getChild("content");
    ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
    try (TempFileProvider provider = TempFileProvider.create("test", executor, false);
        Closeable mount = VFS.mountZip(VFS.getChild(jaxRsApiPath), mountDir, provider)) {
        ResourceFinder finder = new VfsSchemeResourceFinderFactory().create(new URI(mountDir.toURI().toString() + "/javax/ws/rs"), true);
        int scannedEntryCount = 0;
        while (finder.hasNext()) {
            // Fetch next entry.
            finder.next();
            try (InputStream classStream = finder.open()) {
                scannedEntryCount++;
            }
        }
        assertThat("Failed to enumerate all contents of javax.ws.rs-api.", scannedEntryCount, equalTo(actualEntries));
    } finally {
        executor.shutdownNow();
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceFinder(org.glassfish.jersey.server.ResourceFinder) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) InputStream(java.io.InputStream) Closeable(java.io.Closeable) TempFileProvider(org.jboss.vfs.TempFileProvider) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) URI(java.net.URI) Test(org.junit.Test)

Example 2 with TempFileProvider

use of org.jboss.vfs.TempFileProvider in project wildfly by wildfly.

the class JdrTestCase method recursiveMount.

public static List<Closeable> recursiveMount(VirtualFile file) throws IOException {
    TempFileProvider provider = TempFileProvider.create("test", Executors.newSingleThreadScheduledExecutor());
    ArrayList<Closeable> mounts = new ArrayList<Closeable>();
    if (!file.isDirectory() && file.getName().matches("^.*\\.([EeWwJj][Aa][Rr]|[Zz][Ii][Pp])$")) {
        mounts.add(VFS.mountZip(file, file, provider));
    }
    if (file.isDirectory()) {
        for (VirtualFile child : file.getChildren()) {
            mounts.addAll(recursiveMount(child));
        }
    }
    return mounts;
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) Closeable(java.io.Closeable) TempFileProvider(org.jboss.vfs.TempFileProvider) ArrayList(java.util.ArrayList)

Aggregations

Closeable (java.io.Closeable)2 TempFileProvider (org.jboss.vfs.TempFileProvider)2 VirtualFile (org.jboss.vfs.VirtualFile)2 InputStream (java.io.InputStream)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1 ResourceFinder (org.glassfish.jersey.server.ResourceFinder)1 Test (org.junit.Test)1