Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / gnu / java / net / protocol / gcjlib / Connection.java
blob4e6e462f26eab5d67e6233257d73d892a1e46b28
1 // Connection.java - Implementation of URLConnection for gcjlib
2 // protocol.
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
10 details. */
12 package gnu.java.net.protocol.gcjlib;
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;
23 /**
24 * @author Tom Tromey <tromey@redhat.com>
25 * @date January 10, 2003
27 class Connection extends URLConnection
29 String solib;
30 String name;
31 Core core;
33 public Connection (URL url) throws MalformedURLException
35 super (url);
36 int index = url.getFile().indexOf ("!/");
38 if (index == -1)
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
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);
59 public InputStream getInputStream() throws IOException
61 connect();
62 return new CoreInputStream(core);
65 public String getHeaderField(String field)
67 try
69 if (!connected)
70 connect();
72 if (field.equals("content-type"))
73 return guessContentTypeFromName(name);
74 else if (field.equals("content-length"))
75 return Long.toString(core.length);
77 catch (IOException e)
79 // Fall through.
81 return null;