1 package org.sapia.clazzy; 2 3 import java.io.File ; 4 import java.io.IOException ; 5 import java.io.InputStream ; 6 import java.io.OutputStream ; 7 import java.net.URL ; 8 import java.net.URLConnection ; 9 10 11 39 public class ClazzyURLConnection extends URLConnection { 40 41 42 public ClazzyURLConnection(URL url) { 43 super(url); 44 } 45 46 49 public void connect() throws IOException { 50 } 51 52 55 public InputStream getInputStream() throws IOException { 56 String path = getURL().toExternalForm(); 57 int i = path.indexOf("?"); 58 if(i < 0){ 59 throw new IOException ("URL should have format: protocol://path_to_jar?file_name. Got: " + path); 60 } 61 JarClassLoader loader = new JarClassLoader(new File (getURL().getPath())); 62 try{ 63 return loader.findResourceAsStream(path.substring(i+1)); 64 }finally{ 65 loader.close(); 66 } 67 } 68 69 72 public OutputStream getOutputStream() throws IOException { 73 return super.getOutputStream(); 74 } 75 76 79 public boolean getAllowUserInteraction() { 80 return false; 81 } 82 83 } 84 | Popular Tags |