Author: jboynes
Date: Mon Apr  6 16:20:43 2015
New Revision: 1671574

URL: http://svn.apache.org/r1671574
Log:
Simplify URL connection

Modified:
    tomcat/sandbox/niofs/tst/niofs/ClassLoaderTest.java

Modified: tomcat/sandbox/niofs/tst/niofs/ClassLoaderTest.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/niofs/tst/niofs/ClassLoaderTest.java?rev=1671574&r1=1671573&r2=1671574&view=diff
==============================================================================
--- tomcat/sandbox/niofs/tst/niofs/ClassLoaderTest.java (original)
+++ tomcat/sandbox/niofs/tst/niofs/ClassLoaderTest.java Mon Apr  6 16:20:43 2015
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.net.URLConnection;
@@ -31,6 +32,7 @@ import java.nio.file.FileSystem;
 import java.nio.file.FileSystems;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Collections;
 import java.util.Set;
 import java.util.stream.Collectors;
@@ -46,6 +48,8 @@ import static org.junit.Assert.assertEqu
  *
  */
 public class ClassLoaderTest {
+    static int count;
+
     @BeforeClass
     public static void initURLHandler() {
         // Need this to even construct URLs.
@@ -55,9 +59,13 @@ public class ClassLoaderTest {
                     return new URLStreamHandler() {
                         @Override
                         protected URLConnection openConnection(URL u) throws 
IOException {
-                            URI archive = URI.create("archive://" + 
u.getHost());
-                            FileSystem fileSystem = 
FileSystems.getFileSystem(archive);
-                            Path path = fileSystem.getPath(u.getPath());
+                            URI uri;
+                            try {
+                                uri = u.toURI();
+                            } catch (URISyntaxException e) {
+                                throw new IOException(e);
+                            }
+                            Path path = Paths.get(uri);
                             return new URLConnection(u) {
                                 @Override
                                 public void connect() throws IOException {
@@ -65,6 +73,7 @@ public class ClassLoaderTest {
 
                                 @Override
                                 public InputStream getInputStream() throws 
IOException {
+                                    count++;
                                     return Files.newInputStream(path);
                                 }
                             };
@@ -127,12 +136,15 @@ public class ClassLoaderTest {
                     .map(line -> line.split(" ")[1])
                     .collect(Collectors.toSet());
         }
+        int opens = -count;
         long time = -System.nanoTime();
         Set<?> urls = paths.stream()
                 .map(classLoader::getResource)
                 .collect(Collectors.toSet());
         time += System.nanoTime();
+        opens += count;
         System.out.printf("Found %d resources in %dms\n", urls.size(), time / 
1000000);
+        System.out.printf("%d opens\n", opens);
         assertEquals(paths.size(), urls.size());
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to