Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/ikvm-fork.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjfrijters <jfrijters>2008-06-11 13:04:56 +0400
committerjfrijters <jfrijters>2008-06-11 13:04:56 +0400
commit9baab31e8c2ec69b4e098a164fb6ea6d0b8bb56c (patch)
treecb6ea0550c8653b7614e2d221e848180249e27b7 /openjdk/sun/nio/ch/Net.java
parentdb4720da166361f480586decec8581648c0b7ab0 (diff)
Converted tabs to spaces.
Diffstat (limited to 'openjdk/sun/nio/ch/Net.java')
-rw-r--r--openjdk/sun/nio/ch/Net.java692
1 files changed, 346 insertions, 346 deletions
diff --git a/openjdk/sun/nio/ch/Net.java b/openjdk/sun/nio/ch/Net.java
index 835d6f9e..af9c957c 100644
--- a/openjdk/sun/nio/ch/Net.java
+++ b/openjdk/sun/nio/ch/Net.java
@@ -44,7 +44,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.*;
-class Net { // package-private
+class Net { // package-private
private Net() { }
@@ -63,442 +63,442 @@ class Net { // package-private
static FileDescriptor serverSocket(boolean stream) throws IOException
{
- return socket(stream);
+ return socket(stream);
}
static FileDescriptor socket(boolean stream) throws IOException
{
- try
- {
- if (false) throw new cli.System.Net.Sockets.SocketException();
- FileDescriptor fd = new FileDescriptor();
- if (stream)
- {
- fd.setSocket(new cli.System.Net.Sockets.Socket(AddressFamily.wrap(AddressFamily.InterNetwork), SocketType.wrap(SocketType.Stream), ProtocolType.wrap(ProtocolType.Tcp)));
- }
- else
- {
- fd.setSocket(new cli.System.Net.Sockets.Socket(AddressFamily.wrap(AddressFamily.InterNetwork), SocketType.wrap(SocketType.Dgram), ProtocolType.wrap(ProtocolType.Udp)));
- }
- return fd;
- }
- catch (cli.System.Net.Sockets.SocketException x)
- {
- throw PlainSocketImpl.convertSocketExceptionToIOException(x);
- }
+ try
+ {
+ if (false) throw new cli.System.Net.Sockets.SocketException();
+ FileDescriptor fd = new FileDescriptor();
+ if (stream)
+ {
+ fd.setSocket(new cli.System.Net.Sockets.Socket(AddressFamily.wrap(AddressFamily.InterNetwork), SocketType.wrap(SocketType.Stream), ProtocolType.wrap(ProtocolType.Tcp)));
+ }
+ else
+ {
+ fd.setSocket(new cli.System.Net.Sockets.Socket(AddressFamily.wrap(AddressFamily.InterNetwork), SocketType.wrap(SocketType.Dgram), ProtocolType.wrap(ProtocolType.Udp)));
+ }
+ return fd;
+ }
+ catch (cli.System.Net.Sockets.SocketException x)
+ {
+ throw PlainSocketImpl.convertSocketExceptionToIOException(x);
+ }
}
static void bind(FileDescriptor fd, InetAddress addr, int port) throws IOException
{
- try
- {
- if (false) throw new cli.System.Net.Sockets.SocketException();
- if (false) throw new cli.System.ObjectDisposedException("");
- fd.getSocket().Bind(new IPEndPoint(PlainSocketImpl.getAddressFromInetAddress(addr), port));
- }
- catch (cli.System.Net.Sockets.SocketException x)
- {
- throw PlainSocketImpl.convertSocketExceptionToIOException(x);
- }
- catch (cli.System.ObjectDisposedException x1)
- {
- throw new SocketException("Socket is closed");
- }
+ try
+ {
+ if (false) throw new cli.System.Net.Sockets.SocketException();
+ if (false) throw new cli.System.ObjectDisposedException("");
+ fd.getSocket().Bind(new IPEndPoint(PlainSocketImpl.getAddressFromInetAddress(addr), port));
+ }
+ catch (cli.System.Net.Sockets.SocketException x)
+ {
+ throw PlainSocketImpl.convertSocketExceptionToIOException(x);
+ }
+ catch (cli.System.ObjectDisposedException x1)
+ {
+ throw new SocketException("Socket is closed");
+ }
}
static void configureBlocking(FileDescriptor fd, boolean blocking) throws IOException
{
- try
- {
- if (false) throw new cli.System.Net.Sockets.SocketException();
- if (false) throw new cli.System.ObjectDisposedException("");
- fd.getSocket().set_Blocking(blocking);
- }
- catch (cli.System.Net.Sockets.SocketException x)
- {
- if (x.get_ErrorCode() == WSAEINVAL)
- {
- // Work around for winsock issue. You can't set a socket to blocking if a connection request is pending,
- // so we'll have to set the blocking again in SocketChannelImpl.checkConnect().
- return;
- }
- throw PlainSocketImpl.convertSocketExceptionToIOException(x);
- }
- catch (cli.System.ObjectDisposedException _)
- {
- throw new SocketException("Socket is closed");
- }
+ try
+ {
+ if (false) throw new cli.System.Net.Sockets.SocketException();
+ if (false) throw new cli.System.ObjectDisposedException("");
+ fd.getSocket().set_Blocking(blocking);
+ }
+ catch (cli.System.Net.Sockets.SocketException x)
+ {
+ if (x.get_ErrorCode() == WSAEINVAL)
+ {
+ // Work around for winsock issue. You can't set a socket to blocking if a connection request is pending,
+ // so we'll have to set the blocking again in SocketChannelImpl.checkConnect().
+ return;
+ }
+ throw PlainSocketImpl.convertSocketExceptionToIOException(x);
+ }
+ catch (cli.System.ObjectDisposedException _)
+ {
+ throw new SocketException("Socket is closed");
+ }
}
static InetSocketAddress localAddress(FileDescriptor fd)
{
- try
- {
- if (false) throw new cli.System.Net.Sockets.SocketException();
- if (false) throw new cli.System.ObjectDisposedException("");
- IPEndPoint ep = (IPEndPoint)fd.getSocket().get_LocalEndPoint();
- return new InetSocketAddress(PlainSocketImpl.getInetAddressFromIPEndPoint(ep), ep.get_Port());
- }
- catch (cli.System.Net.Sockets.SocketException x)
- {
- throw new Error(x);
- }
- catch (cli.System.ObjectDisposedException x)
- {
- throw new Error(x);
- }
+ try
+ {
+ if (false) throw new cli.System.Net.Sockets.SocketException();
+ if (false) throw new cli.System.ObjectDisposedException("");
+ IPEndPoint ep = (IPEndPoint)fd.getSocket().get_LocalEndPoint();
+ return new InetSocketAddress(PlainSocketImpl.getInetAddressFromIPEndPoint(ep), ep.get_Port());
+ }
+ catch (cli.System.Net.Sockets.SocketException x)
+ {
+ throw new Error(x);
+ }
+ catch (cli.System.ObjectDisposedException x)
+ {
+ throw new Error(x);
+ }
}
static int localPortNumber(FileDescriptor fd)
{
- try
- {
- if (false) throw new cli.System.Net.Sockets.SocketException();
- if (false) throw new cli.System.ObjectDisposedException("");
- IPEndPoint ep = (IPEndPoint)fd.getSocket().get_LocalEndPoint();
- return ep == null ? 0 : ep.get_Port();
- }
- catch (cli.System.Net.Sockets.SocketException x)
- {
- throw new Error(x);
- }
- catch (cli.System.ObjectDisposedException x)
- {
- throw new Error(x);
- }
+ try
+ {
+ if (false) throw new cli.System.Net.Sockets.SocketException();
+ if (false) throw new cli.System.ObjectDisposedException("");
+ IPEndPoint ep = (IPEndPoint)fd.getSocket().get_LocalEndPoint();
+ return ep == null ? 0 : ep.get_Port();
+ }
+ catch (cli.System.Net.Sockets.SocketException x)
+ {
+ throw new Error(x);
+ }
+ catch (cli.System.ObjectDisposedException x)
+ {
+ throw new Error(x);
+ }
}
private static int mapSocketOptionLevel(int opt) throws IOException
{
- switch (opt)
- {
- case SocketOptions.SO_BROADCAST:
- case SocketOptions.SO_KEEPALIVE:
- case SocketOptions.SO_LINGER:
- case SocketOptions.SO_OOBINLINE:
- case SocketOptions.SO_RCVBUF:
- case SocketOptions.SO_SNDBUF:
- case SocketOptions.SO_REUSEADDR:
- return SocketOptionLevel.Socket;
- case SocketOptions.IP_MULTICAST_LOOP:
- case SocketOptions.IP_TOS:
- return SocketOptionLevel.IP;
- case SocketOptions.TCP_NODELAY:
- return SocketOptionLevel.Tcp;
- default:
- throw new SocketException("unsupported socket option: " + opt);
- }
+ switch (opt)
+ {
+ case SocketOptions.SO_BROADCAST:
+ case SocketOptions.SO_KEEPALIVE:
+ case SocketOptions.SO_LINGER:
+ case SocketOptions.SO_OOBINLINE:
+ case SocketOptions.SO_RCVBUF:
+ case SocketOptions.SO_SNDBUF:
+ case SocketOptions.SO_REUSEADDR:
+ return SocketOptionLevel.Socket;
+ case SocketOptions.IP_MULTICAST_LOOP:
+ case SocketOptions.IP_TOS:
+ return SocketOptionLevel.IP;
+ case SocketOptions.TCP_NODELAY:
+ return SocketOptionLevel.Tcp;
+ default:
+ throw new SocketException("unsupported socket option: " + opt);
+ }
}
private static int mapSocketOptionName(int opt) throws IOException
{
- switch (opt)
- {
- case SocketOptions.SO_BROADCAST:
- return SocketOptionName.Broadcast;
- case SocketOptions.SO_KEEPALIVE:
- return SocketOptionName.KeepAlive;
- case SocketOptions.SO_LINGER:
- return SocketOptionName.Linger;
- case SocketOptions.SO_OOBINLINE:
- return SocketOptionName.OutOfBandInline;
- case SocketOptions.SO_RCVBUF:
- return SocketOptionName.ReceiveBuffer;
- case SocketOptions.SO_SNDBUF:
- return SocketOptionName.SendBuffer;
- case SocketOptions.SO_REUSEADDR:
- return SocketOptionName.ReuseAddress;
- case SocketOptions.IP_MULTICAST_LOOP:
- return SocketOptionName.MulticastLoopback;
- case SocketOptions.IP_TOS:
- return SocketOptionName.TypeOfService;
- case SocketOptions.TCP_NODELAY:
- return SocketOptionName.NoDelay;
- default:
- throw new SocketException("unsupported socket option: " + opt);
- }
+ switch (opt)
+ {
+ case SocketOptions.SO_BROADCAST:
+ return SocketOptionName.Broadcast;
+ case SocketOptions.SO_KEEPALIVE:
+ return SocketOptionName.KeepAlive;
+ case SocketOptions.SO_LINGER:
+ return SocketOptionName.Linger;
+ case SocketOptions.SO_OOBINLINE:
+ return SocketOptionName.OutOfBandInline;
+ case SocketOptions.SO_RCVBUF:
+ return SocketOptionName.ReceiveBuffer;
+ case SocketOptions.SO_SNDBUF:
+ return SocketOptionName.SendBuffer;
+ case SocketOptions.SO_REUSEADDR:
+ return SocketOptionName.ReuseAddress;
+ case SocketOptions.IP_MULTICAST_LOOP:
+ return SocketOptionName.MulticastLoopback;
+ case SocketOptions.IP_TOS:
+ return SocketOptionName.TypeOfService;
+ case SocketOptions.TCP_NODELAY:
+ return SocketOptionName.NoDelay;
+ default:
+ throw new SocketException("unsupported socket option: " + opt);
+ }
}
static void setIntOption(FileDescriptor fd, int opt, int arg) throws IOException
{
- try
- {
- if (false) throw new cli.System.Net.Sockets.SocketException();
- if (false) throw new cli.System.ObjectDisposedException("");
- int level = mapSocketOptionLevel(opt);
- int name = mapSocketOptionName(opt);
- fd.getSocket().SetSocketOption(SocketOptionLevel.wrap(level), SocketOptionName.wrap(name), arg);
- }
- catch (cli.System.Net.Sockets.SocketException x)
- {
- throw PlainSocketImpl.convertSocketExceptionToIOException(x);
- }
- catch (cli.System.ObjectDisposedException x1)
- {
- throw new SocketException("Socket is closed");
- }
+ try
+ {
+ if (false) throw new cli.System.Net.Sockets.SocketException();
+ if (false) throw new cli.System.ObjectDisposedException("");
+ int level = mapSocketOptionLevel(opt);
+ int name = mapSocketOptionName(opt);
+ fd.getSocket().SetSocketOption(SocketOptionLevel.wrap(level), SocketOptionName.wrap(name), arg);
+ }
+ catch (cli.System.Net.Sockets.SocketException x)
+ {
+ throw PlainSocketImpl.convertSocketExceptionToIOException(x);
+ }
+ catch (cli.System.ObjectDisposedException x1)
+ {
+ throw new SocketException("Socket is closed");
+ }
}
static int getIntOption(FileDescriptor fd, int opt) throws IOException
{
- try
- {
- if (false) throw new cli.System.Net.Sockets.SocketException();
- if (false) throw new cli.System.ObjectDisposedException("");
- int level = mapSocketOptionLevel(opt);
- int name = mapSocketOptionName(opt);
- Object obj = fd.getSocket().GetSocketOption(SocketOptionLevel.wrap(level), SocketOptionName.wrap(name));
- if (obj instanceof LingerOption)
- {
- LingerOption lo = (LingerOption)obj;
- return lo.get_Enabled() ? lo.get_LingerTime() : -1;
- }
- return CIL.unbox_int(obj);
- }
- catch (cli.System.Net.Sockets.SocketException x)
- {
- throw PlainSocketImpl.convertSocketExceptionToIOException(x);
- }
- catch (cli.System.ObjectDisposedException x1)
- {
- throw new SocketException("Socket is closed");
- }
+ try
+ {
+ if (false) throw new cli.System.Net.Sockets.SocketException();
+ if (false) throw new cli.System.ObjectDisposedException("");
+ int level = mapSocketOptionLevel(opt);
+ int name = mapSocketOptionName(opt);
+ Object obj = fd.getSocket().GetSocketOption(SocketOptionLevel.wrap(level), SocketOptionName.wrap(name));
+ if (obj instanceof LingerOption)
+ {
+ LingerOption lo = (LingerOption)obj;
+ return lo.get_Enabled() ? lo.get_LingerTime() : -1;
+ }
+ return CIL.unbox_int(obj);
+ }
+ catch (cli.System.Net.Sockets.SocketException x)
+ {
+ throw PlainSocketImpl.convertSocketExceptionToIOException(x);
+ }
+ catch (cli.System.ObjectDisposedException x1)
+ {
+ throw new SocketException("Socket is closed");
+ }
}
private static int readImpl(FileDescriptor fd, byte[] buf, int offset, int length) throws IOException
{
- if (length == 0)
- {
- return 0;
- }
- try
- {
- if (false) throw new cli.System.Net.Sockets.SocketException();
- if (false) throw new cli.System.ObjectDisposedException("");
- int read = fd.getSocket().Receive(buf, offset, length, SocketFlags.wrap(SocketFlags.None));
- return read == 0 ? IOStatus.EOF : read;
- }
- catch (cli.System.Net.Sockets.SocketException x)
- {
- if (x.get_ErrorCode() == PlainSocketImpl.WSAESHUTDOWN)
- {
- // the socket was shutdown, so we have to return EOF
- return IOStatus.EOF;
- }
- else if (x.get_ErrorCode() == PlainSocketImpl.WSAEWOULDBLOCK)
- {
- // nothing to read and would block
- return IOStatus.UNAVAILABLE;
- }
- throw PlainSocketImpl.convertSocketExceptionToIOException(x);
- }
- catch (cli.System.ObjectDisposedException x1)
- {
- throw new SocketException("Socket is closed");
- }
+ if (length == 0)
+ {
+ return 0;
+ }
+ try
+ {
+ if (false) throw new cli.System.Net.Sockets.SocketException();
+ if (false) throw new cli.System.ObjectDisposedException("");
+ int read = fd.getSocket().Receive(buf, offset, length, SocketFlags.wrap(SocketFlags.None));
+ return read == 0 ? IOStatus.EOF : read;
+ }
+ catch (cli.System.Net.Sockets.SocketException x)
+ {
+ if (x.get_ErrorCode() == PlainSocketImpl.WSAESHUTDOWN)
+ {
+ // the socket was shutdown, so we have to return EOF
+ return IOStatus.EOF;
+ }
+ else if (x.get_ErrorCode() == PlainSocketImpl.WSAEWOULDBLOCK)
+ {
+ // nothing to read and would block
+ return IOStatus.UNAVAILABLE;
+ }
+ throw PlainSocketImpl.convertSocketExceptionToIOException(x);
+ }
+ catch (cli.System.ObjectDisposedException x1)
+ {
+ throw new SocketException("Socket is closed");
+ }
}
static int read(FileDescriptor fd, ByteBuffer dst) throws IOException
{
- if (dst.hasArray())
- {
- byte[] buf = dst.array();
- int len = readImpl(fd, buf, dst.arrayOffset() + dst.position(), dst.remaining());
- if (len > 0)
- {
- dst.position(dst.position() + len);
- }
- return len;
- }
- else
- {
- byte[] buf = new byte[dst.remaining()];
- int len = readImpl(fd, buf, 0, buf.length);
- if (len > 0)
- {
- dst.put(buf, 0, len);
- }
- return len;
- }
+ if (dst.hasArray())
+ {
+ byte[] buf = dst.array();
+ int len = readImpl(fd, buf, dst.arrayOffset() + dst.position(), dst.remaining());
+ if (len > 0)
+ {
+ dst.position(dst.position() + len);
+ }
+ return len;
+ }
+ else
+ {
+ byte[] buf = new byte[dst.remaining()];
+ int len = readImpl(fd, buf, 0, buf.length);
+ if (len > 0)
+ {
+ dst.put(buf, 0, len);
+ }
+ return len;
+ }
}
static long read(FileDescriptor fd, ByteBuffer[] dsts) throws IOException
{
- long totalRead = 0;
- for (int i = 0; i < dsts.length; i++)
- {
- int size = dsts[i].remaining();
- if (size > 0)
- {
- int read = read(fd, dsts[i]);
- if (read < 0)
- {
- break;
- }
- totalRead += read;
- if (read < size || safeGetAvailable(fd) == 0)
- {
- break;
- }
- }
- }
- return totalRead;
+ long totalRead = 0;
+ for (int i = 0; i < dsts.length; i++)
+ {
+ int size = dsts[i].remaining();
+ if (size > 0)
+ {
+ int read = read(fd, dsts[i]);
+ if (read < 0)
+ {
+ break;
+ }
+ totalRead += read;
+ if (read < size || safeGetAvailable(fd) == 0)
+ {
+ break;
+ }
+ }
+ }
+ return totalRead;
}
private static int safeGetAvailable(FileDescriptor fd)
{
- try
- {
- if (false) throw new cli.System.Net.Sockets.SocketException();
- if (false) throw new cli.System.ObjectDisposedException("");
- return fd.getSocket().get_Available();
- }
- catch (cli.System.Net.Sockets.SocketException x)
- {
- }
- catch (cli.System.ObjectDisposedException x1)
- {
- }
- return 0;
+ try
+ {
+ if (false) throw new cli.System.Net.Sockets.SocketException();
+ if (false) throw new cli.System.ObjectDisposedException("");
+ return fd.getSocket().get_Available();
+ }
+ catch (cli.System.Net.Sockets.SocketException x)
+ {
+ }
+ catch (cli.System.ObjectDisposedException x1)
+ {
+ }
+ return 0;
}
private static int writeImpl(FileDescriptor fd, byte[] buf, int offset, int length) throws IOException
{
- try
- {
- if (false) throw new cli.System.Net.Sockets.SocketException();
- if (false) throw new cli.System.ObjectDisposedException("");
- return fd.getSocket().Send(buf, offset, length, SocketFlags.wrap(SocketFlags.None));
- }
- catch (cli.System.Net.Sockets.SocketException x)
- {
- if (x.get_ErrorCode() == PlainSocketImpl.WSAEWOULDBLOCK)
- {
- return IOStatus.UNAVAILABLE;
- }
- throw PlainSocketImpl.convertSocketExceptionToIOException(x);
- }
- catch (cli.System.ObjectDisposedException x1)
- {
- throw new SocketException("Socket is closed");
- }
+ try
+ {
+ if (false) throw new cli.System.Net.Sockets.SocketException();
+ if (false) throw new cli.System.ObjectDisposedException("");
+ return fd.getSocket().Send(buf, offset, length, SocketFlags.wrap(SocketFlags.None));
+ }
+ catch (cli.System.Net.Sockets.SocketException x)
+ {
+ if (x.get_ErrorCode() == PlainSocketImpl.WSAEWOULDBLOCK)
+ {
+ return IOStatus.UNAVAILABLE;
+ }
+ throw PlainSocketImpl.convertSocketExceptionToIOException(x);
+ }
+ catch (cli.System.ObjectDisposedException x1)
+ {
+ throw new SocketException("Socket is closed");
+ }
}
static int write(FileDescriptor fd, ByteBuffer src) throws IOException
{
- if (src.hasArray())
- {
- byte[] buf = src.array();
- int len = writeImpl(fd, buf, src.arrayOffset() + src.position(), src.remaining());
- if (len > 0)
- {
- src.position(src.position() + len);
- }
- return len;
- }
- else
- {
- int pos = src.position();
- byte[] buf = new byte[src.remaining()];
- src.get(buf);
- int len = writeImpl(fd, buf, 0, buf.length);
- if (len > 0)
- {
- src.position(pos + len);
- }
- return len;
- }
+ if (src.hasArray())
+ {
+ byte[] buf = src.array();
+ int len = writeImpl(fd, buf, src.arrayOffset() + src.position(), src.remaining());
+ if (len > 0)
+ {
+ src.position(src.position() + len);
+ }
+ return len;
+ }
+ else
+ {
+ int pos = src.position();
+ byte[] buf = new byte[src.remaining()];
+ src.get(buf);
+ int len = writeImpl(fd, buf, 0, buf.length);
+ if (len > 0)
+ {
+ src.position(pos + len);
+ }
+ return len;
+ }
}
static long write(FileDescriptor fd, ByteBuffer[] srcs) throws IOException
{
- long totalWritten = 0;
- for (int i = 0; i < srcs.length; i++)
- {
- int size = srcs[i].remaining();
- if (size > 0)
- {
- int written = write(fd, srcs[i]);
- if (written < 0)
- {
- break;
- }
- totalWritten += written;
- if (written < size)
- {
- break;
- }
- }
- }
- return totalWritten;
+ long totalWritten = 0;
+ for (int i = 0; i < srcs.length; i++)
+ {
+ int size = srcs[i].remaining();
+ if (size > 0)
+ {
+ int written = write(fd, srcs[i]);
+ if (written < 0)
+ {
+ break;
+ }
+ totalWritten += written;
+ if (written < size)
+ {
+ break;
+ }
+ }
+ }
+ return totalWritten;
}
// -- Miscellaneous utilities --
static InetSocketAddress checkAddress(SocketAddress sa) {
- if (sa == null)
- throw new IllegalArgumentException();
- if (!(sa instanceof InetSocketAddress))
- throw new UnsupportedAddressTypeException(); // ## needs arg
- InetSocketAddress isa = (InetSocketAddress)sa;
- if (isa.isUnresolved())
- throw new UnresolvedAddressException(); // ## needs arg
- return isa;
+ if (sa == null)
+ throw new IllegalArgumentException();
+ if (!(sa instanceof InetSocketAddress))
+ throw new UnsupportedAddressTypeException(); // ## needs arg
+ InetSocketAddress isa = (InetSocketAddress)sa;
+ if (isa.isUnresolved())
+ throw new UnresolvedAddressException(); // ## needs arg
+ return isa;
}
static InetSocketAddress asInetSocketAddress(SocketAddress sa) {
- if (!(sa instanceof InetSocketAddress))
- throw new UnsupportedAddressTypeException();
- return (InetSocketAddress)sa;
+ if (!(sa instanceof InetSocketAddress))
+ throw new UnsupportedAddressTypeException();
+ return (InetSocketAddress)sa;
}
static void translateToSocketException(Exception x)
- throws SocketException
+ throws SocketException
{
- if (x instanceof SocketException)
- throw (SocketException)x;
- Exception nx = x;
- if (x instanceof ClosedChannelException)
- nx = new SocketException("Socket is closed");
- else if (x instanceof AlreadyBoundException)
- nx = new SocketException("Already bound");
- else if (x instanceof NotYetBoundException)
- nx = new SocketException("Socket is not bound yet");
- else if (x instanceof UnsupportedAddressTypeException)
- nx = new SocketException("Unsupported address type");
- else if (x instanceof UnresolvedAddressException) {
- nx = new SocketException("Unresolved address");
- }
- if (nx != x)
- nx.initCause(x);
+ if (x instanceof SocketException)
+ throw (SocketException)x;
+ Exception nx = x;
+ if (x instanceof ClosedChannelException)
+ nx = new SocketException("Socket is closed");
+ else if (x instanceof AlreadyBoundException)
+ nx = new SocketException("Already bound");
+ else if (x instanceof NotYetBoundException)
+ nx = new SocketException("Socket is not bound yet");
+ else if (x instanceof UnsupportedAddressTypeException)
+ nx = new SocketException("Unsupported address type");
+ else if (x instanceof UnresolvedAddressException) {
+ nx = new SocketException("Unresolved address");
+ }
+ if (nx != x)
+ nx.initCause(x);
- if (nx instanceof SocketException)
- throw (SocketException)nx;
+ if (nx instanceof SocketException)
+ throw (SocketException)nx;
else if (nx instanceof RuntimeException)
- throw (RuntimeException)nx;
- else
- throw new Error("Untranslated exception", nx);
+ throw (RuntimeException)nx;
+ else
+ throw new Error("Untranslated exception", nx);
}
static void translateException(Exception x,
- boolean unknownHostForUnresolved)
- throws IOException
+ boolean unknownHostForUnresolved)
+ throws IOException
{
- if (x instanceof IOException)
- throw (IOException)x;
+ if (x instanceof IOException)
+ throw (IOException)x;
// Throw UnknownHostException from here since it cannot
// be thrown as a SocketException
- if (unknownHostForUnresolved &&
+ if (unknownHostForUnresolved &&
(x instanceof UnresolvedAddressException))
{
throw new UnknownHostException();
}
- translateToSocketException(x);
+ translateToSocketException(x);
}
static void translateException(Exception x)
- throws IOException
+ throws IOException
{
- translateException(x, false);
+ translateException(x, false);
}
}