1 11 12 package org.eclipse.osgi.framework.internal.protocol.reference; 13 14 import java.io.*; 15 import java.net.URL ; 16 import java.net.URLConnection ; 17 import org.eclipse.osgi.framework.adaptor.FilePath; 18 import org.eclipse.osgi.framework.internal.core.FrameworkProperties; 19 import org.eclipse.osgi.framework.internal.core.ReferenceInputStream; 20 21 24 25 public class ReferenceURLConnection extends URLConnection { 26 protected URL reference; 27 28 protected ReferenceURLConnection(URL url) { 29 super(url); 30 } 31 32 public synchronized void connect() throws IOException { 33 if (!connected) { 34 File file = new File(url.getPath().substring(5)); 38 URL ref; 39 if (!file.isAbsolute()) { 40 String installPath = getInstallPath(); 41 if (installPath != null) 42 file = makeAbsolute(installPath, file); 43 } 44 ref = file.toURL(); 45 if (!file.exists()) 46 throw new FileNotFoundException(file.toString()); 47 reference = ref; 48 } 49 } 50 51 public boolean getDoInput() { 52 return true; 53 } 54 55 public boolean getDoOutput() { 56 return false; 57 } 58 59 public InputStream getInputStream() throws IOException { 60 if (!connected) { 61 connect(); 62 } 63 64 return new ReferenceInputStream(reference); 65 } 66 67 private String getInstallPath() { 68 String installURL = FrameworkProperties.getProperty("osgi.install.area"); if (installURL == null) 70 return null; 71 if (!installURL.startsWith("file:")) return null; 73 return installURL.substring(5); 75 } 76 77 private static File makeAbsolute(String base, File relative) { 78 if (relative.isAbsolute()) 79 return relative; 80 return new File(new FilePath(base + relative.getPath()).toString()); 81 } 82 } 83 | Popular Tags |