@Override public boolean isConnected() { return channel.isConnected(); }
@Override public InputStream getInputStream() throws IOException { if (!channel.isOpen()) { throw new SocketException("Socket is closed"); } if (!channel.isConnected()) { throw new SocketException("Socket is not connected"); } if (inputShutdown) { throw new SocketException("Socket input is shutdown"); } return new FilterInputStream(Channels.newInputStream(channel)) { @Override public void close() throws IOException { shutdownInput(); } }; }
@Override public OutputStream getOutputStream() throws IOException { if (!channel.isOpen()) { throw new SocketException("Socket is closed"); } if (!channel.isConnected()) { throw new SocketException("Socket is not connected"); } if (outputShutdown) { throw new SocketException("Socket output is shutdown"); } return new FilterOutputStream(Channels.newOutputStream(channel)) { @Override public void write(byte[] b, int off, int len) throws IOException { out.write(b, off, len); } @Override public void close() throws IOException { shutdownOutput(); } }; }
@Override public boolean isConnected() { return chan.isConnected(); }
@Override public boolean isConnected() { return channel.isConnected(); }
public InputStream getInputStream() throws IOException { if (chan.isConnected()) { return in; } else { throw new IOException("not connected"); } }
@Override public OutputStream getOutputStream() throws IOException { if (chan.isConnected()) { return out; } else { throw new IOException("not connected"); } }
@Override public long write(ByteBuffer[] srcs, int offset, int length) throws IOException { if (isConnected()) { return super.write(srcs, offset, length); } else if (isIdle()) { return 0; } else { throw new ClosedChannelException(); } }
@Override public int read(ByteBuffer dst) throws IOException { if (isConnected()) { return super.read(dst); } else if (isIdle()) { return 0; } else { throw new ClosedChannelException(); } }
@Override public int write(ByteBuffer src) throws IOException { if (isConnected()) { return super.write(src); } else if (isIdle()) { return 0; } else { throw new ClosedChannelException(); } }
public final UnixSocketAddress getRemoteSocketAddress() { if (!isConnected()) { return null; } if (remoteAddress != null) { return remoteAddress; } else { remoteAddress = Common.getpeername(getFD()); return remoteAddress; } }
@Override public InputStream getInputStream() throws IOException { if (!channel.isOpen()) { throw new SocketException("Socket is closed"); } if (!channel.isConnected()) { throw new SocketException("Socket is not connected"); } if (inputShutdown) { throw new SocketException("Socket input is shutdown"); } return new FilterInputStream(Channels.newInputStream(channel)) { @Override public void close() throws IOException { shutdownInput(); } }; }
@Override public OutputStream getOutputStream() throws IOException { if (!channel.isOpen()) { throw new SocketException("Socket is closed"); } if (!channel.isConnected()) { throw new SocketException("Socket is not connected"); } if (outputShutdown) { throw new SocketException("Socket output is shutdown"); } return new FilterOutputStream(Channels.newOutputStream(channel)) { @Override public void write(byte[] b, int off, int len) throws IOException { out.write(b, off, len); } @Override public void close() throws IOException { shutdownOutput(); } }; }
/** * Retrieves the credentials for this UNIX socket. Clients calling this * method will receive the server's credentials, and servers will receive * the client's credentials. User ID, group ID, and PID are supplied. * * See man unix 7; SCM_CREDENTIALS * * @throws UnsupportedOperationException if the underlying socket library * doesn't support the SO_PEERCRED option * @throws SocketException if fetching the socket option failed. * * @return the credentials of the remote; null if not connected */ public final Credentials getCredentials() throws SocketException { if (!chan.isConnected()) { return null; } try { return chan.getOption(UnixSocketOptions.SO_PEERCRED); } catch (IOException e) { throw (SocketException)new SocketException().initCause(e); } }