00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 package org.knopflerfish.framework;
00036
00037 import java.io.*;
00038 import java.net.*;
00039
00040
00046 class BundleURLConnection extends URLConnection {
00047
00048 private InputStream is = null;
00049
00050 private Bundles bundles;
00051
00052 BundleURLConnection(URL u, Bundles b) {
00053 super(u);
00054 bundles = b;
00055 }
00056
00057 public void connect() throws IOException {
00058 if (!connected) {
00059 BundleImpl b = null;
00060 long ai = -1;
00061 long fi = -1;
00062 try {
00063 String s = url.getHost();
00064 int i = s.indexOf('_');
00065 if (i >= 0) {
00066 fi = Long.parseLong(s.substring(i+1));
00067 s = s.substring(0,i);
00068 }
00069 i = s.indexOf('.');
00070 if (i >= 0) {
00071 ai = Long.parseLong(s.substring(i+1));
00072 s = s.substring(0,i);
00073 }
00074 b = (BundleImpl)bundles.getBundle(Long.parseLong(s));
00075 } catch (NumberFormatException _ignore) { }
00076 if (b != null) {
00077 BundleArchive a = b.getBundleArchive(ai, fi);
00078 if (a != null) {
00079 is = a.getInputStream(url.getFile(), url.getPort());
00080 }
00081 }
00082 if (is != null) {
00083 connected = true;
00084 } else {
00085 throw new IOException("URL not found");
00086 }
00087 }
00088 }
00089
00090 public InputStream getInputStream() {
00091 try {
00092 connect();
00093 } catch (IOException ignore) {
00094 }
00095 return is;
00096 }
00097 }