Merged gcj-eclipse branch to trunk.

From-SVN: r120621
This commit is contained in:
Tom Tromey
2007-01-09 19:58:05 +00:00
parent c648dedbde
commit 97b8365caf
17478 changed files with 606493 additions and 100744 deletions
+36 -7
View File
@@ -1,5 +1,5 @@
/* DatagramSocket.java -- A class to model UDP sockets
Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004, 2005
Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -180,7 +180,18 @@ public class DatagramSocket
if (factory != null)
impl = factory.createDatagramSocketImpl();
else
impl = new PlainDatagramSocketImpl();
{
try
{
impl = new PlainDatagramSocketImpl();
}
catch (IOException ioe)
{
SocketException se = new SocketException();
se.initCause(ioe);
throw se;
}
}
}
else
try
@@ -194,7 +205,16 @@ public class DatagramSocket
{
System.err.println("Could not instantiate class: java.net."
+ propVal + "DatagramSocketImpl");
impl = new PlainDatagramSocketImpl();
try
{
impl = new PlainDatagramSocketImpl();
}
catch (IOException ioe)
{
SocketException se = new SocketException();
se.initCause(ioe);
throw se;
}
}
if (address != null)
@@ -305,7 +325,7 @@ public class DatagramSocket
SecurityManager s = System.getSecurityManager();
if (s != null)
s.checkConnect(localAddr.getHostName(), -1);
s.checkConnect(localAddr.getHostAddress(), -1);
}
catch (SecurityException e)
{
@@ -505,7 +525,7 @@ public class DatagramSocket
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkConnect(address.getHostName(), port);
sm.checkConnect(address.getHostAddress(), port);
try
{
@@ -578,11 +598,17 @@ public class DatagramSocket
&& ! ((DatagramChannelImpl) getChannel()).isInChannelOperation())
throw new IllegalBlockingModeException();
getImpl().receive(p);
DatagramPacket p2 = new DatagramPacket(p.getData(), p.getOffset(), p.maxlen);
getImpl().receive(p2);
p.length = p2.length;
if (p2.getAddress() != null)
p.setAddress(p2.getAddress());
if (p2.getPort() != -1)
p.setPort(p2.getPort());
SecurityManager s = System.getSecurityManager();
if (s != null && isConnected())
s.checkAccept(p.getAddress().getHostName(), p.getPort());
s.checkAccept(p.getAddress().getHostAddress(), p.getPort());
}
/**
@@ -649,6 +675,9 @@ public class DatagramSocket
{
if (isClosed())
throw new SocketException("socket is closed");
if (address == null)
address = new InetSocketAddress(InetAddress.ANY_IF, 0);
if (! (address instanceof InetSocketAddress))
throw new IllegalArgumentException("unsupported address type");
+1 -1
View File
@@ -121,7 +121,7 @@ public final class Inet6Address extends InetAddress
*/
public boolean isMulticastAddress()
{
return ipaddress[0] == 0xFF;
return ipaddress[0] == (byte) 0xFF;
}
/**
+4 -4
View File
@@ -59,7 +59,7 @@ import java.io.Serializable;
* @author Per Bothner
* @author Gary Benson (gbenson@redhat.com)
*
* @specnote This class is not final since JK 1.4
* @specnote This class is not final since JDK 1.4
*/
public class InetAddress implements Serializable
{
@@ -87,7 +87,7 @@ public class InetAddress implements Serializable
}
catch (UnknownHostException e)
{
throw new RuntimeException("should never happen", e);
throw (InternalError) new InternalError().initCause(e);
}
ANY_IF.hostName = ANY_IF.getHostName();
}
@@ -104,7 +104,7 @@ public class InetAddress implements Serializable
}
catch (UnknownHostException e)
{
throw new RuntimeException("should never happen", e);
throw (InternalError) new InternalError().initCause(e);
}
}
@@ -522,7 +522,7 @@ public class InetAddress implements Serializable
}
catch (UnknownHostException e)
{
throw new RuntimeException("should never happen", e);
throw (InternalError) new InternalError().initCause(e);
}
}
@@ -202,13 +202,41 @@ public class MulticastSocket extends DatagramSocket
{
if (isClosed())
throw new SocketException("socket is closed");
Enumeration e = netIf.getInetAddresses();
if (! e.hasMoreElements())
throw new SocketException("no network devices found");
InetAddress address = (InetAddress) e.nextElement();
InetAddress address;
if (netIf != null)
out:
{
Enumeration e = netIf.getInetAddresses();
if (getLocalAddress() instanceof Inet4Address)
{
// Search for a IPv4 address.
while (e.hasMoreElements())
{
address = (InetAddress) e.nextElement();
if (address instanceof Inet4Address)
break out;
}
throw new SocketException("interface " + netIf.getName() + " has no IPv6 address");
}
else if (getLocalAddress() instanceof Inet6Address)
{
// Search for a IPv6 address.
while (e.hasMoreElements())
{
address = (InetAddress) e.nextElement();
if (address instanceof Inet6Address)
break out;
}
throw new SocketException("interface " + netIf.getName() + " has no IPv6 address");
}
else
throw new SocketException("interface " + netIf.getName() + " has no suitable IP address");
}
else
address = InetAddress.ANY_IF;
getImpl().setOption(SocketOptions.IP_MULTICAST_IF, address);
}
@@ -230,6 +258,10 @@ public class MulticastSocket extends DatagramSocket
InetAddress address =
(InetAddress) getImpl().getOption(SocketOptions.IP_MULTICAST_IF);
if (address.isAnyLocalAddress())
return NetworkInterface.createAnyInterface();
NetworkInterface netIf = NetworkInterface.getByInetAddress(address);
return netIf;
@@ -1,5 +1,5 @@
/* NetworkInterface.java --
Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,6 +38,8 @@ exception statement from your version. */
package java.net;
import gnu.classpath.SystemProperties;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
@@ -58,25 +60,23 @@ import java.util.Vector;
*/
public final class NetworkInterface
{
private String name;
private Vector inetAddresses;
NetworkInterface(String name, InetAddress address)
private final VMNetworkInterface netif;
private NetworkInterface(VMNetworkInterface netif)
{
this.netif = netif;
}
/** Creates an NetworkInterface instance which
* represents any interface in the system. Its only
* address is <code>0.0.0.0/0.0.0.0</code>. This
* method is needed by {@link MulticastSocket#getNetworkInterface}
*/
static NetworkInterface createAnyInterface()
{
this.name = name;
this.inetAddresses = new Vector(1, 1);
this.inetAddresses.add(address);
return new NetworkInterface(new VMNetworkInterface());
}
NetworkInterface(String name, InetAddress[] addresses)
{
this.name = name;
this.inetAddresses = new Vector(addresses.length, 1);
for (int i = 0; i < addresses.length; i++)
this.inetAddresses.add(addresses[i]);
}
/**
* Returns the name of the network interface
*
@@ -84,7 +84,7 @@ public final class NetworkInterface
*/
public String getName()
{
return name;
return netif.name;
}
/**
@@ -97,22 +97,23 @@ public final class NetworkInterface
*
* @return An enumeration of all addresses.
*/
public Enumeration getInetAddresses()
public Enumeration<InetAddress> getInetAddresses()
{
SecurityManager s = System.getSecurityManager();
Vector inetAddresses = new Vector(netif.addresses);
if (s == null)
return inetAddresses.elements();
Vector tmpInetAddresses = new Vector(1, 1);
Vector<InetAddress> tmpInetAddresses = new Vector<InetAddress>(1, 1);
for (Enumeration addresses = inetAddresses.elements();
for (Enumeration<InetAddress> addresses = inetAddresses.elements();
addresses.hasMoreElements();)
{
InetAddress addr = (InetAddress) addresses.nextElement();
InetAddress addr = addresses.nextElement();
try
{
s.checkConnect(addr.getHostAddress(), 58000);
s.checkConnect(addr.getHostAddress(), -1);
tmpInetAddresses.add(addr);
}
catch (SecurityException e)
@@ -131,7 +132,7 @@ public final class NetworkInterface
*/
public String getDisplayName()
{
return name;
return netif.name;
}
/**
@@ -148,15 +149,14 @@ public final class NetworkInterface
public static NetworkInterface getByName(String name)
throws SocketException
{
for (Enumeration e = getNetworkInterfaces(); e.hasMoreElements();)
if (name == null)
throw new NullPointerException();
VMNetworkInterface[] netifs = VMNetworkInterface.getVMInterfaces();
for (int i = 0; i < netifs.length; i++)
{
NetworkInterface tmp = (NetworkInterface) e.nextElement();
if (name.equals(tmp.getName()))
return tmp;
if (netifs[i].name.equals(name))
return new NetworkInterface(netifs[i]);
}
// No interface with the given name found.
return null;
}
@@ -173,55 +173,15 @@ public final class NetworkInterface
public static NetworkInterface getByInetAddress(InetAddress addr)
throws SocketException
{
for (Enumeration interfaces = getNetworkInterfaces();
interfaces.hasMoreElements();)
if (addr == null)
throw new NullPointerException();
VMNetworkInterface[] netifs = VMNetworkInterface.getVMInterfaces();
for (int i = 0; i < netifs.length; i++)
{
NetworkInterface tmp = (NetworkInterface) interfaces.nextElement();
for (Enumeration addresses = tmp.inetAddresses.elements();
addresses.hasMoreElements();)
{
if (addr.equals((InetAddress) addresses.nextElement()))
return tmp;
}
if (netifs[i].addresses.contains(addr))
return new NetworkInterface(netifs[i]);
}
throw new SocketException("no network interface is bound to such an IP address");
}
static private Collection condense(Collection interfaces)
{
final Map condensed = new HashMap();
final Iterator interfs = interfaces.iterator();
while (interfs.hasNext()) {
final NetworkInterface face = (NetworkInterface) interfs.next();
final String name = face.getName();
if (condensed.containsKey(name))
{
final NetworkInterface conface = (NetworkInterface) condensed.get(name);
if (!conface.inetAddresses.containsAll(face.inetAddresses))
{
final Iterator faceAddresses = face.inetAddresses.iterator();
while (faceAddresses.hasNext())
{
final InetAddress faceAddress = (InetAddress) faceAddresses.next();
if (!conface.inetAddresses.contains(faceAddress))
{
conface.inetAddresses.add(faceAddress);
}
}
}
}
else
{
condensed.put(name, face);
}
}
return condensed.values();
return null;
}
/**
@@ -231,16 +191,18 @@ public final class NetworkInterface
*
* @exception SocketException If an error occurs
*/
public static Enumeration getNetworkInterfaces() throws SocketException
public static Enumeration<NetworkInterface> getNetworkInterfaces()
throws SocketException
{
Vector networkInterfaces = VMNetworkInterface.getInterfaces();
if (networkInterfaces.isEmpty())
return null;
Collection condensed = condense(networkInterfaces);
return Collections.enumeration(condensed);
VMNetworkInterface[] netifs = VMNetworkInterface.getVMInterfaces();
Vector<NetworkInterface> networkInterfaces =
new Vector<NetworkInterface>(netifs.length);
for (int i = 0; i < netifs.length; i++)
{
if (!netifs[i].addresses.isEmpty())
networkInterfaces.add(new NetworkInterface(netifs[i]));
}
return networkInterfaces.elements();
}
/**
@@ -256,8 +218,12 @@ public final class NetworkInterface
return false;
NetworkInterface tmp = (NetworkInterface) obj;
if (netif.name == null)
return tmp.netif.name == null;
return (name.equals(tmp.name) && inetAddresses.equals(tmp.inetAddresses));
return (netif.name.equals(tmp.netif.name)
&& (netif.addresses.equals(tmp.netif.addresses)));
}
/**
@@ -268,7 +234,12 @@ public final class NetworkInterface
public int hashCode()
{
// FIXME: hash correctly
return name.hashCode() + inetAddresses.hashCode();
int hc = netif.addresses.hashCode();
if (netif.name != null)
hc += netif.name.hashCode();
return hc;
}
/**
@@ -279,19 +250,22 @@ public final class NetworkInterface
public String toString()
{
// FIXME: check if this is correct
String result;
String separator = System.getProperty("line.separator");
StringBuffer result;
String separator = SystemProperties.getProperty("line.separator");
result =
"name: " + getDisplayName() + " (" + getName() + ") addresses:"
+ separator;
result = new StringBuffer();
result.append("name: ");
result.append(getDisplayName());
result.append(" (").append(getName()).append(") addresses:");
result.append(separator);
for (Enumeration e = inetAddresses.elements(); e.hasMoreElements();)
for (Iterator it = netif.addresses.iterator(); it.hasNext(); )
{
InetAddress address = (InetAddress) e.nextElement();
result += address.toString() + ";" + separator;
InetAddress address = (InetAddress) it.next();
result.append(address.toString()).append(";").append(separator);
}
return result;
return result.toString();
}
}
+137
View File
@@ -0,0 +1,137 @@
/* Proxy.java -- Represends a proxy for a network connection
Copyright (C) 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.net;
/**
* Defines a proxy setting. This setting contains a type (https, socks,
* direct) and a socket address.
*
* @since 1.5
*/
public class Proxy
{
/**
* Represents the proxy type.
*/
public enum Type
{
DIRECT, HTTP, SOCKS;
/**
* For compatability with Sun's JDK
*/
private static final long serialVersionUID = -2231209257930100533L;
};
public static final Proxy NO_PROXY = new Proxy(Type.DIRECT, null);
private Type type;
private SocketAddress address;
/**
* Creates a new <code>Proxy</code> object.
*
* @param type The type for this proxy
* @param address The address of this proxy
*/
public Proxy(Type type, SocketAddress address)
{
this.type = type;
this.address = address;
}
/**
* Returns the socket address for this proxy object.
*
* @return the socket address
*/
public SocketAddress address()
{
return address;
}
/**
* Returns the of this proxy instance.
*
* @return the type
*
* @see Type
*/
public Type type()
{
return type;
}
/**
* Compares the given object with this object.
*
* @return <code>true</code> if both objects or equals,
* <code>false</code> otherwise.
*/
public final boolean equals(Object obj)
{
if (! (obj instanceof Proxy))
return false;
Proxy tmp = (Proxy) obj;
return (type.equals(tmp.type)
&& address.equals(tmp.address));
}
/**
* Returns the hashcode for this <code>Proxy</code> object.
*
* @return the hashcode
*/
public final int hashCode()
{
return type.hashCode() ^ address.hashCode();
}
/**
* Returns a string representation of this <code>Proxy</code> object.
*
* @return the string
*/
public String toString()
{
return type.toString() + ":" + address.toString();
}
}
@@ -0,0 +1,117 @@
/* ProxySelector.java -- A proxy selector class
Copyright (C) 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.net;
import gnu.java.net.DefaultProxySelector;
import java.io.IOException;
import java.util.List;
/**
* Class for handling proxies for different connections.
*
* @since 1.5
*/
public abstract class ProxySelector
{
/**
* Default proxy selector.
*/
private static ProxySelector defaultSelector = new DefaultProxySelector();
/**
* Creates a new <code>ProxySelector</code> object.
*/
public ProxySelector()
{
// Do nothing here.
}
/**
* Returns the default proxy selector.
*
* @return the default proxy selector
*
* @throws SecurityException If a security manager is installed and it
* denies NetPermission("getProxySelector")
*/
public static ProxySelector getDefault()
{
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkPermission(new NetPermission("getProxySelector"));
return defaultSelector;
}
/**
* Sets the default proxy selector.
*
* @param selector the defualt proxy selector
*
* @throws SecurityException If a security manager is installed and it
* denies NetPermission("setProxySelector")
*/
public static void setDefault(ProxySelector selector)
{
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkPermission(new NetPermission("setProxySelector"));
defaultSelector = selector;
}
/**
* Signals to the selector that a proxy was no available.
*
* @throws IllegalArgumentException If one argument is null
*/
public abstract void connectFailed(URI uri, SocketAddress address,
IOException exception);
/**
* Returns the list of proxy settings for a given URI.
*
* @return list of proxy settings
*
* @throws IllegalArgumentException If uri is null
*/
public abstract List<Proxy> select(URI uri);
}
+70 -39
View File
@@ -79,6 +79,7 @@ public class ServerSocket
* We need to retain the local address even after the socket is closed.
*/
private InetSocketAddress local;
private int port;
/*
* This constructor is only used by java.nio.
@@ -93,6 +94,7 @@ public class ServerSocket
this.impl = impl;
this.impl.create(true);
setReuseAddress(true);
}
/*
@@ -219,43 +221,53 @@ public class ServerSocket
if (isClosed())
throw new SocketException("ServerSocket is closed");
if (! (endpoint instanceof InetSocketAddress))
throw new IllegalArgumentException("Address type not supported");
if (isBound())
throw new SocketException("Already bound");
InetSocketAddress tmp = (InetSocketAddress) endpoint;
InetAddress addr;
int port;
if (endpoint == null)
{
addr = InetAddress.ANY_IF;
port = 0;
}
else if (! (endpoint instanceof InetSocketAddress))
{
throw new IllegalArgumentException("Address type not supported");
}
else
{
InetSocketAddress tmp = (InetSocketAddress) endpoint;
if (tmp.isUnresolved())
throw new SocketException("Unresolved address");
addr = tmp.getAddress();
port = tmp.getPort();
}
SecurityManager s = System.getSecurityManager();
if (s != null)
s.checkListen(tmp.getPort());
InetAddress addr = tmp.getAddress();
// Initialize addr with 0.0.0.0.
if (addr == null)
addr = InetAddress.ANY_IF;
s.checkListen(port);
try
{
impl.bind(addr, tmp.getPort());
impl.bind(addr, port);
impl.listen(backlog);
local = new InetSocketAddress(
this.port = port;
local = new InetSocketAddress(
(InetAddress) impl.getOption(SocketOptions.SO_BINDADDR),
impl.getLocalPort());
}
catch (IOException exception)
finally
{
close();
throw exception;
}
catch (RuntimeException exception)
{
close();
throw exception;
}
catch (Error error)
{
close();
throw error;
try
{
if (local == null)
close();
}
catch (IOException _)
{
}
}
}
@@ -333,6 +345,19 @@ public class ServerSocket
throw e;
}
catch (SecurityException e)
{
try
{
socket.close();
}
catch (IOException e2)
{
// Ignore.
}
throw e;
}
return socket;
}
@@ -355,9 +380,6 @@ public class ServerSocket
if (isClosed())
throw new SocketException("ServerSocket is closed");
// FIXME: Add a security check to make sure we're allowed to
// connect to the remote host.
// The Sun spec says that if we have an associated channel and
// it is in non-blocking mode, we throw an IllegalBlockingModeException.
// However, in our implementation if the channel itself initiated this
@@ -367,8 +389,12 @@ public class ServerSocket
throw new IllegalBlockingModeException();
impl.accept(socket.impl);
socket.implCreated = true;
socket.bound = true;
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkAccept(socket.getInetAddress().getHostAddress(),
socket.getPort());
}
/**
@@ -378,14 +404,11 @@ public class ServerSocket
*/
public void close() throws IOException
{
if (isClosed())
return;
impl.close();
impl = null;
if (getChannel() != null)
getChannel().close();
if (impl != null)
{
impl.close();
impl = null;
}
}
/**
@@ -425,7 +448,8 @@ public class ServerSocket
*/
public boolean isClosed()
{
return impl == null;
ServerSocketChannel channel = getChannel();
return impl == null || (channel != null && ! channel.isOpen());
}
/**
@@ -573,7 +597,7 @@ public class ServerSocket
return "ServerSocket[unbound]";
return ("ServerSocket[addr=" + getInetAddress() + ",port="
+ impl.getPort() + ",localport=" + impl.getLocalPort() + "]");
+ port + ",localport=" + getLocalPort() + "]");
}
/**
@@ -594,6 +618,13 @@ public class ServerSocket
public static synchronized void setSocketFactory(SocketImplFactory fac)
throws IOException
{
if (factory != null)
throw new SocketException("SocketFactory already defined");
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkSetFactory();
factory = fac;
}
}
+60 -58
View File
@@ -1,5 +1,5 @@
/* Socket.java -- Client socket implementation
Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004
Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004, 2006
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -82,13 +82,6 @@ public class Socket
// package-private because ServerSocket.implAccept() needs to access it.
SocketImpl impl;
/**
* True if socket implementation was created by calling their
* create() method.
*/
// package-private because ServerSocket.implAccept() needs to access it.
boolean implCreated;
/**
* True if the socket is bound.
* Package private so it can be set from ServerSocket when accept is called.
@@ -298,15 +291,33 @@ public class Socket
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkConnect(raddr.getHostName(), rport);
sm.checkConnect(raddr.getHostAddress(), rport);
// bind socket
SocketAddress bindaddr =
laddr == null ? null : new InetSocketAddress(laddr, lport);
bind(bindaddr);
// connect socket
connect(new InetSocketAddress(raddr, rport));
// Connect socket in case of Exceptions we must close the socket
// because an exception in the constructor means that the caller will
// not have a reference to this instance.
// Note: You may have the idea that the exception treatment
// should be moved into connect() but there is a Mauve test which
// shows that a failed connect should not close the socket.
try
{
connect(new InetSocketAddress(raddr, rport));
}
catch (IOException ioe)
{
impl.close();
throw ioe;
}
catch (RuntimeException re)
{
impl.close();
throw re;
}
// FIXME: JCL p. 1586 says if localPort is unspecified, bind to any port,
// i.e. '0' and if localAddr is unspecified, use getLocalAddress() as
@@ -315,21 +326,6 @@ public class Socket
private SocketImpl getImpl() throws SocketException
{
try
{
if (! implCreated)
{
impl.create(true);
implCreated = true;
}
}
catch (IOException e)
{
SocketException se = new SocketException(e.toString());
se.initCause(e);
throw se;
}
return impl;
}
@@ -363,6 +359,7 @@ public class Socket
// bind to address/port
try
{
getImpl().create(true);
getImpl().bind(tmp.getAddress(), tmp.getPort());
bound = true;
}
@@ -479,16 +476,22 @@ public class Socket
InetAddress addr = null;
try
if (impl instanceof PlainSocketImpl)
addr = ((PlainSocketImpl) impl).getLocalAddress().getAddress();
if (addr == null)
{
addr = (InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR);
}
catch (SocketException e)
{
// (hopefully) shouldn't happen
// throw new java.lang.InternalError
// ("Error in PlainSocketImpl.getOption");
return null;
try
{
addr = (InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR);
}
catch (SocketException e)
{
// (hopefully) shouldn't happen
// throw new java.lang.InternalError
// ("Error in PlainSocketImpl.getOption");
return null;
}
}
// FIXME: According to libgcj, checkConnect() is supposed to be called
@@ -707,10 +710,10 @@ public class Socket
if (linger > 65535)
linger = 65535;
getImpl().setOption(SocketOptions.SO_LINGER, new Integer(linger));
getImpl().setOption(SocketOptions.SO_LINGER, Integer.valueOf(linger));
}
else
getImpl().setOption(SocketOptions.SO_LINGER, Boolean.valueOf(false));
getImpl().setOption(SocketOptions.SO_LINGER, Integer.valueOf(-1));
}
/**
@@ -1001,12 +1004,8 @@ public class Socket
if (isClosed())
return;
getImpl().close();
impl.close();
impl = null;
bound = false;
if (getChannel() != null)
getChannel().close();
}
/**
@@ -1019,16 +1018,17 @@ public class Socket
try
{
if (isConnected())
return ("Socket[addr=" + getImpl().getInetAddress() + ",port="
+ getImpl().getPort() + ",localport="
+ getImpl().getLocalPort() + "]");
return (super.toString()
+ " [addr=" + getImpl().getInetAddress() + ",port="
+ getImpl().getPort() + ",localport="
+ getImpl().getLocalPort() + "]");
}
catch (SocketException e)
{
// This cannot happen as we are connected.
}
return "Socket[unconnected]";
return super.toString() + " [unconnected]";
}
/**
@@ -1206,17 +1206,10 @@ public class Socket
*/
public boolean isConnected()
{
try
{
if (getImpl() == null)
return false;
return getImpl().getInetAddress() != null;
}
catch (SocketException e)
{
return false;
}
if (impl == null)
return false;
return impl.getInetAddress() != null;
}
/**
@@ -1228,6 +1221,13 @@ public class Socket
*/
public boolean isBound()
{
if (isClosed())
return false;
if (impl instanceof PlainSocketImpl)
{
InetSocketAddress addr = ((PlainSocketImpl) impl).getLocalAddress();
return addr != null && addr.getAddress() != null;
}
return bound;
}
@@ -1240,7 +1240,9 @@ public class Socket
*/
public boolean isClosed()
{
return impl == null;
SocketChannel channel = getChannel();
return impl == null || (channel != null && ! channel.isOpen());
}
/**
+4 -6
View File
@@ -156,7 +156,7 @@ import java.util.regex.Pattern;
* @since 1.4
*/
public final class URI
implements Comparable, Serializable
implements Comparable<URI>, Serializable
{
/**
* For serialization compatability.
@@ -1229,7 +1229,7 @@ public final class URI
}
/**
* Compare the URI with another object that must also be a URI.
* Compare the URI with another URI.
* Undefined components are taken to be less than any other component.
* The following criteria are observed:
* </p>
@@ -1265,16 +1265,14 @@ public final class URI
* </ul>
* </ul>
*
* @param obj This object to compare this URI with
* @param uri The other URI to compare this URI with
* @return a negative integer, zero or a positive integer depending
* on whether this URI is less than, equal to or greater
* than that supplied, respectively.
* @throws ClassCastException if the given object is not a URI
*/
public int compareTo(Object obj)
public int compareTo(URI uri)
throws ClassCastException
{
URI uri = (URI) obj;
if (scheme == null && uri.getScheme() != null)
return -1;
if (scheme != null)
+28 -4
View File
@@ -322,7 +322,8 @@ public final class URL implements Serializable
*/
public URL(String spec) throws MalformedURLException
{
this((URL) null, spec != null ? spec : "", (URLStreamHandler) null);
this((URL) null, spec != null ? spec : "", (URLStreamHandler) null,
false);
}
/**
@@ -343,7 +344,9 @@ public final class URL implements Serializable
*/
public URL(URL context, String spec) throws MalformedURLException
{
this(context, spec, (context == null) ? (URLStreamHandler)null : context.ph);
this(context, spec,
(context == null) ? (URLStreamHandler) null : context.ph,
false);
}
/**
@@ -376,6 +379,23 @@ public final class URL implements Serializable
*/
public URL(URL context, String spec, URLStreamHandler ph)
throws MalformedURLException
{
this(context, spec, ph, true);
}
/**
* Private constructor called by all other constructors taking
* a context and spec.
*
* @param context The context in which to parse the specification
* @param spec The string to parse as an URL
* @param ph The stream handler for the URL
* @param phFromUser Whether or not the user supplied the URLStreamHandler
*
*/
private URL(URL context, String spec, URLStreamHandler ph,
boolean phFromUser)
throws MalformedURLException
{
/* A protocol is defined by the doc as the substring before a ':'
* as long as the ':' occurs before any '/'.
@@ -397,7 +417,11 @@ public final class URL implements Serializable
if ((colon = spec.indexOf("://", 1)) > 0
&& ((colon < slash || slash < 0))
&& ! spec.regionMatches(colon, "://:", 0, 4))
context = null;
{
context = null;
if (! phFromUser)
ph = null;
}
boolean protocolSpecified = false;
@@ -458,7 +482,7 @@ public final class URL implements Serializable
if (ph != null)
{
SecurityManager s = System.getSecurityManager();
if (s != null)
if (s != null && phFromUser)
s.checkPermission(new NetPermission("specifyStreamHandler"));
this.ph = ph;
@@ -508,7 +508,7 @@ public class URLClassLoader extends SecureClassLoader
* loaded
* @return a Class object representing the found class
*/
protected Class findClass(final String className)
protected Class<?> findClass(final String className)
throws ClassNotFoundException
{
// Just try to find the resource by the (almost) same name
@@ -714,10 +714,10 @@ public class URLClassLoader extends SecureClassLoader
* @exception IOException when an error occurs accessing one of the
* locations
*/
public Enumeration findResources(String resourceName)
public Enumeration<URL> findResources(String resourceName)
throws IOException
{
Vector resources = new Vector();
Vector<URL> resources = new Vector<URL>();
int max = urlinfos.size();
for (int i = 0; i < max; i++)
{
+55 -11
View File
@@ -49,6 +49,7 @@ import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;
@@ -174,9 +175,14 @@ public abstract class URLConnection
private static boolean dateformats_initialized;
/**
* The timeout period.
* The connection timeout period.
*/
private int timeout;
private int connectTimeout;
/**
* The read timeout period.
*/
private int readTimeout;
/* Cached ParsePosition, used when parsing dates. */
private ParsePosition position;
@@ -216,8 +222,8 @@ public abstract class URLConnection
}
/**
* Returns the connection timeout speed, in milliseconds, or zero if the timeout
* is infinite or not set.
* Returns the connection timeout speed, in milliseconds, or zero if
* the timeout is infinite or not set.
*
* @return The timeout.
*
@@ -225,7 +231,7 @@ public abstract class URLConnection
*/
public int getConnectTimeout()
{
return timeout;
return connectTimeout;
}
/**
@@ -235,7 +241,7 @@ public abstract class URLConnection
*
* Throws an <code>IllegalArgumentException</code> if timeout < 0.
*
* @param timeout - The timeout, in milliseconds.
* @param timeout the timeout, in milliseconds.
*
* @since 1.5
*/
@@ -244,7 +250,45 @@ public abstract class URLConnection
{
if( timeout < 0 )
throw new IllegalArgumentException("Timeout must be 0 or positive.");
this.timeout = timeout;
connectTimeout = timeout;
}
/**
* Returns the read timeout, in milliseconds, or zero if the timeout
* is infinite or not set.
*
* @return The timeout.
*
* @see #setReadTimeout
*
* @since 1.5
*/
public int getReadTimeout()
{
return readTimeout;
}
/**
* Set the read timeout, in milliseconds, or zero if the timeout
* is to be considered infinite. Note that in certain socket
* implementations/platforms this method may not have any effect.
*
* Throws an <code>IllegalArgumentException</code> if timeout < 0.
*
* @param timeout - The timeout, in milliseconds.
*
* @throws IllegalArgumentException if timeout is negative.
*
* @see #getReadTimeout
*
* @since 1.5
*/
public void setReadTimeout(int timeout)
throws IllegalArgumentException
{
if( timeout < 0 )
throw new IllegalArgumentException("Timeout must be 0 or positive.");
readTimeout = timeout;
}
/**
@@ -359,10 +403,10 @@ public abstract class URLConnection
*
* @since 1.4
*/
public Map getHeaderFields()
public Map<String,List<String>> getHeaderFields()
{
// Subclasses for specific protocols override this.
return Collections.EMPTY_MAP;
return Collections.emptyMap();
}
/**
@@ -862,14 +906,14 @@ public abstract class URLConnection
*
* @since 1.4
*/
public Map getRequestProperties()
public Map<String,List<String>> getRequestProperties()
{
if (connected)
throw new IllegalStateException("Already connected");
// Overridden by subclasses that support reading header fields from the
// request.
return Collections.EMPTY_MAP;
return Collections.emptyMap();
}
/**
@@ -0,0 +1,122 @@
# This property file contains dependencies of classes, methods, and
# field on other methods or classes.
#
# Syntax:
#
# <used>: <needed 1> [... <needed N>]
#
# means that when <used> is included, <needed 1> (... <needed N>) must
# be included as well.
#
# <needed X> and <used> are of the form
#
# <class.methodOrField(signature)>
#
# or just
#
# <class>
#
# Within dependencies, variables can be used. A variable is defined as
# follows:
#
# {variable}: value1 value2 ... value<n>
#
# variables can be used on the right side of dependencies as follows:
#
# <used>: com.bla.blu.{variable}.Class.m()V
#
# The use of the variable will expand to <n> dependencies of the form
#
# <used>: com.bla.blu.value1.Class.m()V
# <used>: com.bla.blu.value2.Class.m()V
# ...
# <used>: com.bla.blu.value<n>.Class.m()V
#
# Variables can be redefined when building a system to select the
# required support for features like encodings, protocols, etc.
#
# Hints:
#
# - For methods and fields, the signature is mandatory. For
# specification, please see the Java Virtual Machine Specification by
# SUN. Unlike in the spec, field signatures (types) are in brackets.
#
# - Package names must be separated by '/' (and not '.'). E.g.,
# java/lang/Class (this is necessary, because the '.' is used to
# separate method or field names from classes)
#
# - In case <needed> refers to a class, only the class itself will be
# included in the resulting binary, NOT necessarily all its methods
# and fields. If you want to refer to all methods and fields, you can
# write class.* as an abbreviation.
#
# - Abbreviations for packages are also possible: my/package/* means all
# methods and fields of all classes in my/package.
#
# - A line with a trailing '\' continues in the next line.
java/net/InetAddress: \
java/lang/ClassNotFoundException.<init>(Ljava/lang/String;)V \
java/lang/InternalError.<init>(Ljava/lang/String;)V \
java/net/UnknownHostException.<init>(Ljava/lang/String;)V
java/net/DatagramSocketImpl: \
java/net/DatagramSocketImpl.fd(Ljava/io/FileDescriptor;) \
java/net/DatagramSocketImpl.localPort(I)
java/net/PlainDatagramSocketImpl: \
java/lang/ClassNotFoundException.<init>(Ljava/lang/String;)V \
java/lang/InternalError.<init>(Ljava/lang/String;)V \
java/io/IOException.<init>(Ljava/lang/String;)V \
java/io/FileDescriptor.<init>()V \
java/lang/Boolean.<init>(Z)V \
java/lang/Integer.<init>(I)V \
java/net/InetAddress.getByName(Ljava/lang/String;)Ljava/net/InetAddress; \
java/net/InetAddress.getAddress()[B \
java/lang/Boolean.booleanValue()Z \
java/lang/Integer.intValue()I \
java/net/SocketException.<init>(Ljava/lang/String;)V \
java/net/DatagramPacket.getData()[B \
java/net/SocketImpl.address(Ljava/net/InetAddress;) \
java/net/PlainSocketImpl.native_fd(I) \
java/net/SocketImpl.fd(Ljava/io/FileDescriptor;) \
java/net/SocketImpl.address(Ljava/net/InetAddress;) \
java/net/PlainDatagramSocketImpl.native_fd(I) \
java/net/SocketImpl.localport(I) \
java/net/SocketImpl.port(I)
java/net/PlainSocketImpl: \
java/lang/ClassNotFoundException.<init>(Ljava/lang/String;)V \
java/lang/InternalError.<init>(Ljava/lang/String;)V \
java/io/IOException.<init>(Ljava/lang/String;)V \
java/io/FileDescriptor.<init>()V \
java/lang/Boolean.<init>(Z)V \
java/lang/Integer.<init>(I)V \
java/net/InetAddress.getByName(Ljava/lang/String;)Ljava/net/InetAddress; \
java/net/InetAddress.getAddress()[B \
java/lang/Boolean.booleanValue()Z \
java/lang/Integer.intValue()I \
java/net/SocketException.<init>(Ljava/lang/String;)V \
java/net/DatagramPacket.getData()[B \
java/net/SocketImpl.address(Ljava/net/InetAddress;) \
java/net/PlainSocketImpl.native_fd(I) \
java/net/SocketImpl.fd(Ljava/io/FileDescriptor;) \
java/net/SocketImpl.address(Ljava/net/InetAddress;) \
java/net/PlainDatagramSocketImpl.native_fd(I) \
java/net/SocketImpl.localport(I) \
java/net/SocketImpl.port(I)
# All protocols supported are loaded via URL.getURLStreamHandler from
# class gnu.java.net.protocol.<protocol>.Handler.
#
# This introduces a dependency for all protocols. To allow an easy selection
# and addition of protocols, the library variable {protocols} can be set to
# the set of supported protocols.
#
{protocols}: http file jar
java/net/URL.getURLStreamHandler(Ljava/lang/String;)Ljava/net/URLStreamHandler;: \
gnu/java/net/protocol/{protocols}/Handler.* \
com/aicas/java/net/protocol/rom/Handler.*
# end of file