OSDN Git Service

2003-10-08 Michael Koch <konqueror@gmx.de>
[pf3gnuchains/gcc-fork.git] / libjava / gnu / java / net / protocol / gcjlib / Connection.java
1 // Connection.java - Implementation of URLConnection for gcjlib
2 // protocol.
3
4 /* Copyright (C) 2003  Free Software Foundation
5
6    This file is part of libgcj.
7
8 This software is copyrighted work licensed under the terms of the
9 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
10 details.  */
11
12 package gnu.java.net.protocol.gcjlib;
13
14 import java.io.InputStream;
15 import java.io.IOException;
16 import java.net.MalformedURLException;
17 import java.net.URL;
18 import java.net.URLConnection;
19 import gnu.gcj.Core;
20 import gnu.gcj.runtime.SharedLibHelper;
21 import gnu.java.net.protocol.core.CoreInputStream;
22
23 /**
24  * @author Tom Tromey <tromey@redhat.com>
25  * @date January 10, 2003
26  */
27 class Connection extends URLConnection
28 {
29   String solib;
30   String name;
31   Core core;
32
33   public Connection (URL url) throws MalformedURLException
34   {
35     super (url);
36     int index = url.getFile().indexOf ("!/");
37     
38     if (index == -1)
39       throw new MalformedURLException ("couldn't find !/ in gcjlib URL");
40
41     name = url.getFile().substring (index + 2);
42     solib = url.getFile().substring (0, index);
43   }
44
45   public void connect() throws IOException
46   {
47     if (core != null)
48       return;
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);
52     if (helper == null)
53       throw new IOException("library not loaded: " + solib);
54     core = helper.findCore(name);
55     if (core == null)
56       throw new IOException("couldn't find core object: " + name);
57   }
58
59   public InputStream getInputStream() throws IOException
60   {
61     connect();
62     return new CoreInputStream(core);
63   }
64 }