1 // Connection.java - Implementation of URLConnection for gcjlib
4 /* Copyright (C) 2003 Free Software Foundation
6 This file is part of libgcj.
8 This software is copyrighted work licensed under the terms of the
9 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
12 package gnu
.java
.net
.protocol
.gcjlib
;
14 import java
.io
.InputStream
;
15 import java
.io
.IOException
;
16 import java
.net
.MalformedURLException
;
18 import java
.net
.URLConnection
;
20 import gnu
.gcj
.runtime
.SharedLibHelper
;
21 import gnu
.java
.net
.protocol
.core
.CoreInputStream
;
24 * @author Tom Tromey <tromey@redhat.com>
25 * @date January 10, 2003
27 class Connection
extends URLConnection
33 public Connection (URL url
) throws MalformedURLException
36 int index
= url
.getFile().indexOf ("!/");
39 throw new MalformedURLException ("couldn't find !/ in gcjlib URL");
41 name
= url
.getFile().substring (index
+ 2);
42 solib
= url
.getFile().substring (0, index
);
45 public void connect() throws IOException
49 // We can't create a new SharedLibHelper here, since we don't know
50 // what parent class loader to use.
51 SharedLibHelper helper
= SharedLibHelper
.findHelper(solib
);
53 throw new IOException("library not loaded: " + solib
);
54 core
= helper
.findCore(name
);
56 throw new IOException("couldn't find core object: " + name
);
59 public InputStream
getInputStream() throws IOException
62 return new CoreInputStream(core
);
65 public String
getHeaderField(String field
)
72 if (field
.equals("content-type"))
73 return guessContentTypeFromName(name
);
74 else if (field
.equals("content-length"))
75 return Long
.toString(core
.length
);