OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [gnu/] [java/] [net/] [protocol/] [gcjlib/] [Connection.java] - Blame information for rev 756

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 756 jeremybenn
// 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
 
65
  public String getHeaderField(String field)
66
  {
67
    try
68
      {
69
        if (!connected)
70
          connect();
71
 
72
        if (field.equals("content-type"))
73
          return guessContentTypeFromName(name);
74
        else if (field.equals("content-length"))
75
          return Long.toString(core.length);
76
      }
77
    catch (IOException e)
78
      {
79
        // Fall through.
80
      }
81
    return null;
82
  }
83
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.