1 19 20 package org.netbeans.core.startup; 21 22 import java.io.IOException ; 23 import java.net.URL ; 24 import java.net.URLConnection ; 25 import java.net.URLStreamHandler ; 26 import java.net.URLStreamHandlerFactory ; 27 28 33 public class NbURLStreamHandlerFactoryWhenSetTest extends NbURLStreamHandlerFactoryTest { 34 static { 35 java.net.URL.setURLStreamHandlerFactory(new SomeURLStreamHandFact()); 37 } 38 39 40 public NbURLStreamHandlerFactoryWhenSetTest(String s) { 41 super(s); 42 } 43 44 public void testDefaultImpleDelegatesToPreviousURLFactory() throws Exception { 45 URL u = new URL ("jarda://ClassLoaderCacheContent.properties/"); 46 47 byte[] arr = new byte[100000]; 48 int len = u.openStream().read(arr); 49 if (len < 50000) { 50 fail("Should be able to read at least 50KB: " + len); 51 } 52 } 53 54 private static class SomeURLStreamHandFact implements URLStreamHandlerFactory { 55 56 57 public URLStreamHandler createURLStreamHandler(String protocol) { 58 if ("jarda".equals(protocol)) { 59 return new H(); 60 } 61 return null; 62 } 63 } 64 65 private static class H extends URLStreamHandler { 66 protected URLConnection openConnection(URL u) throws IOException { 67 return getClass().getResource(u.getHost()).openConnection(); 68 } 69 } 70 } 71 | Popular Tags |