diff options
Diffstat (limited to 'libjava/classpath/java/net')
24 files changed, 1142 insertions, 1142 deletions
diff --git a/libjava/classpath/java/net/ContentHandler.java b/libjava/classpath/java/net/ContentHandler.java index 7f63e740229..fed8f3de4b5 100644 --- a/libjava/classpath/java/net/ContentHandler.java +++ b/libjava/classpath/java/net/ContentHandler.java @@ -117,8 +117,8 @@ public abstract class ContentHandler for (int i = 0; i < classes.length; i++) { - if (classes[i].isInstance(obj)) - return obj; + if (classes[i].isInstance(obj)) + return obj; } return null; diff --git a/libjava/classpath/java/net/DatagramSocket.java b/libjava/classpath/java/net/DatagramSocket.java index ea681a1ab0a..6ca9c42fea6 100644 --- a/libjava/classpath/java/net/DatagramSocket.java +++ b/libjava/classpath/java/net/DatagramSocket.java @@ -196,15 +196,15 @@ public class DatagramSocket else try { - impl = - (DatagramSocketImpl) Class.forName("java.net." + propVal - + "DatagramSocketImpl") - .newInstance(); + impl = + (DatagramSocketImpl) Class.forName("java.net." + propVal + + "DatagramSocketImpl") + .newInstance(); } catch (Exception e) { - System.err.println("Could not instantiate class: java.net." - + propVal + "DatagramSocketImpl"); + System.err.println("Could not instantiate class: java.net." + + propVal + "DatagramSocketImpl"); try { impl = new PlainDatagramSocketImpl(); @@ -226,19 +226,19 @@ public class DatagramSocket { try { - if (! implCreated) - { - impl.create(); - implCreated = true; - } + if (! implCreated) + { + impl.create(); + implCreated = true; + } - return impl; + return impl; } catch (IOException e) { - SocketException se = new SocketException(); - se.initCause(e); - throw se; + SocketException se = new SocketException(); + se.initCause(e); + throw se; } } @@ -252,27 +252,27 @@ public class DatagramSocket try { - getImpl().close(); + getImpl().close(); } catch (SocketException e) { - // Ignore this case, just close the socket in finally clause. + // Ignore this case, just close the socket in finally clause. } finally { - remoteAddress = null; - remotePort = -1; - impl = null; + remoteAddress = null; + remotePort = -1; + impl = null; } try { - if (getChannel() != null) - getChannel().close(); + if (getChannel() != null) + getChannel().close(); } catch (IOException e) { - // Do nothing. + // Do nothing. } } @@ -320,21 +320,21 @@ public class DatagramSocket try { - localAddr = - (InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR); + localAddr = + (InetAddress) getImpl().getOption(SocketOptions.SO_BINDADDR); - SecurityManager s = System.getSecurityManager(); - if (s != null) - s.checkConnect(localAddr.getHostAddress(), -1); + SecurityManager s = System.getSecurityManager(); + if (s != null) + s.checkConnect(localAddr.getHostAddress(), -1); } catch (SecurityException e) { - localAddr = InetAddress.ANY_IF; + localAddr = InetAddress.ANY_IF; } catch (SocketException e) { - // This cannot happen as we are bound. - return null; + // This cannot happen as we are bound. + return null; } return localAddr; @@ -352,12 +352,12 @@ public class DatagramSocket try { - return getImpl().getLocalPort(); + return getImpl().getLocalPort(); } catch (SocketException e) { - // This cannot happen as we are bound. - return 0; + // This cannot happen as we are bound. + return 0; } } @@ -529,13 +529,13 @@ public class DatagramSocket try { - getImpl().connect(address, port); - remoteAddress = address; - remotePort = port; + getImpl().connect(address, port); + remoteAddress = address; + remotePort = port; } catch (SocketException e) { - // This means simply not connected or connect not implemented. + // This means simply not connected or connect not implemented. } } @@ -553,16 +553,16 @@ public class DatagramSocket try { - getImpl().disconnect(); + getImpl().disconnect(); } catch (SocketException e) { - // This cannot happen as we are connected. + // This cannot happen as we are connected. } finally { - remoteAddress = null; - remotePort = -1; + remoteAddress = null; + remotePort = -1; } } @@ -592,7 +592,7 @@ public class DatagramSocket if (remoteAddress != null && remoteAddress.isMulticastAddress()) throw new IOException - ("Socket connected to a multicast address my not receive"); + ("Socket connected to a multicast address my not receive"); if (getChannel() != null && ! getChannel().isBlocking() && ! ((DatagramChannelImpl) getChannel()).isInChannelOperation()) @@ -635,19 +635,19 @@ public class DatagramSocket SecurityManager s = System.getSecurityManager(); if (s != null && ! isConnected()) { - InetAddress addr = p.getAddress(); - if (addr.isMulticastAddress()) - s.checkMulticast(addr); - else - s.checkConnect(addr.getHostAddress(), p.getPort()); + InetAddress addr = p.getAddress(); + if (addr.isMulticastAddress()) + s.checkMulticast(addr); + else + s.checkConnect(addr.getHostAddress(), p.getPort()); } if (isConnected()) { - if (p.getAddress() != null - && (remoteAddress != p.getAddress() || remotePort != p.getPort())) - throw new IllegalArgumentException - ("DatagramPacket address does not match remote address"); + if (p.getAddress() != null + && (remoteAddress != p.getAddress() || remotePort != p.getPort())) + throw new IllegalArgumentException + ("DatagramPacket address does not match remote address"); } // FIXME: if this is a subclass of MulticastSocket, @@ -675,7 +675,7 @@ public class DatagramSocket { if (isClosed()) throw new SocketException("socket is closed"); - + if (address == null) address = new InetSocketAddress(InetAddress.ANY_IF, 0); @@ -697,23 +697,23 @@ public class DatagramSocket try { - getImpl().bind(port, addr); - bound = true; + getImpl().bind(port, addr); + bound = true; } catch (SocketException exception) { - getImpl().close(); - throw exception; + getImpl().close(); + throw exception; } catch (RuntimeException exception) { - getImpl().close(); - throw exception; + getImpl().close(); + throw exception; } catch (Error error) { - getImpl().close(); - throw error; + getImpl().close(); + throw error; } } diff --git a/libjava/classpath/java/net/DatagramSocketImpl.java b/libjava/classpath/java/net/DatagramSocketImpl.java index cfcde92e5fc..4f51f9f938a 100644 --- a/libjava/classpath/java/net/DatagramSocketImpl.java +++ b/libjava/classpath/java/net/DatagramSocketImpl.java @@ -200,9 +200,9 @@ public abstract class DatagramSocketImpl implements SocketOptions * socket. <b>Use <code>getTimeToLive()</code></b> instead. * * @return the current time-to-live - * + * * @exception IOException If an error occurs - * + * * @deprecated // FIXME: when ? */ protected abstract byte getTTL() throws IOException; @@ -222,7 +222,7 @@ public abstract class DatagramSocketImpl implements SocketOptions * socket. * * @return the current time-to-live - * + * * @exception IOException If an error occurs */ protected abstract int getTimeToLive() throws IOException; @@ -276,7 +276,7 @@ public abstract class DatagramSocketImpl implements SocketOptions /** * Returns the FileDescriptor for this socket - * + * * @return the file descriptor associated with this socket */ protected FileDescriptor getFileDescriptor() diff --git a/libjava/classpath/java/net/HttpURLConnection.java b/libjava/classpath/java/net/HttpURLConnection.java index 07eae48e77a..72dd67d9164 100644 --- a/libjava/classpath/java/net/HttpURLConnection.java +++ b/libjava/classpath/java/net/HttpURLConnection.java @@ -380,7 +380,7 @@ public abstract class HttpURLConnection extends URLConnection /** * Returns the value of this HttpURLConnection's instanceFollowRedirects * field - * + * * @return true if following redirects is enabled, false otherwise */ public boolean getInstanceFollowRedirects() @@ -474,33 +474,33 @@ public abstract class HttpURLConnection extends URLConnection // If responseCode not yet explicitly set by subclass if (responseCode == -1) { - // Response is the first header received from the connection. - String respField = getHeaderField(0); - - if (respField == null || ! respField.startsWith("HTTP/")) - { - // Set to default values on failure. - responseCode = -1; - responseMessage = null; - return; - } - - int firstSpc; - int nextSpc; - firstSpc = respField.indexOf(' '); - nextSpc = respField.indexOf(' ', firstSpc + 1); - responseMessage = respField.substring(nextSpc + 1); - String codeStr = respField.substring(firstSpc + 1, nextSpc); - try - { - responseCode = Integer.parseInt(codeStr); - } - catch (NumberFormatException e) - { - // Set to default values on failure. - responseCode = -1; - responseMessage = null; - } + // Response is the first header received from the connection. + String respField = getHeaderField(0); + + if (respField == null || ! respField.startsWith("HTTP/")) + { + // Set to default values on failure. + responseCode = -1; + responseMessage = null; + return; + } + + int firstSpc; + int nextSpc; + firstSpc = respField.indexOf(' '); + nextSpc = respField.indexOf(' ', firstSpc + 1); + responseMessage = respField.substring(nextSpc + 1); + String codeStr = respField.substring(firstSpc + 1, nextSpc); + try + { + responseCode = Integer.parseInt(codeStr); + } + catch (NumberFormatException e) + { + // Set to default values on failure. + responseCode = -1; + responseMessage = null; + } } } @@ -542,11 +542,11 @@ public abstract class HttpURLConnection extends URLConnection int code; try { - code = getResponseCode(); + code = getResponseCode(); } catch (IOException e) { - code = -1; + code = -1; } if (code == -1) @@ -557,18 +557,18 @@ public abstract class HttpURLConnection extends URLConnection try { - PushbackInputStream pbis = new PushbackInputStream(getInputStream()); + PushbackInputStream pbis = new PushbackInputStream(getInputStream()); - int i = pbis.read(); - if (i == -1) - return null; + int i = pbis.read(); + if (i == -1) + return null; - pbis.unread(i); - return pbis; + pbis.unread(i); + return pbis; } catch (IOException e) { - return null; + return null; } } diff --git a/libjava/classpath/java/net/Inet4Address.java b/libjava/classpath/java/net/Inet4Address.java index 1a50a472925..e3cff7b13ae 100644 --- a/libjava/classpath/java/net/Inet4Address.java +++ b/libjava/classpath/java/net/Inet4Address.java @@ -70,7 +70,7 @@ public final class Inet4Address extends InetAddress { return new InetAddress(addr, hostName, AF_INET); } - + /** * Initializes this object's addr instance variable from the passed in * byte array. Note that this constructor is protected and is called @@ -175,8 +175,8 @@ public final class Inet4Address extends InetAddress return false; return ((addr[0] & 0xff) == 0xe0 - && (addr[1] & 0xff) == 0x00 - && (addr[2] & 0xff) == 0x00); + && (addr[1] & 0xff) == 0x00 + && (addr[2] & 0xff) == 0x00); } /** @@ -218,15 +218,15 @@ public final class Inet4Address extends InetAddress int len = addr.length; int i = 0; - + for ( ; ; ) { sb.append(addr[i] & 0xff); i++; - + if (i == len) break; - + sb.append('.'); } @@ -266,7 +266,7 @@ public final class Inet4Address extends InetAddress for (int i = addr1.length; --i >= 0;) if (addr1[i] != addr2[i]) - return false; + return false; return true; } diff --git a/libjava/classpath/java/net/Inet6Address.java b/libjava/classpath/java/net/Inet6Address.java index 9a1c4ea96da..60c406587d4 100644 --- a/libjava/classpath/java/net/Inet6Address.java +++ b/libjava/classpath/java/net/Inet6Address.java @@ -48,7 +48,7 @@ import java.io.IOException; /* * Written using on-line Java Platform 1.4 API Specification and * RFC 1884 (http://www.ietf.org/rfc/rfc1884.txt) - * + * * @author Michael Koch * @status Updated to 1.5. Serialization compatibility is tested. */ @@ -62,37 +62,37 @@ public final class Inet6Address extends InetAddress byte[] ipaddress; /** - * The scope ID, if any. + * The scope ID, if any. * @since 1.5 - * @serial + * @serial */ private int scope_id; /** - * The scope ID, if any. + * The scope ID, if any. * @since 1.5 - * @serial + * @serial */ private boolean scope_id_set; /** * Whether ifname is set or not. * @since 1.5 - * @serial + * @serial */ private boolean scope_ifname_set; /** * Name of the network interface, used only by the serialization methods * @since 1.5 - * @serial + * @serial */ private String ifname; /** * Scope network interface, or <code>null</code>. */ - private transient NetworkInterface nif; + private transient NetworkInterface nif; /** * The address family of these addresses (used for serialization). @@ -250,14 +250,14 @@ public final class Inet6Address extends InetAddress * * @throws UnkownHostException if the address is an invalid number of bytes. * @since 1.5 - */ - public static Inet6Address getByAddress(String host, byte[] addr, - int scopeId) + */ + public static Inet6Address getByAddress(String host, byte[] addr, + int scopeId) throws UnknownHostException { if( addr.length != 16 ) throw new UnknownHostException("Illegal address length: " + addr.length - + " bytes."); + + " bytes."); Inet6Address ip = new Inet6Address( addr, host ); ip.scope_id = scopeId; ip.scope_id_set = true; @@ -270,14 +270,14 @@ public final class Inet6Address extends InetAddress * * @throws UnkownHostException if the address is an invalid number of bytes. * @since 1.5 - */ - public static Inet6Address getByAddress(String host, byte[] addr, - NetworkInterface nif) + */ + public static Inet6Address getByAddress(String host, byte[] addr, + NetworkInterface nif) throws UnknownHostException { if( addr.length != 16 ) throw new UnknownHostException("Illegal address length: " + addr.length - + " bytes."); + + " bytes."); Inet6Address ip = new Inet6Address( addr, host ); ip.nif = nif; @@ -287,8 +287,8 @@ public final class Inet6Address extends InetAddress /** * Returns the <code>NetworkInterface</code> of the address scope * if it is a scoped address and the scope is given in the form of a - * NetworkInterface. - * (I.e. the address was created using the + * NetworkInterface. + * (I.e. the address was created using the * getByAddress(String, byte[], NetworkInterface) method) * Otherwise this method returns <code>null</code>. * @since 1.5 @@ -310,7 +310,7 @@ public final class Inet6Address extends InetAddress // check scope_id_set because some JDK-serialized objects seem to have // scope_id set to a nonzero value even when scope_id_set == false if( scope_id_set ) - return scope_id; + return scope_id; return 0; } @@ -323,12 +323,12 @@ public final class Inet6Address extends InetAddress for (int i = 0; i < 16; i += 2) { - int x = ((ipaddress[i] & 0xFF) << 8) | (ipaddress[i + 1] & 0xFF); + int x = ((ipaddress[i] & 0xFF) << 8) | (ipaddress[i + 1] & 0xFF); - if (i > 0) - sbuf.append(':'); + if (i > 0) + sbuf.append(':'); - sbuf.append(Integer.toHexString(x)); + sbuf.append(Integer.toHexString(x)); } if( nif != null ) sbuf.append( "%" + nif.getName() ); @@ -361,7 +361,7 @@ public final class Inet6Address extends InetAddress for (int i = 0; i < ip.ipaddress.length; i++) if (ipaddress[i] != ip.ipaddress[i]) - return false; + return false; if( ip.nif != null && nif != null ) return nif.equals( ip.nif ); @@ -399,16 +399,16 @@ public final class Inet6Address extends InetAddress */ private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException - { + { s.defaultReadObject(); try { - if( scope_ifname_set ) - nif = NetworkInterface.getByName( ifname ); + if( scope_ifname_set ) + nif = NetworkInterface.getByName( ifname ); } catch( SocketException se ) { - // FIXME: Ignore this? or throw an IOException? + // FIXME: Ignore this? or throw an IOException? } } @@ -421,8 +421,8 @@ public final class Inet6Address extends InetAddress { if( nif != null ) { - ifname = nif.getName(); - scope_ifname_set = true; + ifname = nif.getName(); + scope_ifname_set = true; } s.defaultWriteObject(); } diff --git a/libjava/classpath/java/net/InetAddress.java b/libjava/classpath/java/net/InetAddress.java index 1f266798045..1a9dc62026b 100644 --- a/libjava/classpath/java/net/InetAddress.java +++ b/libjava/classpath/java/net/InetAddress.java @@ -74,24 +74,24 @@ public class InetAddress implements Serializable byte[] addr; try { - addr = VMInetAddress.lookupInaddrAny(); + addr = VMInetAddress.lookupInaddrAny(); } catch (UnknownHostException e) { - // Make one up and hope it works. - addr = new byte[] {0, 0, 0, 0}; + // Make one up and hope it works. + addr = new byte[] {0, 0, 0, 0}; } try { - ANY_IF = getByAddress(addr); + ANY_IF = getByAddress(addr); } catch (UnknownHostException e) { - throw (InternalError) new InternalError().initCause(e); + throw (InternalError) new InternalError().initCause(e); } ANY_IF.hostName = ANY_IF.getHostName(); } - + /** * Stores static localhost address object. */ @@ -100,13 +100,13 @@ public class InetAddress implements Serializable { try { - LOCALHOST = getByAddress("localhost", new byte[] {127, 0, 0, 1}); + LOCALHOST = getByAddress("localhost", new byte[] {127, 0, 0, 1}); } catch (UnknownHostException e) { - throw (InternalError) new InternalError().initCause(e); + throw (InternalError) new InternalError().initCause(e); } - } + } /** * The Serialized Form specifies that an int 'address' is saved/restored. @@ -158,7 +158,7 @@ public class InetAddress implements Serializable * <p>This method cannot be abstract for backward compatibility reasons. By * default it always throws {@link UnsupportedOperationException} unless * overridden.</p> - * + * * @return true if mulitcast, false if not * * @since 1.1 @@ -174,7 +174,7 @@ public class InetAddress implements Serializable * <p>This method cannot be abstract for backward compatibility reasons. By * default it always throws {@link UnsupportedOperationException} unless * overridden.</p> - * + * * @since 1.4 */ public boolean isAnyLocalAddress() @@ -188,7 +188,7 @@ public class InetAddress implements Serializable * <p>This method cannot be abstract for backward compatibility reasons. By * default it always throws {@link UnsupportedOperationException} unless * overridden.</p> - * + * * @since 1.4 */ public boolean isLoopbackAddress() @@ -202,7 +202,7 @@ public class InetAddress implements Serializable * <p>This method cannot be abstract for backward compatibility reasons. By * default it always throws {@link UnsupportedOperationException} unless * overridden.</p> - * + * * @since 1.4 */ public boolean isLinkLocalAddress() @@ -216,7 +216,7 @@ public class InetAddress implements Serializable * <p>This method cannot be abstract for backward compatibility reasons. By * default it always throws {@link UnsupportedOperationException} unless * overridden.</p> - * + * * @since 1.4 */ public boolean isSiteLocalAddress() @@ -230,7 +230,7 @@ public class InetAddress implements Serializable * <p>This method cannot be abstract for backward compatibility reasons. By * default it always throws {@link UnsupportedOperationException} unless * overridden.</p> - * + * * @since 1.4 */ public boolean isMCGlobal() @@ -244,7 +244,7 @@ public class InetAddress implements Serializable * <p>This method cannot be abstract for backward compatibility reasons. By * default it always throws {@link UnsupportedOperationException} unless * overridden.</p> - * + * * @since 1.4 */ public boolean isMCNodeLocal() @@ -258,7 +258,7 @@ public class InetAddress implements Serializable * <p>This method cannot be abstract for backward compatibility reasons. By * default it always throws {@link UnsupportedOperationException} unless * overridden.</p> - * + * * @since 1.4 */ public boolean isMCLinkLocal() @@ -272,7 +272,7 @@ public class InetAddress implements Serializable * <p>This method cannot be abstract for backward compatibility reasons. By * default it always throws {@link UnsupportedOperationException} unless * overridden.</p> - * + * * @since 1.4 */ public boolean isMCSiteLocal() @@ -287,7 +287,7 @@ public class InetAddress implements Serializable * <p>This method cannot be abstract for backward compatibility reasons. By * default it always throws {@link UnsupportedOperationException} unless * overridden.</p> - * + * * @since 1.4 */ public boolean isMCOrgLocal() @@ -316,17 +316,17 @@ public class InetAddress implements Serializable { try { - return ResolverCache.getHostByAddr(addr); + return ResolverCache.getHostByAddr(addr); } catch (UnknownHostException e) { - return getHostAddress(); + return getHostAddress(); } } /** * Returns the canonical hostname represented by this InetAddress - * + * * @since 1.4 */ public String getCanonicalHostName() @@ -337,13 +337,13 @@ public class InetAddress implements Serializable if (sm != null) { try - { + { sm.checkConnect(hostname, -1); - } - catch (SecurityException e) - { - return getHostAddress(); - } + } + catch (SecurityException e) + { + return getHostAddress(); + } } return hostname; @@ -367,7 +367,7 @@ public class InetAddress implements Serializable * <p>This method cannot be abstract for backward compatibility reasons. By * default it always throws {@link UnsupportedOperationException} unless * overridden.</p> - * + * * @return The IP address of this object in String form * * @since 1.0.2 @@ -425,7 +425,7 @@ public class InetAddress implements Serializable for (int i = 0; i < addr.length; i++) if (addr[i] != addr2[i]) - return false; + return false; return true; } @@ -481,18 +481,18 @@ public class InetAddress implements Serializable if (addr.length == 16) { - for (int i = 0; i < 12; i++) - { - if (addr[i] != (i < 10 ? 0 : (byte) 0xFF)) - return new Inet6Address(addr, host); - } - - byte[] ip4addr = new byte[4]; - ip4addr[0] = addr[12]; - ip4addr[1] = addr[13]; - ip4addr[2] = addr[14]; - ip4addr[3] = addr[15]; - return new Inet4Address(ip4addr, host); + for (int i = 0; i < 12; i++) + { + if (addr[i] != (i < 10 ? 0 : (byte) 0xFF)) + return new Inet6Address(addr, host); + } + + byte[] ip4addr = new byte[4]; + ip4addr[0] = addr[12]; + ip4addr[1] = addr[13]; + ip4addr[2] = addr[14]; + ip4addr[3] = addr[15]; + return new Inet4Address(ip4addr, host); } throw new UnknownHostException("IP address has illegal length"); @@ -515,14 +515,14 @@ public class InetAddress implements Serializable byte[] address = VMInetAddress.aton(literal); if (address == null) return null; - + try { - return getByAddress(address); + return getByAddress(address); } catch (UnknownHostException e) { - throw (InternalError) new InternalError().initCause(e); + throw (InternalError) new InternalError().initCause(e); } } @@ -534,7 +534,7 @@ public class InetAddress implements Serializable * default. This method is equivalent to returning the first element in * the InetAddress array returned from GetAllByName. * - * @param hostname The name of the desired host, or null for the local + * @param hostname The name of the desired host, or null for the local * loopback address. * * @return The address of the host as an InetAddress object. @@ -612,11 +612,11 @@ public class InetAddress implements Serializable String hostname = VMInetAddress.getLocalHostname(); try { - return getByName(hostname); + return getByName(hostname); } catch (SecurityException e) { - return LOCALHOST; + return LOCALHOST; } } diff --git a/libjava/classpath/java/net/InetSocketAddress.java b/libjava/classpath/java/net/InetSocketAddress.java index 5267cc11a5d..2126f770324 100644 --- a/libjava/classpath/java/net/InetSocketAddress.java +++ b/libjava/classpath/java/net/InetSocketAddress.java @@ -181,14 +181,14 @@ public class InetSocketAddress extends SocketAddress // The hostname may differ. if (obj instanceof InetSocketAddress) { - InetSocketAddress sa = (InetSocketAddress) obj; - - if (addr == null && sa.addr != null) - return false; - else if (addr == null && sa.addr == null) // we know hostname != null - return hostname.equals(sa.hostname) && sa.port == port; - else - return addr.equals(sa.addr) && sa.port == port; + InetSocketAddress sa = (InetSocketAddress) obj; + + if (addr == null && sa.addr != null) + return false; + else if (addr == null && sa.addr == null) // we know hostname != null + return hostname.equals(sa.hostname) && sa.port == port; + else + return addr.equals(sa.addr) && sa.port == port; } return false; diff --git a/libjava/classpath/java/net/MimeTypeMapper.java b/libjava/classpath/java/net/MimeTypeMapper.java index b0d400cedbf..3e43792911a 100644 --- a/libjava/classpath/java/net/MimeTypeMapper.java +++ b/libjava/classpath/java/net/MimeTypeMapper.java @@ -258,15 +258,15 @@ class MimeTypeMapper implements FileNameMap } } - public static void fillFromFile (Map<String, String> table, String fname) + public static void fillFromFile (Map<String, String> table, String fname) throws IOException { - LineNumberReader reader = + LineNumberReader reader = new LineNumberReader (new FileReader (fname)); while (reader.ready ()) { - StringTokenizer tokenizer = + StringTokenizer tokenizer = new StringTokenizer (reader.readLine ()); try @@ -308,10 +308,10 @@ class MimeTypeMapper implements FileNameMap int index = filename.lastIndexOf("."); if (index != -1) { - if (index == filename.length()) - return "application/octet-stream"; - else - filename = filename.substring(index + 1); + if (index == filename.length()) + return "application/octet-stream"; + else + filename = filename.substring(index + 1); } String type = (String) mime_types.get(filename); @@ -338,7 +338,7 @@ class MimeTypeMapper implements FileNameMap String key = it.next(); String value = map.get(key); // Put the "," first since it is easier to make correct syntax this way. - System.out.println(" " + (first ? " " : ", ") + System.out.println(" " + (first ? " " : ", ") + "{ \"" + key + "\", \"" + value + "\" }"); first = false; } diff --git a/libjava/classpath/java/net/MulticastSocket.java b/libjava/classpath/java/net/MulticastSocket.java index 114d11f2d3c..5014b6a8e53 100644 --- a/libjava/classpath/java/net/MulticastSocket.java +++ b/libjava/classpath/java/net/MulticastSocket.java @@ -202,7 +202,7 @@ public class MulticastSocket extends DatagramSocket { if (isClosed()) throw new SocketException("socket is closed"); - + InetAddress address; if (netIf != null) out: @@ -235,8 +235,8 @@ public class MulticastSocket extends DatagramSocket } else address = InetAddress.ANY_IF; - - + + getImpl().setOption(SocketOptions.IP_MULTICAST_IF, address); } @@ -258,10 +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; @@ -294,7 +294,7 @@ public class MulticastSocket extends DatagramSocket * Checks if local loopback mode is enabled * * @return true if loopback mode is enabled, false otherwise - * + * * @exception SocketException If an error occurs * * @since 1.4 @@ -501,13 +501,13 @@ public class MulticastSocket extends DatagramSocket SecurityManager s = System.getSecurityManager(); if (s != null) { - InetAddress addr = packet.getAddress(); - if (addr.isMulticastAddress()) - s.checkPermission(new SocketPermission(addr.getHostName() - + packet.getPort(), - "accept,connect")); - else - s.checkConnect(addr.getHostAddress(), packet.getPort()); + InetAddress addr = packet.getAddress(); + if (addr.isMulticastAddress()) + s.checkPermission(new SocketPermission(addr.getHostName() + + packet.getPort(), + "accept,connect")); + else + s.checkConnect(addr.getHostAddress(), packet.getPort()); } int oldttl = getImpl().getTimeToLive(); diff --git a/libjava/classpath/java/net/NetworkInterface.java b/libjava/classpath/java/net/NetworkInterface.java index 5ec64ff16ce..127dfba7835 100644 --- a/libjava/classpath/java/net/NetworkInterface.java +++ b/libjava/classpath/java/net/NetworkInterface.java @@ -59,12 +59,12 @@ import java.util.Vector; public final class NetworkInterface { 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 @@ -74,7 +74,7 @@ public final class NetworkInterface { return new NetworkInterface(new VMNetworkInterface()); } - + /** * Returns the name of the network interface * @@ -109,16 +109,16 @@ public final class NetworkInterface for (Enumeration<InetAddress> addresses = inetAddresses.elements(); addresses.hasMoreElements();) { - InetAddress addr = addresses.nextElement(); - try - { - s.checkConnect(addr.getHostAddress(), -1); - tmpInetAddresses.add(addr); - } - catch (SecurityException e) - { - // Ignore. - } + InetAddress addr = addresses.nextElement(); + try + { + s.checkConnect(addr.getHostAddress(), -1); + tmpInetAddresses.add(addr); + } + catch (SecurityException e) + { + // Ignore. + } } return tmpInetAddresses.elements(); @@ -138,7 +138,7 @@ public final class NetworkInterface * Returns an network interface by name * * @param name The name of the interface to return - * + * * @return a <code>NetworkInterface</code> object representing the interface, * or null if there is no interface with that name. * @@ -187,14 +187,14 @@ public final class NetworkInterface * Return an <code>Enumeration</code> of all available network interfaces * * @return all interfaces - * + * * @exception SocketException If an error occurs */ public static Enumeration<NetworkInterface> getNetworkInterfaces() throws SocketException { VMNetworkInterface[] netifs = VMNetworkInterface.getVMInterfaces(); - Vector<NetworkInterface> networkInterfaces = + Vector<NetworkInterface> networkInterfaces = new Vector<NetworkInterface>(netifs.length); for (int i = 0; i < netifs.length; i++) { @@ -217,7 +217,7 @@ public final class NetworkInterface return false; NetworkInterface tmp = (NetworkInterface) obj; - + if (netif.name == null) return tmp.netif.name == null; @@ -234,10 +234,10 @@ public final class NetworkInterface { // FIXME: hash correctly int hc = netif.addresses.hashCode(); - + if (netif.name != null) hc += netif.name.hashCode(); - + return hc; } @@ -253,7 +253,7 @@ public final class NetworkInterface String separator = SystemProperties.getProperty("line.separator"); result = new CPStringBuilder(); - + result.append("name: "); result.append(getDisplayName()); result.append(" (").append(getName()).append(") addresses:"); @@ -261,8 +261,8 @@ public final class NetworkInterface for (Iterator it = netif.addresses.iterator(); it.hasNext(); ) { - InetAddress address = (InetAddress) it.next(); - result.append(address.toString()).append(";").append(separator); + InetAddress address = (InetAddress) it.next(); + result.append(address.toString()).append(";").append(separator); } return result.toString(); diff --git a/libjava/classpath/java/net/Proxy.java b/libjava/classpath/java/net/Proxy.java index 315177413ad..36a25fa801c 100644 --- a/libjava/classpath/java/net/Proxy.java +++ b/libjava/classpath/java/net/Proxy.java @@ -41,7 +41,7 @@ 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 @@ -49,8 +49,8 @@ public class Proxy /** * Represents the proxy type. */ - public enum Type - { + public enum Type + { DIRECT, HTTP, SOCKS; /** @@ -112,8 +112,8 @@ public class Proxy Proxy tmp = (Proxy) obj; return (type.equals(tmp.type) - && (address == null ? tmp.address == null - : address.equals(tmp.address))); + && (address == null ? tmp.address == null + : address.equals(tmp.address))); } /** @@ -134,6 +134,6 @@ public class Proxy public String toString() { return type.toString() + (address == null ? "" - : (":" + address.toString())); + : (":" + address.toString())); } } diff --git a/libjava/classpath/java/net/ProxySelector.java b/libjava/classpath/java/net/ProxySelector.java index 78592a24441..6c85f99c782 100644 --- a/libjava/classpath/java/net/ProxySelector.java +++ b/libjava/classpath/java/net/ProxySelector.java @@ -44,7 +44,7 @@ import java.util.List; /** * Class for handling proxies for different connections. - * + * * @since 1.5 */ public abstract class ProxySelector @@ -100,17 +100,17 @@ public abstract class ProxySelector /** * 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); + 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); diff --git a/libjava/classpath/java/net/ResolverCache.java b/libjava/classpath/java/net/ResolverCache.java index ad329b6075d..d7e5ed407b8 100644 --- a/libjava/classpath/java/net/ResolverCache.java +++ b/libjava/classpath/java/net/ResolverCache.java @@ -119,21 +119,21 @@ class ResolverCache Entry entry = get(key); if (entry != null) { - if (entry.value == null) - throw new UnknownHostException(); - return (String) entry.value; + if (entry.value == null) + throw new UnknownHostException(); + return (String) entry.value; } try { - String hostname = VMInetAddress.getHostByAddr(addr); - put(new Entry(key, hostname)); - return hostname; + String hostname = VMInetAddress.getHostByAddr(addr); + put(new Entry(key, hostname)); + return hostname; } catch (UnknownHostException e) { - put(new Entry(key, null)); - throw e; + put(new Entry(key, null)); + throw e; } } @@ -152,21 +152,21 @@ class ResolverCache Entry entry = get(hostname); if (entry != null) { - if (entry.value == null) - throw new UnknownHostException(); - return (byte[][]) entry.value; + if (entry.value == null) + throw new UnknownHostException(); + return (byte[][]) entry.value; } try { - byte[][] addrs = VMInetAddress.getHostByName(hostname); - put(new Entry(hostname, addrs)); - return addrs; + byte[][] addrs = VMInetAddress.getHostByName(hostname); + put(new Entry(hostname, addrs)); + return addrs; } catch (UnknownHostException e) { - put(new Entry(hostname, null)); - throw e; + put(new Entry(hostname, null)); + throw e; } } @@ -201,9 +201,9 @@ class ResolverCache reap(); if (entry.expires != 0) { - if (entry.expires != -1) - killqueue.add(entry); - cache.put(entry.key, entry); + if (entry.expires != -1) + killqueue.add(entry); + cache.put(entry.key, entry); } } @@ -215,20 +215,20 @@ class ResolverCache { if (!killqueue.isEmpty()) { - long now = System.currentTimeMillis(); + long now = System.currentTimeMillis(); - Iterator iter = killqueue.iterator(); - while (iter.hasNext()) - { - Entry entry = (Entry) iter.next(); - if (entry.expires > now) - break; - cache.remove(entry.key); - iter.remove(); - } + Iterator iter = killqueue.iterator(); + while (iter.hasNext()) + { + Entry entry = (Entry) iter.next(); + if (entry.expires > now) + break; + cache.remove(entry.key); + iter.remove(); + } } } - + /** * An entry in the cache. */ @@ -243,7 +243,7 @@ class ResolverCache * The entry itself. A null value indicates a failed lookup. */ public final Object value; - + /** * The time when this cache entry expires. If set to -1 then * this entry will never expire. If set to 0 then this entry @@ -261,9 +261,9 @@ class ResolverCache int ttl = value != null ? POSITIVE_TTL : NEGATIVE_TTL; if (ttl < 1) - expires = ttl; + expires = ttl; else - expires = System.currentTimeMillis() + ttl * 1000; + expires = System.currentTimeMillis() + ttl * 1000; } } } diff --git a/libjava/classpath/java/net/ServerSocket.java b/libjava/classpath/java/net/ServerSocket.java index fa1c51e75c1..1dbd7636cb5 100644 --- a/libjava/classpath/java/net/ServerSocket.java +++ b/libjava/classpath/java/net/ServerSocket.java @@ -247,8 +247,8 @@ public class ServerSocket try { - impl.bind(addr, port); - impl.listen(backlog); + impl.bind(addr, port); + impl.listen(backlog); this.port = port; local = new InetSocketAddress( (InetAddress) impl.getOption(SocketOptions.SO_BINDADDR), @@ -259,7 +259,7 @@ public class ServerSocket try { if (local == null) - close(); + close(); } catch (IOException _) { @@ -297,7 +297,7 @@ public class ServerSocket * Returns the local socket address * * @return the local socket address, null if not bound - * + * * @since 1.4 */ public SocketAddress getLocalSocketAddress() @@ -326,33 +326,33 @@ public class ServerSocket try { - implAccept(socket); + implAccept(socket); } catch (IOException e) { - try - { - socket.close(); - } - catch (IOException e2) - { - // Ignore. - } - - throw e; + try + { + socket.close(); + } + catch (IOException e2) + { + // Ignore. + } + + throw e; } catch (SecurityException e) { - try - { - socket.close(); - } - catch (IOException e2) - { - // Ignore. - } - - throw e; + try + { + socket.close(); + } + catch (IOException e2) + { + // Ignore. + } + + throw e; } return socket; @@ -391,7 +391,7 @@ public class ServerSocket SecurityManager sm = System.getSecurityManager(); if (sm != null) sm.checkAccept(socket.getInetAddress().getHostAddress(), - socket.getPort()); + socket.getPort()); } /** @@ -416,7 +416,7 @@ public class ServerSocket * by <code>ServerSocketChannel.open()</code>.</p> * * @return the associated socket channel, null if none exists - * + * * @since 1.4 */ public ServerSocketChannel getChannel() @@ -428,7 +428,7 @@ public class ServerSocket * Returns true when the socket is bound, otherwise false * * @return true if socket is bound, false otherwise - * + * * @since 1.4 */ public boolean isBound() @@ -440,7 +440,7 @@ public class ServerSocket * Returns true if the socket is closed, otherwise false * * @return true if socket is closed, false otherwise - * + * * @since 1.4 */ public boolean isClosed() @@ -501,7 +501,7 @@ public class ServerSocket * Enables/Disables the SO_REUSEADDR option * * @param on true if SO_REUSEADDR should be enabled, false otherwise - * + * * @exception SocketException If an error occurs * * @since 1.4 diff --git a/libjava/classpath/java/net/Socket.java b/libjava/classpath/java/net/Socket.java index 7541bdf78c5..d61e81f5e42 100644 --- a/libjava/classpath/java/net/Socket.java +++ b/libjava/classpath/java/net/Socket.java @@ -377,23 +377,23 @@ public class Socket // bind to address/port try { - getImpl().bind(tmp.getAddress(), tmp.getPort()); - bound = true; + getImpl().bind(tmp.getAddress(), tmp.getPort()); + bound = true; } catch (IOException exception) { - close(); - throw exception; + close(); + throw exception; } catch (RuntimeException exception) { - close(); - throw exception; + close(); + throw exception; } catch (Error error) { - close(); - throw error; + close(); + throw error; } } @@ -467,11 +467,11 @@ public class Socket try { - return getImpl().getInetAddress(); + return getImpl().getInetAddress(); } catch (SocketException e) { - // This cannot happen as we are connected. + // This cannot happen as we are connected. } return null; @@ -495,7 +495,7 @@ public class Socket if (impl instanceof PlainSocketImpl) addr = ((PlainSocketImpl) impl).getLocalAddress().getAddress(); - + if (addr == null) { try @@ -536,11 +536,11 @@ public class Socket try { - return getImpl().getPort(); + return getImpl().getPort(); } catch (SocketException e) { - // This cannot happen as we are connected. + // This cannot happen as we are connected. } return 0; @@ -559,12 +559,12 @@ public class Socket try { - if (getImpl() != null) - return getImpl().getLocalPort(); + if (getImpl() != null) + return getImpl().getLocalPort(); } catch (SocketException e) { - // This cannot happen as we are bound. + // This cannot happen as we are bound. } return -1; @@ -586,12 +586,12 @@ public class Socket try { - return new InetSocketAddress(addr, getImpl().getLocalPort()); + return new InetSocketAddress(addr, getImpl().getLocalPort()); } catch (SocketException e) { - // This cannot happen as we are bound. - return null; + // This cannot happen as we are bound. + return null; } } @@ -609,13 +609,13 @@ public class Socket try { - return new InetSocketAddress(getImpl().getInetAddress(), - getImpl().getPort()); + return new InetSocketAddress(getImpl().getInetAddress(), + getImpl().getPort()); } catch (SocketException e) { - // This cannot happen as we are connected. - return null; + // This cannot happen as we are connected. + return null; } } @@ -721,13 +721,13 @@ public class Socket if (on) { - if (linger < 0) - throw new IllegalArgumentException("SO_LINGER must be >= 0"); + if (linger < 0) + throw new IllegalArgumentException("SO_LINGER must be >= 0"); - if (linger > 65535) - linger = 65535; + if (linger > 65535) + linger = 65535; - getImpl().setOption(SocketOptions.SO_LINGER, Integer.valueOf(linger)); + getImpl().setOption(SocketOptions.SO_LINGER, Integer.valueOf(linger)); } else getImpl().setOption(SocketOptions.SO_LINGER, Integer.valueOf(-1)); @@ -1034,15 +1034,15 @@ public class Socket { try { - if (isConnected()) - return (super.toString() + if (isConnected()) + return (super.toString() + " [addr=" + getImpl().getInetAddress() + ",port=" - + getImpl().getPort() + ",localport=" - + getImpl().getLocalPort() + "]"); + + getImpl().getPort() + ",localport=" + + getImpl().getLocalPort() + "]"); } catch (SocketException e) { - // This cannot happen as we are connected. + // This cannot happen as we are connected. } return super.toString() + " [unconnected]"; @@ -1225,7 +1225,7 @@ public class Socket { if (impl == null) return false; - + return impl.getInetAddress() != null; } @@ -1242,7 +1242,7 @@ public class Socket return false; if (impl instanceof PlainSocketImpl) { - InetSocketAddress addr = ((PlainSocketImpl) impl).getLocalAddress(); + InetSocketAddress addr = ((PlainSocketImpl) impl).getLocalAddress(); return addr != null && addr.getAddress() != null; } return bound; @@ -1258,7 +1258,7 @@ public class Socket public boolean isClosed() { SocketChannel channel = getChannel(); - + return impl == null || (channel != null && ! channel.isOpen()); } diff --git a/libjava/classpath/java/net/SocketPermission.java b/libjava/classpath/java/net/SocketPermission.java index a5a848eee7a..ce16a79a078 100644 --- a/libjava/classpath/java/net/SocketPermission.java +++ b/libjava/classpath/java/net/SocketPermission.java @@ -127,9 +127,9 @@ public final class SocketPermission extends Permission implements Serializable /** * An IP address (IPv4 or IPv6). Will be set if and only if this * object was initialized with a single literal IP address. - */ + */ private transient InetAddress address = null; - + /** * A range of ports. */ @@ -199,39 +199,39 @@ public final class SocketPermission extends Permission implements Serializable boolean colon_allowed = true; for (int i = 0; i < hostport.length(); i++) { - if (hostport.charAt(i) == ':') - { - if (!colon_allowed) - throw new IllegalArgumentException("Ambiguous hostport part"); - colons++; - colon_allowed = false; - } - else - colon_allowed = true; + if (hostport.charAt(i) == ':') + { + if (!colon_allowed) + throw new IllegalArgumentException("Ambiguous hostport part"); + colons++; + colon_allowed = false; + } + else + colon_allowed = true; } switch (colons) { case 0: case 1: - // a hostname or IPv4 address - return hostport; - + // a hostname or IPv4 address + return hostport; + case 7: - // an IPv6 address with no ports - return "[" + hostport + "]"; + // an IPv6 address with no ports + return "[" + hostport + "]"; case 8: - // an IPv6 address with ports - int last_colon = hostport.lastIndexOf(':'); - return "[" + hostport.substring(0, last_colon) + "]" - + hostport.substring(last_colon); + // an IPv6 address with ports + int last_colon = hostport.lastIndexOf(':'); + return "[" + hostport.substring(0, last_colon) + "]" + + hostport.substring(last_colon); default: - throw new IllegalArgumentException("Ambiguous hostport part"); + throw new IllegalArgumentException("Ambiguous hostport part"); } } - + /** * Parse the hostport argument to the constructor. */ @@ -241,90 +241,90 @@ public final class SocketPermission extends Permission implements Serializable String host, ports; if (hostport.charAt(0) == '[') { - // host is a bracketed IPv6 address - int end = hostport.indexOf("]"); - if (end == -1) - throw new IllegalArgumentException("Unmatched '['"); - host = hostport.substring(1, end); - - address = InetAddress.getByLiteral(host); - if (address == null) - throw new IllegalArgumentException("Bad IPv6 address"); - - if (end == hostport.length() - 1) - ports = ""; - else if (hostport.charAt(end + 1) == ':') - ports = hostport.substring(end + 2); - else - throw new IllegalArgumentException("Bad character after ']'"); + // host is a bracketed IPv6 address + int end = hostport.indexOf("]"); + if (end == -1) + throw new IllegalArgumentException("Unmatched '['"); + host = hostport.substring(1, end); + + address = InetAddress.getByLiteral(host); + if (address == null) + throw new IllegalArgumentException("Bad IPv6 address"); + + if (end == hostport.length() - 1) + ports = ""; + else if (hostport.charAt(end + 1) == ':') + ports = hostport.substring(end + 2); + else + throw new IllegalArgumentException("Bad character after ']'"); } else { - // host is a hostname or IPv4 address - int sep = hostport.indexOf(":"); - if (sep == -1) - { - host = hostport; - ports = ""; - } - else - { - host = hostport.substring(0, sep); - ports = hostport.substring(sep + 1); - } - - address = InetAddress.getByLiteral(host); - if (address == null) - { - if (host.lastIndexOf('*') > 0) - throw new IllegalArgumentException("Bad hostname"); - - hostname = host; - } + // host is a hostname or IPv4 address + int sep = hostport.indexOf(":"); + if (sep == -1) + { + host = hostport; + ports = ""; + } + else + { + host = hostport.substring(0, sep); + ports = hostport.substring(sep + 1); + } + + address = InetAddress.getByLiteral(host); + if (address == null) + { + if (host.lastIndexOf('*') > 0) + throw new IllegalArgumentException("Bad hostname"); + + hostname = host; + } } // Parse and validate the ports if (ports.length() == 0) { - minport = MIN_PORT; - maxport = MAX_PORT; + minport = MIN_PORT; + maxport = MAX_PORT; } else { - int sep = ports.indexOf("-"); - if (sep == -1) - { - // a single port - minport = maxport = Integer.parseInt(ports); - } - else - { - if (ports.indexOf("-", sep + 1) != -1) - throw new IllegalArgumentException("Unexpected '-'"); - - if (sep == 0) - { - // an upper bound - minport = MIN_PORT; - maxport = Integer.parseInt(ports.substring(1)); - } - else if (sep == ports.length() - 1) - { - // a lower bound - minport = - Integer.parseInt(ports.substring(0, ports.length() - 1)); - maxport = MAX_PORT; - } - else - { - // a range with two bounds - minport = Integer.parseInt(ports.substring(0, sep)); - maxport = Integer.parseInt(ports.substring(sep + 1)); - } - } + int sep = ports.indexOf("-"); + if (sep == -1) + { + // a single port + minport = maxport = Integer.parseInt(ports); + } + else + { + if (ports.indexOf("-", sep + 1) != -1) + throw new IllegalArgumentException("Unexpected '-'"); + + if (sep == 0) + { + // an upper bound + minport = MIN_PORT; + maxport = Integer.parseInt(ports.substring(1)); + } + else if (sep == ports.length() - 1) + { + // a lower bound + minport = + Integer.parseInt(ports.substring(0, ports.length() - 1)); + maxport = MAX_PORT; + } + else + { + // a range with two bounds + minport = Integer.parseInt(ports.substring(0, sep)); + maxport = Integer.parseInt(ports.substring(sep + 1)); + } + } } } - + /** * Parse the actions argument to the constructor. */ @@ -334,18 +334,18 @@ public final class SocketPermission extends Permission implements Serializable boolean resolve_needed = false; boolean resolve_present = false; - + StringTokenizer t = new StringTokenizer(actionstring, ","); while (t.hasMoreTokens()) { - String action = t.nextToken(); - action = action.trim().toLowerCase(); - setAction(action); - - if (action.equals("resolve")) - resolve_present = true; - else - resolve_needed = true; + String action = t.nextToken(); + action = action.trim().toLowerCase(); + setAction(action); + + if (action.equals("resolve")) + resolve_present = true; + else + resolve_needed = true; } if (resolve_needed && !resolve_present) @@ -359,11 +359,11 @@ public final class SocketPermission extends Permission implements Serializable { for (int i = 0; i < ACTIONS.length; i++) { - if (action.equals(ACTIONS[i])) - { - actionmask |= 1 << i; - return; - } + if (action.equals(ACTIONS[i])) + { + actionmask |= 1 << i; + return; + } } throw new IllegalArgumentException("Unknown action " + action); } @@ -389,23 +389,23 @@ public final class SocketPermission extends Permission implements Serializable return false; if (p.actionmask != actionmask || - p.minport != minport || - p.maxport != maxport) + p.minport != minport || + p.maxport != maxport) return false; if (address != null) { - if (p.address == null) - return false; - else - return p.address.equals(address); + if (p.address == null) + return false; + else + return p.address.equals(address); } else { - if (p.hostname == null) - return false; - else - return p.hostname.equals(hostname); + if (p.hostname == null) + return false; + else + return p.hostname.equals(hostname); } } @@ -437,12 +437,12 @@ public final class SocketPermission extends Permission implements Serializable for (int i = 0; i < ACTIONS.length; i++) { - if ((actionmask & (1 << i)) != 0) - { - if (sb.length() != 0) - sb.append(","); - sb.append(ACTIONS[i]); - } + if ((actionmask & (1 << i)) != 0) + { + if (sb.length() != 0) + sb.append(","); + sb.append(ACTIONS[i]); + } } return sb.toString(); @@ -471,11 +471,11 @@ public final class SocketPermission extends Permission implements Serializable try { - return InetAddress.getAllByName(hostname); + return InetAddress.getAllByName(hostname); } catch (UnknownHostException e) { - return new InetAddress[0]; + return new InetAddress[0]; } } @@ -491,18 +491,18 @@ public final class SocketPermission extends Permission implements Serializable return null; try { - return InetAddress.getByName(hostname).internalGetCanonicalHostName(); + return InetAddress.getByName(hostname).internalGetCanonicalHostName(); } catch (UnknownHostException e) { - return null; + return null; } } - + /** * Returns true if the permission object passed it is implied by the * this permission. This will be true if: - * + * * <ul> * <li>The argument is of type <code>SocketPermission</code></li> * <li>The actions list of the argument are in this object's actions</li> @@ -511,7 +511,7 @@ public final class SocketPermission extends Permission implements Serializable * </ul> * * <p>The argument's hostname will be a subset of this object's hostname if:</p> - * + * * <ul> * <li>The argument's hostname or IP address is equal to this object's.</li> * <li>The argument's canonical hostname is equal to this object's.</li> @@ -538,10 +538,10 @@ public final class SocketPermission extends Permission implements Serializable // imply it. This is not part of the spec, but it seems necessary. if (p.hostname != null && p.hostname.length() == 0) return false; - + // Next check the actions if ((p.actionmask & actionmask) != p.actionmask) - return false; + return false; // Then check the ports if ((p.minport < minport) || (p.maxport > maxport)) @@ -554,49 +554,49 @@ public final class SocketPermission extends Permission implements Serializable // IP address which one of p's IP addresses is equal to. if (address != null) { - InetAddress[] addrs = p.getAddresses(); - for (int i = 0; i < addrs.length; i++) - { - if (address.equals(addrs[i])) - return true; - } + InetAddress[] addrs = p.getAddresses(); + for (int i = 0; i < addrs.length; i++) + { + if (address.equals(addrs[i])) + return true; + } } // Return true if this object is a wildcarded domain that // p's canonical name matches. if (hostname != null && hostname.charAt(0) == '*') { - p_canon = p.getCanonicalHostName(); - if (p_canon != null && p_canon.endsWith(hostname.substring(1))) - return true; - + p_canon = p.getCanonicalHostName(); + if (p_canon != null && p_canon.endsWith(hostname.substring(1))) + return true; + } // Return true if this one of this object's IP addresses // is equal to one of p's. if (address == null) { - InetAddress[] addrs = p.getAddresses(); - InetAddress[] p_addrs = p.getAddresses(); - - for (int i = 0; i < addrs.length; i++) - { - for (int j = 0; j < p_addrs.length; j++) - { - if (addrs[i].equals(p_addrs[j])) - return true; - } - } + InetAddress[] addrs = p.getAddresses(); + InetAddress[] p_addrs = p.getAddresses(); + + for (int i = 0; i < addrs.length; i++) + { + for (int j = 0; j < p_addrs.length; j++) + { + if (addrs[i].equals(p_addrs[j])) + return true; + } + } } // Return true if this object's canonical name equals p's. String canon = getCanonicalHostName(); if (canon != null) { - if (p_canon == null) - p_canon = p.getCanonicalHostName(); - if (p_canon != null && canon.equals(p_canon)) - return true; + if (p_canon == null) + p_canon = p.getCanonicalHostName(); + if (p_canon != null && canon.equals(p_canon)) + return true; } // Didn't make it diff --git a/libjava/classpath/java/net/URI.java b/libjava/classpath/java/net/URI.java index 933e4f451f0..b5fb9654fec 100644 --- a/libjava/classpath/java/net/URI.java +++ b/libjava/classpath/java/net/URI.java @@ -49,7 +49,7 @@ import java.util.regex.Pattern; /** * <p> - * A URI instance represents that defined by + * A URI instance represents that defined by * <a href="http://www.ietf.org/rfc/rfc3986.txt">RFC3986</a>, * with some deviations. * </p> @@ -157,7 +157,7 @@ import java.util.regex.Pattern; * @author Andrew John Hughes (gnu_andrew@member.fsf.org) * @since 1.4 */ -public final class URI +public final class URI implements Comparable<URI>, Serializable { /** @@ -193,7 +193,7 @@ public final class URI private static final String RFC3986_SUBDELIMS = "!$&'()*+,;="; private static final String RFC3986_REG_NAME = RFC3986_UNRESERVED + RFC3986_SUBDELIMS + "%"; - private static final String RFC3986_PCHAR = RFC3986_UNRESERVED + + private static final String RFC3986_PCHAR = RFC3986_UNRESERVED + RFC3986_SUBDELIMS + ":@%"; private static final String RFC3986_SEGMENT = RFC3986_PCHAR; private static final String RFC3986_PATH_SEGMENTS = RFC3986_SEGMENT + "/"; @@ -230,7 +230,7 @@ public final class URI * Index of fragment component in parsed URI. */ private static final int FRAGMENT_GROUP = 10; - + /** * Index of userinfo component in parsed authority section. */ @@ -294,19 +294,19 @@ public final class URI this.string = (String) is.readObject(); try { - parseURI(this.string); + parseURI(this.string); } catch (URISyntaxException x) { - // Should not happen. - throw new RuntimeException(x); + // Should not happen. + throw new RuntimeException(x); } } private void writeObject(ObjectOutputStream os) throws IOException { if (string == null) - string = toString(); + string = toString(); os.writeObject(string); } @@ -350,11 +350,11 @@ public final class URI String matched = match.group(group); if (matched == null || matched.length() == 0) { - String prevMatched = match.group(group -1); - if (prevMatched == null || prevMatched.length() == 0) - return null; - else - return ""; + String prevMatched = match.group(group -1); + if (prevMatched == null || prevMatched.length() == 0) + return null; + else + return ""; } return matched; } @@ -369,23 +369,23 @@ public final class URI private void parseURI(String str) throws URISyntaxException { Matcher matcher = URI_PATTERN.matcher(str); - + if (matcher.matches()) { - scheme = getURIGroup(matcher, SCHEME_GROUP); - rawSchemeSpecificPart = matcher.group(SCHEME_SPEC_PART_GROUP); - schemeSpecificPart = unquote(rawSchemeSpecificPart); - if (!isOpaque()) - { - rawAuthority = getURIGroup(matcher, AUTHORITY_GROUP); - rawPath = matcher.group(PATH_GROUP); - rawQuery = getURIGroup(matcher, QUERY_GROUP); - } - rawFragment = getURIGroup(matcher, FRAGMENT_GROUP); + scheme = getURIGroup(matcher, SCHEME_GROUP); + rawSchemeSpecificPart = matcher.group(SCHEME_SPEC_PART_GROUP); + schemeSpecificPart = unquote(rawSchemeSpecificPart); + if (!isOpaque()) + { + rawAuthority = getURIGroup(matcher, AUTHORITY_GROUP); + rawPath = matcher.group(PATH_GROUP); + rawQuery = getURIGroup(matcher, QUERY_GROUP); + } + rawFragment = getURIGroup(matcher, FRAGMENT_GROUP); } else throw new URISyntaxException(str, - "doesn't match URI regular expression"); + "doesn't match URI regular expression"); parseServerAuthority(); // We must eagerly unquote the parts, because this is the only time @@ -416,27 +416,27 @@ public final class URI int pos = 0; for (int i = 0; i < str.length(); i++) { - char c = str.charAt(i); - if (c == '%') - { - if (i + 2 >= str.length()) - throw new URISyntaxException(str, "Invalid quoted character"); - int hi = Character.digit(str.charAt(++i), 16); - int lo = Character.digit(str.charAt(++i), 16); - if (lo < 0 || hi < 0) - throw new URISyntaxException(str, "Invalid quoted character"); - buf[pos++] = (byte) (hi * 16 + lo); - } - else - buf[pos++] = (byte) c; + char c = str.charAt(i); + if (c == '%') + { + if (i + 2 >= str.length()) + throw new URISyntaxException(str, "Invalid quoted character"); + int hi = Character.digit(str.charAt(++i), 16); + int lo = Character.digit(str.charAt(++i), 16); + if (lo < 0 || hi < 0) + throw new URISyntaxException(str, "Invalid quoted character"); + buf[pos++] = (byte) (hi * 16 + lo); + } + else + buf[pos++] = (byte) c; } try { - return new String(buf, 0, pos, "utf-8"); + return new String(buf, 0, pos, "utf-8"); } catch (java.io.UnsupportedEncodingException x2) { - throw (Error) new InternalError().initCause(x2); + throw (Error) new InternalError().initCause(x2); } } @@ -488,16 +488,16 @@ public final class URI CPStringBuilder sb = new CPStringBuilder(str.length()); for (int i = 0; i < str.length(); i++) { - char c = str.charAt(i); - if ((legalCharacters.indexOf(c) == -1) - && (c <= 127)) - { - sb.append('%'); - sb.append(HEX.charAt(c / 16)); - sb.append(HEX.charAt(c % 16)); - } - else - sb.append(c); + char c = str.charAt(i); + if ((legalCharacters.indexOf(c) == -1) + && (c <= 127)) + { + sb.append('%'); + sb.append(HEX.charAt(c / 16)); + sb.append(HEX.charAt(c % 16)); + } + else + sb.append(c); } return sb.toString(); } @@ -659,12 +659,12 @@ public final class URI { try { - return new URI(str); + return new URI(str); } catch (URISyntaxException e) { - throw (IllegalArgumentException) new IllegalArgumentException() - .initCause(e); + throw (IllegalArgumentException) new IllegalArgumentException() + .initCause(e); } } @@ -686,32 +686,32 @@ public final class URI { if (rawAuthority != null) { - Matcher matcher = AUTHORITY_PATTERN.matcher(rawAuthority); - - if (matcher.matches()) - { - rawUserInfo = getURIGroup(matcher, AUTHORITY_USERINFO_GROUP); - rawHost = getURIGroup(matcher, AUTHORITY_HOST_GROUP); - - String portStr = getURIGroup(matcher, AUTHORITY_PORT_GROUP); - - if (portStr != null && ! portStr.isEmpty()) - try - { - port = Integer.parseInt(portStr); - } - catch (NumberFormatException e) - { - URISyntaxException use = - new URISyntaxException - (string, "doesn't match URI regular expression"); - use.initCause(e); - throw use; - } - } - else - throw new URISyntaxException(string, - "doesn't match URI regular expression"); + Matcher matcher = AUTHORITY_PATTERN.matcher(rawAuthority); + + if (matcher.matches()) + { + rawUserInfo = getURIGroup(matcher, AUTHORITY_USERINFO_GROUP); + rawHost = getURIGroup(matcher, AUTHORITY_HOST_GROUP); + + String portStr = getURIGroup(matcher, AUTHORITY_PORT_GROUP); + + if (portStr != null && ! portStr.isEmpty()) + try + { + port = Integer.parseInt(portStr); + } + catch (NumberFormatException e) + { + URISyntaxException use = + new URISyntaxException + (string, "doesn't match URI regular expression"); + use.initCause(e); + throw use; + } + } + else + throw new URISyntaxException(string, + "doesn't match URI regular expression"); } return this; } @@ -744,13 +744,13 @@ public final class URI return this; try { - return new URI(scheme, authority, normalizePath(path), query, - fragment); + return new URI(scheme, authority, normalizePath(path), query, + fragment); } catch (URISyntaxException e) { - throw (Error) new InternalError("Normalized URI variant could not "+ - "be constructed").initCause(e); + throw (Error) new InternalError("Normalized URI variant could not "+ + "be constructed").initCause(e); } } @@ -770,13 +770,13 @@ public final class URI * The resulting URI will be free of `.' and `..' segments, barring those * that were prepended or which couldn't be paired, respectively. * </p> - * + * * @param relativePath the relative path to be normalized. * @return the normalized path. */ private String normalizePath(String relativePath) { - /* + /* This follows the algorithm in section 5.2.4. of RFC3986, but doesn't modify the input buffer. */ @@ -785,66 +785,66 @@ public final class URI int start = 0; while (start < input.length()) { - /* A */ - if (input.indexOf("../",start) == start) - { - start += 3; - continue; - } - if (input.indexOf("./",start) == start) - { - start += 2; - continue; - } - /* B */ - if (input.indexOf("/./",start) == start) - { - start += 2; - continue; - } - if (input.indexOf("/.",start) == start - && input.charAt(start + 2) != '.') - { - start += 1; - input.setCharAt(start,'/'); - continue; - } - /* C */ - if (input.indexOf("/../",start) == start) - { - start += 3; - removeLastSegment(output); - continue; - } - if (input.indexOf("/..",start) == start) - { - start += 2; - input.setCharAt(start,'/'); - removeLastSegment(output); - continue; - } - /* D */ - if (start == input.length() - 1 && input.indexOf(".",start) == start) - { - input.delete(0,1); - continue; - } - if (start == input.length() - 2 && input.indexOf("..",start) == start) - { - input.delete(0,2); - continue; - } - /* E */ - int indexOfSlash = input.indexOf("/",start); - while (indexOfSlash == start) - { - output.append("/"); - ++start; - indexOfSlash = input.indexOf("/",start); - } - if (indexOfSlash == -1) - indexOfSlash = input.length(); - output.append(input.substring(start, indexOfSlash)); + /* A */ + if (input.indexOf("../",start) == start) + { + start += 3; + continue; + } + if (input.indexOf("./",start) == start) + { + start += 2; + continue; + } + /* B */ + if (input.indexOf("/./",start) == start) + { + start += 2; + continue; + } + if (input.indexOf("/.",start) == start + && input.charAt(start + 2) != '.') + { + start += 1; + input.setCharAt(start,'/'); + continue; + } + /* C */ + if (input.indexOf("/../",start) == start) + { + start += 3; + removeLastSegment(output); + continue; + } + if (input.indexOf("/..",start) == start) + { + start += 2; + input.setCharAt(start,'/'); + removeLastSegment(output); + continue; + } + /* D */ + if (start == input.length() - 1 && input.indexOf(".",start) == start) + { + input.delete(0,1); + continue; + } + if (start == input.length() - 2 && input.indexOf("..",start) == start) + { + input.delete(0,2); + continue; + } + /* E */ + int indexOfSlash = input.indexOf("/",start); + while (indexOfSlash == start) + { + output.append("/"); + ++start; + indexOfSlash = input.indexOf("/",start); + } + if (indexOfSlash == -1) + indexOfSlash = input.length(); + output.append(input.substring(start, indexOfSlash)); start = indexOfSlash; } return output.toString(); @@ -890,33 +890,33 @@ public final class URI try { - if (fragment != null && path != null && path.equals("") - && scheme == null && authority == null && query == null) - return new URI(this.scheme, this.schemeSpecificPart, fragment); - - if (authority == null) - { - authority = this.authority; - if (path == null) - path = ""; - if (! (path.startsWith("/"))) - { - CPStringBuilder basepath = new CPStringBuilder(this.path); - int i = this.path.lastIndexOf('/'); - - if (i >= 0) - basepath.delete(i + 1, basepath.length()); - - basepath.append(path); - path = normalizePath(basepath.toString()); - } - } - return new URI(this.scheme, authority, path, query, fragment); + if (fragment != null && path != null && path.equals("") + && scheme == null && authority == null && query == null) + return new URI(this.scheme, this.schemeSpecificPart, fragment); + + if (authority == null) + { + authority = this.authority; + if (path == null) + path = ""; + if (! (path.startsWith("/"))) + { + CPStringBuilder basepath = new CPStringBuilder(this.path); + int i = this.path.lastIndexOf('/'); + + if (i >= 0) + basepath.delete(i + 1, basepath.length()); + + basepath.append(path); + path = normalizePath(basepath.toString()); + } + } + return new URI(this.scheme, authority, path, query, fragment); } catch (URISyntaxException e) { - throw (Error) new InternalError("Resolved URI variant could not "+ - "be constructed").initCause(e); + throw (Error) new InternalError("Resolved URI variant could not "+ + "be constructed").initCause(e); } } @@ -973,21 +973,21 @@ public final class URI String basePath = rawPath; if (!(uri.getRawPath().equals(rawPath))) { - if (!(basePath.endsWith("/"))) - basePath = basePath.concat("/"); - if (!(uri.getRawPath().startsWith(basePath))) - return uri; + if (!(basePath.endsWith("/"))) + basePath = basePath.concat("/"); + if (!(uri.getRawPath().startsWith(basePath))) + return uri; } try { - return new URI(null, null, - uri.getRawPath().substring(basePath.length()), - uri.getRawQuery(), uri.getRawFragment()); + return new URI(null, null, + uri.getRawPath().substring(basePath.length()), + uri.getRawQuery(), uri.getRawFragment()); } catch (URISyntaxException e) { - throw (Error) new InternalError("Relativized URI variant could not "+ - "be constructed").initCause(e); + throw (Error) new InternalError("Relativized URI variant could not "+ + "be constructed").initCause(e); } } @@ -1144,7 +1144,7 @@ public final class URI } /** - * <p> + * <p> * Compares the URI with the given object for equality. If the * object is not a <code>URI</code>, then the method returns false. * Otherwise, the following criteria are observed: @@ -1187,40 +1187,40 @@ public final class URI URI uriObj = (URI) obj; if (scheme == null) { - if (uriObj.getScheme() != null) - return false; + if (uriObj.getScheme() != null) + return false; } else if (!(scheme.equalsIgnoreCase(uriObj.getScheme()))) - return false; + return false; if (rawFragment == null) { - if (uriObj.getRawFragment() != null) - return false; + if (uriObj.getRawFragment() != null) + return false; } else if (!(rawFragment.equalsIgnoreCase(uriObj.getRawFragment()))) - return false; + return false; boolean opaqueThis = isOpaque(); boolean opaqueObj = uriObj.isOpaque(); if (opaqueThis && opaqueObj) return rawSchemeSpecificPart.equals(uriObj.getRawSchemeSpecificPart()); else if (!opaqueThis && !opaqueObj) { - boolean common = rawPath.equalsIgnoreCase(uriObj.getRawPath()) - && ((rawQuery == null && uriObj.getRawQuery() == null) - || rawQuery.equalsIgnoreCase(uriObj.getRawQuery())); - if (rawAuthority == null && uriObj.getRawAuthority() == null) - return common; - if (host == null) - return common - && rawAuthority.equalsIgnoreCase(uriObj.getRawAuthority()); - return common - && host.equalsIgnoreCase(uriObj.getHost()) - && port == uriObj.getPort() - && (rawUserInfo == null ? - uriObj.getRawUserInfo() == null : - rawUserInfo.equalsIgnoreCase(uriObj.getRawUserInfo())); + boolean common = rawPath.equalsIgnoreCase(uriObj.getRawPath()) + && ((rawQuery == null && uriObj.getRawQuery() == null) + || rawQuery.equalsIgnoreCase(uriObj.getRawQuery())); + if (rawAuthority == null && uriObj.getRawAuthority() == null) + return common; + if (host == null) + return common + && rawAuthority.equalsIgnoreCase(uriObj.getRawAuthority()); + return common + && host.equalsIgnoreCase(uriObj.getHost()) + && port == uriObj.getPort() + && (rawUserInfo == null ? + uriObj.getRawUserInfo() == null : + rawUserInfo.equalsIgnoreCase(uriObj.getRawUserInfo())); } else return false; @@ -1278,16 +1278,16 @@ public final class URI * on whether this URI is less than, equal to or greater * than that supplied, respectively. */ - public int compareTo(URI uri) + public int compareTo(URI uri) throws ClassCastException { if (scheme == null && uri.getScheme() != null) return -1; if (scheme != null) { - int sCompare = scheme.compareToIgnoreCase(uri.getScheme()); - if (sCompare != 0) - return sCompare; + int sCompare = scheme.compareToIgnoreCase(uri.getScheme()); + if (sCompare != 0) + return sCompare; } boolean opaqueThis = isOpaque(); boolean opaqueObj = uri.isOpaque(); @@ -1297,51 +1297,51 @@ public final class URI return -1; if (opaqueThis) { - int ssCompare = - rawSchemeSpecificPart.compareTo(uri.getRawSchemeSpecificPart()); - if (ssCompare == 0) - return compareFragments(uri); - else - return ssCompare; + int ssCompare = + rawSchemeSpecificPart.compareTo(uri.getRawSchemeSpecificPart()); + if (ssCompare == 0) + return compareFragments(uri); + else + return ssCompare; } if (rawAuthority == null && uri.getRawAuthority() != null) return -1; if (rawAuthority != null) { - int aCompare = rawAuthority.compareTo(uri.getRawAuthority()); - if (aCompare != 0) - { - if (host == null) - return aCompare; - if (rawUserInfo == null && uri.getRawUserInfo() != null) - return -1; - int uCompare = rawUserInfo.compareTo(uri.getRawUserInfo()); - if (uCompare != 0) - return uCompare; - if (host == null && uri.getHost() != null) - return -1; - int hCompare = host.compareTo(uri.getHost()); - if (hCompare != 0) - return hCompare; - int uriPort = uri.getPort(); - return (uriPort == port) ? 0 : (uriPort > port) ? -1 : 1; - } + int aCompare = rawAuthority.compareTo(uri.getRawAuthority()); + if (aCompare != 0) + { + if (host == null) + return aCompare; + if (rawUserInfo == null && uri.getRawUserInfo() != null) + return -1; + int uCompare = rawUserInfo.compareTo(uri.getRawUserInfo()); + if (uCompare != 0) + return uCompare; + if (host == null && uri.getHost() != null) + return -1; + int hCompare = host.compareTo(uri.getHost()); + if (hCompare != 0) + return hCompare; + int uriPort = uri.getPort(); + return (uriPort == port) ? 0 : (uriPort > port) ? -1 : 1; + } } if (rawPath == null && uri.getRawPath() != null) return -1; if (rawPath != null) { - int pCompare = rawPath.compareTo(uri.getRawPath()); - if (pCompare != 0) - return pCompare; + int pCompare = rawPath.compareTo(uri.getRawPath()); + if (pCompare != 0) + return pCompare; } if (rawQuery == null && uri.getRawQuery() != null) return -1; if (rawQuery != null) { - int qCompare = rawQuery.compareTo(uri.getRawQuery()); - if (qCompare != 0) - return qCompare; + int qCompare = rawQuery.compareTo(uri.getRawQuery()); + if (qCompare != 0) + return qCompare; } return compareFragments(uri); } @@ -1394,25 +1394,25 @@ public final class URI CPStringBuilder encBuffer = null; for (int i = 0; i < strRep.length(); i++) { - char c = strRep.charAt(i); - if (c <= 127) - { - if (inNonAsciiBlock) - { - buffer.append(escapeCharacters(encBuffer.toString())); - inNonAsciiBlock = false; - } - buffer.append(c); - } - else - { - if (!inNonAsciiBlock) - { - encBuffer = new CPStringBuilder(); - inNonAsciiBlock = true; - } - encBuffer.append(c); - } + char c = strRep.charAt(i); + if (c <= 127) + { + if (inNonAsciiBlock) + { + buffer.append(escapeCharacters(encBuffer.toString())); + inNonAsciiBlock = false; + } + buffer.append(c); + } + else + { + if (!inNonAsciiBlock) + { + encBuffer = new CPStringBuilder(); + inNonAsciiBlock = true; + } + encBuffer.append(c); + } } return buffer.toString(); } @@ -1430,20 +1430,20 @@ public final class URI { try { - CPStringBuilder sb = new CPStringBuilder(); - // this is far from optimal, but it works - byte[] utf8 = str.getBytes("utf-8"); - for (int j = 0; j < utf8.length; j++) - { - sb.append('%'); - sb.append(HEX.charAt((utf8[j] & 0xff) / 16)); - sb.append(HEX.charAt((utf8[j] & 0xff) % 16)); - } - return sb.toString(); + CPStringBuilder sb = new CPStringBuilder(); + // this is far from optimal, but it works + byte[] utf8 = str.getBytes("utf-8"); + for (int j = 0; j < utf8.length; j++) + { + sb.append('%'); + sb.append(HEX.charAt((utf8[j] & 0xff) / 16)); + sb.append(HEX.charAt((utf8[j] & 0xff) % 16)); + } + return sb.toString(); } catch (java.io.UnsupportedEncodingException x) { - throw (Error) new InternalError("Escaping error").initCause(x); + throw (Error) new InternalError("Escaping error").initCause(x); } } diff --git a/libjava/classpath/java/net/URL.java b/libjava/classpath/java/net/URL.java index 16a606fbc7e..1b778b40a4b 100644 --- a/libjava/classpath/java/net/URL.java +++ b/libjava/classpath/java/net/URL.java @@ -203,9 +203,9 @@ public final class URL implements Serializable String s = SystemProperties.getProperty("gnu.java.net.nocache_protocol_handlers"); if (s == null) - cache_handlers = true; + cache_handlers = true; else - cache_handlers = false; + cache_handlers = false; } /** @@ -276,11 +276,11 @@ public final class URL implements Serializable if (ph != null) { - SecurityManager s = System.getSecurityManager(); - if (s != null) - s.checkPermission(new NetPermission("specifyStreamHandler")); + SecurityManager s = System.getSecurityManager(); + if (s != null) + s.checkPermission(new NetPermission("specifyStreamHandler")); - this.ph = ph; + this.ph = ph; } else this.ph = getURLStreamHandler(protocol); @@ -293,18 +293,18 @@ public final class URL implements Serializable this.port = port; this.authority = (host != null) ? host : ""; if (port >= 0 && host != null) - this.authority += ":" + port; + this.authority += ":" + port; int hashAt = file.indexOf('#'); if (hashAt < 0) { - this.file = file; - this.ref = null; + this.file = file; + this.ref = null; } else { - this.file = file.substring(0, hashAt); - this.ref = file.substring(hashAt + 1); + this.file = file.substring(0, hashAt); + this.ref = file.substring(hashAt + 1); } hashCode = hashCode(); // Used for serialization. } @@ -324,7 +324,7 @@ public final class URL implements Serializable public URL(String spec) throws MalformedURLException { this((URL) null, spec != null ? spec : "", (URLStreamHandler) null, - false); + false); } /** @@ -346,8 +346,8 @@ public final class URL implements Serializable public URL(URL context, String spec) throws MalformedURLException { this(context, spec, - (context == null) ? (URLStreamHandler) null : context.ph, - false); + (context == null) ? (URLStreamHandler) null : context.ph, + false); } /** @@ -395,7 +395,7 @@ public final class URL implements Serializable * */ private URL(URL context, String spec, URLStreamHandler ph, - boolean phFromUser) + boolean phFromUser) throws MalformedURLException { /* A protocol is defined by the doc as the substring before a ':' @@ -416,12 +416,12 @@ public final class URL implements Serializable int colon; int slash = spec.indexOf('/'); if ((colon = spec.indexOf("://", 1)) > 0 - && ((colon < slash || slash < 0)) + && ((colon < slash || slash < 0)) && ! spec.regionMatches(colon, "://:", 0, 4)) { - context = null; - if (! phFromUser) - ph = null; + context = null; + if (! phFromUser) + ph = null; } boolean protocolSpecified = false; @@ -429,10 +429,10 @@ public final class URL implements Serializable if ((colon = spec.indexOf(':')) > 0 && (colon < slash || slash < 0)) { - // Protocol may have been specified in spec string. + // Protocol may have been specified in spec string. protocolSpecified = true; - protocol = spec.substring(0, colon).toLowerCase(); - if (context != null) + protocol = spec.substring(0, colon).toLowerCase(); + if (context != null) { if (context.protocol.equals(protocol)) { @@ -482,11 +482,11 @@ public final class URL implements Serializable if (ph != null) { - SecurityManager s = System.getSecurityManager(); - if (s != null && phFromUser) - s.checkPermission(new NetPermission("specifyStreamHandler")); + SecurityManager s = System.getSecurityManager(); + if (s != null && phFromUser) + s.checkPermission(new NetPermission("specifyStreamHandler")); - this.ph = ph; + this.ph = ph; } else this.ph = getURLStreamHandler(protocol); @@ -502,14 +502,14 @@ public final class URL implements Serializable try { - this.ph.parseURL(this, spec, colon + 1, - hashAt < 0 ? spec.length() : hashAt); + this.ph.parseURL(this, spec, colon + 1, + hashAt < 0 ? spec.length() : hashAt); } catch (URLParseError e) { MalformedURLException mue = new MalformedURLException(e.getMessage()); mue.initCause(e); - throw mue; + throw mue; } catch (RuntimeException e) { @@ -772,13 +772,13 @@ public final class URL implements Serializable protocol = protocol.toLowerCase(); if (! this.protocol.equals(protocol)) protocolHandler = getURLStreamHandler(protocol); - + // It is an hidden feature of the JDK. If the protocol does not exist, // we keep the previously initialized protocol. if (protocolHandler != null) { - this.ph = protocolHandler; - this.protocol = protocol; + this.ph = protocolHandler; + this.protocol = protocol; } this.authority = ""; this.port = port; @@ -818,13 +818,13 @@ public final class URL implements Serializable protocol = protocol.toLowerCase(); if (! this.protocol.equals(protocol)) protocolHandler = getURLStreamHandler(protocol); - + // It is an hidden feature of the JDK. If the protocol does not exist, // we keep the previously initialized protocol. if (protocolHandler != null) { - this.ph = protocolHandler; - this.protocol = protocol; + this.ph = protocolHandler; + this.protocol = protocol; } this.host = host; this.userInfo = userInfo; @@ -902,70 +902,70 @@ public final class URL implements Serializable // First, see if a protocol handler is in our cache. if (cache_handlers) { - if ((ph = ph_cache.get(protocol)) != null) - return ph; + if ((ph = ph_cache.get(protocol)) != null) + return ph; } // If a non-default factory has been set, use it to find the protocol. if (factory != null) { - ph = factory.createURLStreamHandler(protocol); + ph = factory.createURLStreamHandler(protocol); } // Non-default factory may have returned null or a factory wasn't set. // Use the default search algorithm to find a handler for this protocol. if (ph == null) { - // Get the list of packages to check and append our default handler - // to it, along with the JDK specified default as a last resort. - // Except in very unusual environments the JDK specified one shouldn't - // ever be needed (or available). - String ph_search_path = - SystemProperties.getProperty("java.protocol.handler.pkgs"); - - // Tack our default package on at the ends. - if (ph_search_path != null) - ph_search_path += "|" + DEFAULT_SEARCH_PATH; - else - ph_search_path = DEFAULT_SEARCH_PATH; - - // Finally loop through our search path looking for a match. - StringTokenizer pkgPrefix = new StringTokenizer(ph_search_path, "|"); - - // Cache the systemClassLoader - if (systemClassLoader == null) - { - systemClassLoader = AccessController.doPrivileged - (new PrivilegedAction<ClassLoader>() { - public ClassLoader run() - { - return ClassLoader.getSystemClassLoader(); - } - }); - } - - do - { - try - { - // Try to get a class from the system/application - // classloader, initialize it, make an instance - // and try to cast it to a URLStreamHandler. - String clsName = - (pkgPrefix.nextToken() + "." + protocol + ".Handler"); - Class c = Class.forName(clsName, true, systemClassLoader); - ph = (URLStreamHandler) c.newInstance(); - } + // Get the list of packages to check and append our default handler + // to it, along with the JDK specified default as a last resort. + // Except in very unusual environments the JDK specified one shouldn't + // ever be needed (or available). + String ph_search_path = + SystemProperties.getProperty("java.protocol.handler.pkgs"); + + // Tack our default package on at the ends. + if (ph_search_path != null) + ph_search_path += "|" + DEFAULT_SEARCH_PATH; + else + ph_search_path = DEFAULT_SEARCH_PATH; + + // Finally loop through our search path looking for a match. + StringTokenizer pkgPrefix = new StringTokenizer(ph_search_path, "|"); + + // Cache the systemClassLoader + if (systemClassLoader == null) + { + systemClassLoader = AccessController.doPrivileged + (new PrivilegedAction<ClassLoader>() { + public ClassLoader run() + { + return ClassLoader.getSystemClassLoader(); + } + }); + } + + do + { + try + { + // Try to get a class from the system/application + // classloader, initialize it, make an instance + // and try to cast it to a URLStreamHandler. + String clsName = + (pkgPrefix.nextToken() + "." + protocol + ".Handler"); + Class c = Class.forName(clsName, true, systemClassLoader); + ph = (URLStreamHandler) c.newInstance(); + } catch (ThreadDeath death) { throw death; } - catch (Throwable t) - { - // Ignored. - } - } - while (ph == null && pkgPrefix.hasMoreTokens()); + catch (Throwable t) + { + // Ignored. + } + } + while (ph == null && pkgPrefix.hasMoreTokens()); } // Update the hashtable with the new protocol handler. diff --git a/libjava/classpath/java/net/URLClassLoader.java b/libjava/classpath/java/net/URLClassLoader.java index 52d297a3c17..418ee77f358 100644 --- a/libjava/classpath/java/net/URLClassLoader.java +++ b/libjava/classpath/java/net/URLClassLoader.java @@ -288,8 +288,8 @@ public class URLClassLoader extends SecureClassLoader if (newUrl == null) return; // Silently ignore... - // Reset the toString() value. - thisString = null; + // Reset the toString() value. + thisString = null; // Create a loader for this URL. URLLoader loader = null; @@ -394,8 +394,8 @@ public class URLClassLoader extends SecureClassLoader newUrl); } - urlinfos.add(loader); - ArrayList<URLLoader> extra = loader.getClassPath(); + urlinfos.add(loader); + ArrayList<URLLoader> extra = loader.getClassPath(); if (extra != null) urlinfos.addAll(extra); } @@ -414,8 +414,8 @@ public class URLClassLoader extends SecureClassLoader { for (int i = 0; i < newUrls.length; i++) { - urls.add(newUrls[i]); - addURLImpl(newUrls[i]); + urls.add(newUrls[i]); + addURLImpl(newUrls[i]); } } @@ -424,7 +424,7 @@ public class URLClassLoader extends SecureClassLoader * object, if not null, has precedence. */ private String getAttributeValue(Attributes.Name name, Attributes first, - Attributes second) + Attributes second) { String result = null; if (first != null) @@ -457,7 +457,7 @@ public class URLClassLoader extends SecureClassLoader CPStringBuilder xform = new CPStringBuilder(name); for (int i = xform.length () - 1; i >= 0; --i) if (xform.charAt(i) == '.') - xform.setCharAt(i, '/'); + xform.setCharAt(i, '/'); xform.append('/'); String xformName = xform.toString(); @@ -466,22 +466,22 @@ public class URLClassLoader extends SecureClassLoader String specTitle = getAttributeValue(Attributes.Name.SPECIFICATION_TITLE, - entryAttr, attr); + entryAttr, attr); String specVersion = getAttributeValue(Attributes.Name.SPECIFICATION_VERSION, - entryAttr, attr); + entryAttr, attr); String specVendor = getAttributeValue(Attributes.Name.SPECIFICATION_VENDOR, - entryAttr, attr); + entryAttr, attr); String implTitle = getAttributeValue(Attributes.Name.IMPLEMENTATION_TITLE, - entryAttr, attr); + entryAttr, attr); String implVersion = getAttributeValue(Attributes.Name.IMPLEMENTATION_VERSION, - entryAttr, attr); + entryAttr, attr); String implVendor = getAttributeValue(Attributes.Name.IMPLEMENTATION_VENDOR, - entryAttr, attr); + entryAttr, attr); // Look if the Manifest indicates that this package is sealed // XXX - most likely not completely correct! @@ -494,9 +494,9 @@ public class URLClassLoader extends SecureClassLoader url = null; return definePackage(name, - specTitle, specVendor, specVersion, - implTitle, implVendor, implVersion, - url); + specTitle, specVendor, specVersion, + implTitle, implVendor, implVersion, + url); } /** @@ -534,47 +534,47 @@ public class URLClassLoader extends SecureClassLoader // construct the class (and watch out for those nasty IOExceptions) try { - byte[] data; - InputStream in = resource.getInputStream(); - try - { - int length = resource.getLength(); - if (length != -1) - { - // We know the length of the data. - // Just try to read it in all at once - data = new byte[length]; - int pos = 0; - while (length - pos > 0) - { - int len = in.read(data, pos, length - pos); - if (len == -1) - throw new EOFException("Not enough data reading from: " - + in); - pos += len; - } - } - else - { - // We don't know the data length. - // Have to read it in chunks. - ByteArrayOutputStream out = new ByteArrayOutputStream(4096); - byte[] b = new byte[4096]; - int l = 0; - while (l != -1) - { - l = in.read(b); - if (l != -1) - out.write(b, 0, l); - } - data = out.toByteArray(); - } - } - finally - { - in.close(); - } - final byte[] classData = data; + byte[] data; + InputStream in = resource.getInputStream(); + try + { + int length = resource.getLength(); + if (length != -1) + { + // We know the length of the data. + // Just try to read it in all at once + data = new byte[length]; + int pos = 0; + while (length - pos > 0) + { + int len = in.read(data, pos, length - pos); + if (len == -1) + throw new EOFException("Not enough data reading from: " + + in); + pos += len; + } + } + else + { + // We don't know the data length. + // Have to read it in chunks. + ByteArrayOutputStream out = new ByteArrayOutputStream(4096); + byte[] b = new byte[4096]; + int l = 0; + while (l != -1) + { + l = in.read(b); + if (l != -1) + out.write(b, 0, l); + } + data = out.toByteArray(); + } + } + finally + { + in.close(); + } + final byte[] classData = data; // Now get the CodeSource final CodeSource source = resource.getCodeSource(); @@ -620,18 +620,18 @@ public class URLClassLoader extends SecureClassLoader Certificate[] resourceCertificates = resource.getCertificates(); if(resourceCertificates != null) super.setSigners(result, resourceCertificates); - + return result; } catch (IOException ioe) { - throw new ClassNotFoundException(className + " not found in " + this, ioe); + throw new ClassNotFoundException(className + " not found in " + this, ioe); } } - + // Cached String representation of this URLClassLoader private String thisString; - + /** * Returns a String representation of this URLClassLoader giving the * actual Class name, the URLs that are searched and the parent @@ -641,25 +641,25 @@ public class URLClassLoader extends SecureClassLoader { synchronized (this) { - if (thisString == null) - { - CPStringBuilder sb = new CPStringBuilder(); - sb.append(this.getClass().getName()); - sb.append("{urls=[" ); - URL[] thisURLs = getURLs(); - for (int i = 0; i < thisURLs.length; i++) - { - sb.append(thisURLs[i]); - if (i < thisURLs.length - 1) - sb.append(','); - } - sb.append(']'); - sb.append(", parent="); - sb.append(getParent()); - sb.append('}'); - thisString = sb.toString(); - } - return thisString; + if (thisString == null) + { + CPStringBuilder sb = new CPStringBuilder(); + sb.append(this.getClass().getName()); + sb.append("{urls=[" ); + URL[] thisURLs = getURLs(); + for (int i = 0; i < thisURLs.length; i++) + { + sb.append(thisURLs[i]); + if (i < thisURLs.length - 1) + sb.append(','); + } + sb.append(']'); + sb.append(", parent="); + sb.append(getParent()); + sb.append('}'); + thisString = sb.toString(); + } + return thisString; } } diff --git a/libjava/classpath/java/net/URLConnection.java b/libjava/classpath/java/net/URLConnection.java index 67405801416..e9365a3e0eb 100644 --- a/libjava/classpath/java/net/URLConnection.java +++ b/libjava/classpath/java/net/URLConnection.java @@ -173,7 +173,7 @@ public abstract class URLConnection private static SimpleDateFormat[] dateFormats; private static boolean dateformats_initialized; - + /** * The connection timeout period. */ @@ -236,7 +236,7 @@ public abstract class URLConnection /** * Set the connection timeout speed, in milliseconds, or zero if the timeout - * is to be considered infinite. Note that in certain socket + * 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. @@ -270,7 +270,7 @@ public abstract class URLConnection /** * Set the read timeout, in milliseconds, or zero if the timeout - * is to be considered infinite. Note that in certain socket + * 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. @@ -368,7 +368,7 @@ public abstract class URLConnection /** * Return a String representing the header value at the specified index. * This allows the caller to walk the list of header fields. The analogous - * {@link #getHeaderField(int)} method allows access to the corresponding + * {@link #getHeaderField(int)} method allows access to the corresponding * key for this header field * * @param index The index into the header field list to retrieve the value for @@ -397,8 +397,8 @@ public abstract class URLConnection /** * Returns an unmodifiable Map containing all sent header fields. - * - * @return The map of header fields. The map consists of String keys with + * + * @return The map of header fields. The map consists of String keys with * an unmodifiable List of String objects as value. * * @since 1.4 @@ -430,11 +430,11 @@ public abstract class URLConnection try { - return Integer.parseInt(value); + return Integer.parseInt(value); } catch (NumberFormatException e) { - return defaultValue; + return defaultValue; } } @@ -463,15 +463,15 @@ public abstract class URLConnection if (str != null) { - for (int i = 0; i < dateFormats.length; i++) - { - SimpleDateFormat df = dateFormats[i]; - position.setIndex(0); - position.setErrorIndex(0); - Date date = df.parse(str, position); - if (date != null) - return date.getTime(); - } + for (int i = 0; i < dateFormats.length; i++) + { + SimpleDateFormat df = dateFormats[i]; + position.setIndex(0); + position.setErrorIndex(0); + Date date = df.parse(str, position); + if (date != null) + return date.getTime(); + } } return result; @@ -480,7 +480,7 @@ public abstract class URLConnection /** * Returns a String representing the header key at the specified index. * This allows the caller to walk the list of header fields. The analogous - * {@link #getHeaderField(int)} method allows access to the corresponding + * {@link #getHeaderField(int)} method allows access to the corresponding * value for this tag. * * @param index The index into the header field list to retrieve the key for. @@ -527,7 +527,7 @@ public abstract class URLConnection connect(); // FIXME: Doc indicates that other criteria should be applied as - // heuristics to determine the true content type, e.g. see + // heuristics to determine the true content type, e.g. see // guessContentTypeFromName() and guessContentTypeFromStream methods // as well as FileNameMap class & fileNameMap field & get/set methods. String type = getContentType(); @@ -698,7 +698,7 @@ public abstract class URLConnection { if (connected) throw new IllegalStateException("Already connected"); - + allowUserInteraction = allow; } @@ -820,8 +820,8 @@ public abstract class URLConnection } /** - * Sets the value of the named request property. - * This method does overwrite the value of existing properties with + * Sets the value of the named request property. + * This method does overwrite the value of existing properties with * the new value. * * @param key The name of the property @@ -898,8 +898,8 @@ public abstract class URLConnection /** * Returns an unmodifiable Map containing the request properties. - * - * @return The map of properties. The map consists of String keys with an + * + * @return The map of properties. The map consists of String keys with an * unmodifiable List of String objects as value. * * @exception IllegalStateException If already connected @@ -1074,11 +1074,11 @@ public abstract class URLConnection handler = factory.createContentHandler(contentType); // Now try default factory. Using this factory to instantiate built-in - // content handlers is preferable + // content handlers is preferable if (handler == null) handler = defaultFactory.createContentHandler(contentType); - // User-set factory has not returned a handler. Use the default search + // User-set factory has not returned a handler. Use the default search // algorithm. if (handler == null) { @@ -1103,7 +1103,7 @@ public abstract class URLConnection { if (cArray[i] == '/') cArray[i] = '.'; - else if (! ((cArray[i] >= 'A' && cArray[i] <= 'Z') || + else if (! ((cArray[i] >= 'A' && cArray[i] <= 'Z') || (cArray[i] >= 'a' && cArray[i] <= 'z') || (cArray[i] >= '0' && cArray[i] <= '9'))) cArray[i] = '_'; @@ -1129,7 +1129,7 @@ public abstract class URLConnection return handler; } - + // We don't put these in a static initializer, because it creates problems // with initializer co-dependency: SimpleDateFormat's constructors // eventually depend on URLConnection (via the java.text.*Symbols classes). diff --git a/libjava/classpath/java/net/URLDecoder.java b/libjava/classpath/java/net/URLDecoder.java index fb7ab591696..73cedea5cf7 100644 --- a/libjava/classpath/java/net/URLDecoder.java +++ b/libjava/classpath/java/net/URLDecoder.java @@ -87,12 +87,12 @@ public class URLDecoder { try { - return decode(s, "UTF-8"); + return decode(s, "UTF-8"); } catch (UnsupportedEncodingException uee) { - // Should never happen since UTF-8 encoding should always be supported - return s; + // Should never happen since UTF-8 encoding should always be supported + return s; } } @@ -132,45 +132,45 @@ public class URLDecoder CPStringBuilder result = new CPStringBuilder(length); while ((i = str.indexOf('%', start)) >= 0) { - // Add all non-encoded characters to the result buffer - result.append(str.substring(start, i)); - start = i; - - // Get all consecutive encoded bytes - while ((i + 2 < length) && (str.charAt(i) == '%')) - i += 3; - - // Decode all these bytes - if ((bytes == null) || (bytes.length < ((i - start) / 3))) - bytes = new byte[((i - start) / 3)]; - - int index = 0; - try - { - while (start < i) - { - String sub = str.substring(start + 1, start + 3); - bytes[index] = (byte) Integer.parseInt(sub, 16); - index++; - start += 3; - } - } - catch (NumberFormatException nfe) - { - // One of the hex encoded strings was bad - } - - // Add the bytes as characters according to the given encoding - result.append(new String(bytes, 0, index, encoding)); - - // Make sure we skip to just after a % sign - // There might not have been enough encoded characters after the % - // or the hex chars were not actually hex chars (NumberFormatException) - if (start < length && s.charAt(start) == '%') - { - result.append('%'); - start++; - } + // Add all non-encoded characters to the result buffer + result.append(str.substring(start, i)); + start = i; + + // Get all consecutive encoded bytes + while ((i + 2 < length) && (str.charAt(i) == '%')) + i += 3; + + // Decode all these bytes + if ((bytes == null) || (bytes.length < ((i - start) / 3))) + bytes = new byte[((i - start) / 3)]; + + int index = 0; + try + { + while (start < i) + { + String sub = str.substring(start + 1, start + 3); + bytes[index] = (byte) Integer.parseInt(sub, 16); + index++; + start += 3; + } + } + catch (NumberFormatException nfe) + { + // One of the hex encoded strings was bad + } + + // Add the bytes as characters according to the given encoding + result.append(new String(bytes, 0, index, encoding)); + + // Make sure we skip to just after a % sign + // There might not have been enough encoded characters after the % + // or the hex chars were not actually hex chars (NumberFormatException) + if (start < length && s.charAt(start) == '%') + { + result.append('%'); + start++; + } } // Add any characters left diff --git a/libjava/classpath/java/net/URLEncoder.java b/libjava/classpath/java/net/URLEncoder.java index 89d9a0bd04c..09c0f3de024 100644 --- a/libjava/classpath/java/net/URLEncoder.java +++ b/libjava/classpath/java/net/URLEncoder.java @@ -83,14 +83,14 @@ public class URLEncoder { try { - // We default to 8859_1 for compatibility with the same - // default elsewhere in the library. - return encode(s, System.getProperty("file.encoding", "8859_1")); + // We default to 8859_1 for compatibility with the same + // default elsewhere in the library. + return encode(s, System.getProperty("file.encoding", "8859_1")); } catch (UnsupportedEncodingException uee) { - // Should never happen since default should always be supported - return s; + // Should never happen since default should always be supported + return s; } } @@ -118,40 +118,40 @@ public class URLEncoder CPStringBuilder result = new CPStringBuilder(length); while (true) { - while (i < length && isSafe(s.charAt(i))) - i++; - - // Safe character can just be added - result.append(s.substring(start, i)); - - // Are we done? - if (i >= length) - return result.toString(); - else if (s.charAt(i) == ' ') - { - result.append('+'); // Replace space char with plus symbol. - i++; - } - else - { - // Get all unsafe characters - start = i; - char c; - while (i < length && (c = s.charAt(i)) != ' ' && ! isSafe(c)) - i++; - - // Convert them to %XY encoded strings - String unsafe = s.substring(start, i); - byte[] bytes = unsafe.getBytes(encoding); - for (int j = 0; j < bytes.length; j++) - { - result.append('%'); - int val = bytes[j]; - result.append(hex.charAt((val & 0xf0) >> 4)); - result.append(hex.charAt(val & 0x0f)); - } - } - start = i; + while (i < length && isSafe(s.charAt(i))) + i++; + + // Safe character can just be added + result.append(s.substring(start, i)); + + // Are we done? + if (i >= length) + return result.toString(); + else if (s.charAt(i) == ' ') + { + result.append('+'); // Replace space char with plus symbol. + i++; + } + else + { + // Get all unsafe characters + start = i; + char c; + while (i < length && (c = s.charAt(i)) != ' ' && ! isSafe(c)) + i++; + + // Convert them to %XY encoded strings + String unsafe = s.substring(start, i); + byte[] bytes = unsafe.getBytes(encoding); + for (int j = 0; j < bytes.length; j++) + { + result.append('%'); + int val = bytes[j]; + result.append(hex.charAt((val & 0xf0) >> 4)); + result.append(hex.charAt(val & 0x0f)); + } + } + start = i; } } diff --git a/libjava/classpath/java/net/URLStreamHandler.java b/libjava/classpath/java/net/URLStreamHandler.java index 4748191e07b..5433aedd9d7 100644 --- a/libjava/classpath/java/net/URLStreamHandler.java +++ b/libjava/classpath/java/net/URLStreamHandler.java @@ -131,69 +131,69 @@ public abstract class URLStreamHandler String userInfo = url.getUserInfo(); String authority = url.getAuthority(); String query = null; - + // On Windows we need to change \ to / for file URLs char separator = File.separatorChar; if (url.getProtocol().equals("file") && separator != '/') { - file = file.replace(separator, '/'); - spec = spec.replace(separator, '/'); + file = file.replace(separator, '/'); + spec = spec.replace(separator, '/'); } if (spec.regionMatches(start, "//", 0, 2)) { - String genuineHost; - int hostEnd; - int colon; - int at_host; - - start += 2; - int slash = spec.indexOf('/', start); - if (slash >= 0) - hostEnd = slash; - else - hostEnd = end; - - authority = host = spec.substring(start, hostEnd); - - // We first need a genuine host name (with userinfo). - // So we check for '@': if it's present check the port in the - // section after '@' in the other case check it in the full string. - // P.S.: We don't care having '@' at the beginning of the string. - if ((at_host = host.indexOf('@')) >= 0) - { - genuineHost = host.substring(at_host); - userInfo = host.substring(0, at_host); - } - else - genuineHost = host; - - // Look for optional port number. It is valid for the non-port - // part of the host name to be null (e.g. a URL "http://:80"). - // TBD: JDK 1.2 in this case sets host to null rather than ""; - // this is undocumented and likely an unintended side effect in 1.2 - // so we'll be simple here and stick with "". Note that - // "http://" or "http:///" produce a "" host in JDK 1.2. - if ((colon = genuineHost.indexOf(':')) >= 0) - { - try - { - port = Integer.parseInt(genuineHost.substring(colon + 1)); - } - catch (NumberFormatException e) - { - // Ignore invalid port values; port is already set to u's - // port. - } - - // Now we must cut the port number in the original string. - if (at_host >= 0) - host = host.substring(0, at_host + colon); - else - host = host.substring(0, colon); - } - file = null; - start = hostEnd; + String genuineHost; + int hostEnd; + int colon; + int at_host; + + start += 2; + int slash = spec.indexOf('/', start); + if (slash >= 0) + hostEnd = slash; + else + hostEnd = end; + + authority = host = spec.substring(start, hostEnd); + + // We first need a genuine host name (with userinfo). + // So we check for '@': if it's present check the port in the + // section after '@' in the other case check it in the full string. + // P.S.: We don't care having '@' at the beginning of the string. + if ((at_host = host.indexOf('@')) >= 0) + { + genuineHost = host.substring(at_host); + userInfo = host.substring(0, at_host); + } + else + genuineHost = host; + + // Look for optional port number. It is valid for the non-port + // part of the host name to be null (e.g. a URL "http://:80"). + // TBD: JDK 1.2 in this case sets host to null rather than ""; + // this is undocumented and likely an unintended side effect in 1.2 + // so we'll be simple here and stick with "". Note that + // "http://" or "http:///" produce a "" host in JDK 1.2. + if ((colon = genuineHost.indexOf(':')) >= 0) + { + try + { + port = Integer.parseInt(genuineHost.substring(colon + 1)); + } + catch (NumberFormatException e) + { + // Ignore invalid port values; port is already set to u's + // port. + } + + // Now we must cut the port number in the original string. + if (at_host >= 0) + host = host.substring(0, at_host + colon); + else + host = host.substring(0, colon); + } + file = null; + start = hostEnd; } else if (host == null) host = ""; @@ -201,49 +201,49 @@ public abstract class URLStreamHandler if (file == null || file.length() == 0 || (start < end && spec.charAt(start) == '/')) { - // No file context available; just spec for file. - // Or this is an absolute path name; ignore any file context. - file = spec.substring(start, end); - ref = null; + // No file context available; just spec for file. + // Or this is an absolute path name; ignore any file context. + file = spec.substring(start, end); + ref = null; } else if (start < end) { - // Context is available, but only override it if there is a new file. - int lastSlash = file.lastIndexOf('/'); - if (lastSlash < 0) - file = spec.substring(start, end); - else - file = (file.substring(0, lastSlash) - + '/' + spec.substring(start, end)); - - // For URLs constructed relative to a context, we - // need to canonicalise the file path. - file = canonicalizeFilename(file); - - ref = null; + // Context is available, but only override it if there is a new file. + int lastSlash = file.lastIndexOf('/'); + if (lastSlash < 0) + file = spec.substring(start, end); + else + file = (file.substring(0, lastSlash) + + '/' + spec.substring(start, end)); + + // For URLs constructed relative to a context, we + // need to canonicalise the file path. + file = canonicalizeFilename(file); + + ref = null; } if (ref == null) { - // Normally there should be no '#' in the file part, - // but we are nice. - int hash = file.indexOf('#'); - if (hash != -1) - { - ref = file.substring(hash + 1, file.length()); - file = file.substring(0, hash); - } + // Normally there should be no '#' in the file part, + // but we are nice. + int hash = file.indexOf('#'); + if (hash != -1) + { + ref = file.substring(hash + 1, file.length()); + file = file.substring(0, hash); + } } // We care about the query tag only if there is no reference at all. if (ref == null) { - int queryTag = file.indexOf('?'); - if (queryTag != -1) - { - query = file.substring(queryTag + 1); - file = file.substring(0, queryTag); - } + int queryTag = file.indexOf('?'); + if (queryTag != -1) + { + query = file.substring(queryTag + 1); + file = file.substring(0, queryTag); + } } // XXX - Classpath used to call PlatformHelper.toCanonicalForm() on @@ -270,12 +270,12 @@ public abstract class URLStreamHandler // the general case, but it's probably not bad most of the time. while ((index = file.indexOf("/../")) >= 0) { - // Strip of the previous directory - if it exists. - int previous = file.lastIndexOf('/', index - 1); - if (previous >= 0) - file = file.substring(0, previous) + file.substring(index + 3); - else - break; + // Strip of the previous directory - if it exists. + int previous = file.lastIndexOf('/', index - 1); + if (previous >= 0) + file = file.substring(0, previous) + file.substring(index + 3); + else + break; } return file; } @@ -451,11 +451,11 @@ public abstract class URLStreamHandler try { - return InetAddress.getByName(hostname); + return InetAddress.getByName(hostname); } catch (UnknownHostException e) { - return null; + return null; } } @@ -505,7 +505,7 @@ public abstract class URLStreamHandler authority = url.getAuthority(); if (authority == null) authority = ""; - + file = url.getFile(); ref = url.getRef(); @@ -516,15 +516,15 @@ public abstract class URLStreamHandler if (protocol.length() > 0) { - sb.append(protocol); - sb.append(":"); + sb.append(protocol); + sb.append(":"); } - + // If we have superfluous leading slashes (that means, at least 2) // we always add the authority component ("//" + host) to // avoid ambiguity. Otherwise we would generate an URL like // proto://home/foo - // where we meant: + // where we meant: // host: <empty> - file: //home/foo // but URL spec says it is: // host: home - file: /foo |