Java Code Examples for java.net.Socket#isOutputShutdown()

The following examples show how to use java.net.Socket#isOutputShutdown() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: localization_nifi   File: SocketUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static void closeQuietly(final Socket socket) {
    if (socket == null) {
        return;
    }

    try {
        try {
            // can't shudown input/output individually with secure sockets
            if ((socket instanceof SSLSocket) == false) {
                if (socket.isInputShutdown() == false) {
                    socket.shutdownInput();
                }
                if (socket.isOutputShutdown() == false) {
                    socket.shutdownOutput();
                }
            }
        } finally {
            if (socket.isClosed() == false) {
                socket.close();
            }
        }
    } catch (final Exception ex) {
        logger.debug("Failed to close socket due to: " + ex, ex);
    }
}
 
Example 2
Source Project: trufflesqueak   File: SqueakTCPSocket.java    License: MIT License 6 votes vote down vote up
private Status clientStatus() throws IOException {
    if (clientChannel == null) {
        return Status.Unconnected;
    }

    maybeCompleteConnection();
    final Socket socket = clientChannel.socket();

    if (socket.isInputShutdown()) {
        return Status.OtherEndClosed;
    }

    if (socket.isOutputShutdown()) {
        return Status.ThisEndClosed;
    }

    if (!socket.isConnected()) {
        return Status.Unconnected;
    }

    if (socket.isClosed()) {
        return Status.ThisEndClosed;
    }

    return Status.Connected;
}
 
Example 3
Source Project: Azzet   File: SslSource.java    License: Open Software License 3.0 6 votes vote down vote up
@Override
public InputStream getStream( String request ) throws Exception
{
	byte[] path = getAbsolute( request ).getBytes();

	Socket s = socketPool.poll();
	if (s == null || s.isClosed() || s.isOutputShutdown() || s.isInputShutdown())
	{
		s = socketFactory.createSocket( address.getAddress(), address.getPort() );
	}

	DataOutputStream o = new DataOutputStream( s.getOutputStream() );
	o.writeInt( path.length );
	o.write( path );
	o.flush();

	DataInputStream i = new DataInputStream( s.getInputStream() );
	int size = i.readInt();

	return new SocketInputStream( s, size, socketPool );
}
 
Example 4
Source Project: triplea   File: NioSocket.java    License: GNU General Public License v3.0 6 votes vote down vote up
/** Close the channel, and clean up any data associated with it. */
public void close(final SocketChannel channel) {
  try {
    final Socket s = channel.socket();
    if (!s.isInputShutdown()) {
      s.shutdownInput();
    }
    if (!s.isOutputShutdown()) {
      s.shutdownOutput();
    }
    if (!s.isClosed()) {
      s.close();
    }
    channel.close();
  } catch (final IOException e1) {
    log.log(Level.FINE, "error closing channel", e1);
  }
  decoder.close(channel);
  writer.close(channel);
  reader.close(channel);
}
 
Example 5
Source Project: nifi   File: SocketUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static void closeQuietly(final Socket socket) {
    if (socket == null) {
        return;
    }

    try {
        try {
            // Can't shutdown input/output individually with secure sockets
            if (!(socket instanceof SSLSocket)) {
                if (!socket.isInputShutdown()) {
                    socket.shutdownInput();
                }
                if (!socket.isOutputShutdown()) {
                    socket.shutdownOutput();
                }
            }
        } finally {
            if (!socket.isClosed()) {
                socket.close();
            }
        }
    } catch (final Exception ex) {
        logger.debug("Failed to close socket due to: " + ex, ex);
    }
}
 
Example 6
private void closeSocketOutput(Socket socket) {
    try {
        if (!socket.isOutputShutdown()) {
            socket.shutdownOutput();
        }
    } catch (IOException e) {
        VenvyLog.w("Failed to close socket on proxy side: {}. It seems client have already closed connection.", e.getMessage());
    }
}
 
Example 7
private void closeSocketOutput(Socket socket) {
    try {
        if (!socket.isOutputShutdown()) {
            socket.shutdownOutput();
        }
    } catch (IOException e) {
        KLog.w("Failed to close socket on proxy side: {}. It seems client have already closed connection.", e.getMessage());
    }
}
 
Example 8
private void closeSocketOutput(Socket socket) {
    try {
        if (!socket.isOutputShutdown()) {
            socket.shutdownOutput();
        }
    } catch (IOException e) {
        LOG.warn("Failed to close socket on proxy side: {}. It seems client have already closed connection.", e.getMessage());
    }
}
 
Example 9
private void closeSocketOutput(Socket socket) {
    try {
        if (!socket.isOutputShutdown()) {
            socket.shutdownOutput();
        }
    } catch (IOException e) {
        Logger.warn("Failed to close socket on proxy side: {}. It seems client have already closed connection.");
    }
}
 
Example 10
private void closeSocketOutput(Socket socket) {
    try {
        if (!socket.isOutputShutdown()) {
            socket.shutdownOutput();
        }
    } catch (IOException e) {
        HttpProxyCacheDebuger.printfWarning("Failed to close socket on proxy side: {}. It seems client have already closed connection.", e.getMessage());
    }
}
 
Example 11
private static void forwardData(Socket inputSocket, Socket outputSocket) {
    try {
        InputStream inputStream = inputSocket.getInputStream();
        try {
            OutputStream outputStream = outputSocket.getOutputStream();
            try {
                byte[] buffer = new byte[4096];
                int read;
                do {
                    read = inputStream.read(buffer);
                    if (read > 0) {
                        outputStream.write(buffer, 0, read);
                        if (inputStream.available() < 1) {
                            outputStream.flush();
                        }
                    }
                } while (read >= 0);
            } finally {
                if (!outputSocket.isOutputShutdown()) {
                    outputSocket.shutdownOutput();
                }
            }
        } finally {
            if (!inputSocket.isInputShutdown()) {
                inputSocket.shutdownInput();
            }
        }
    } catch (IOException e) {

    }
}
 
Example 12
private void closeSocketOutput(Socket socket) {
    try {
        if (!socket.isOutputShutdown()) {
            socket.shutdownOutput();
        }
    } catch (IOException e) {
        LOG.warn("Failed to close socket on proxy side: {}. It seems client have already closed connection.", e.getMessage());
    }
}
 
Example 13
Source Project: portforward   File: NetUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Quietly shutdown the output of a {@linkplain Socket}. Exceptions are ignored.
 * 
 * @param socket
 *            the socket to shutdown the output
 * @see Socket#shutdownOutput()
 */
public static void shutdownOutput(Socket socket) {
    if (socket == null) return;
    try {
        if (!socket.isOutputShutdown()) socket.shutdownOutput();
    } catch (Throwable e) {
        log.debug(e.getMessage(), e);
    }
}
 
Example 14
Source Project: netty-4.1.22   File: NioSocketChannel.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean isShutdown() {
    Socket socket = javaChannel().socket();
    return socket.isInputShutdown() && socket.isOutputShutdown() || !isActive();
}
 
Example 15
Source Project: p4ic4idea   File: RpcSocketPool.java    License: Apache License 2.0 4 votes vote down vote up
private boolean isAlive(Socket socket) {
	return socket != null && socket.isBound() && !socket.isClosed()
			&& socket.isConnected() && !socket.isInputShutdown()
			&& !socket.isOutputShutdown();
}
 
Example 16
Source Project: p4ic4idea   File: RpcSocketPool.java    License: Apache License 2.0 4 votes vote down vote up
private boolean isAlive(Socket socket) {
	return socket != null && socket.isBound() && !socket.isClosed()
			&& socket.isConnected() && !socket.isInputShutdown()
			&& !socket.isOutputShutdown();
}
 
Example 17
Source Project: p4ic4idea   File: RpcSocketPool.java    License: Apache License 2.0 4 votes vote down vote up
private boolean isAlive(Socket socket) {
	return socket != null && socket.isBound() && !socket.isClosed()
			&& socket.isConnected() && !socket.isInputShutdown()
			&& !socket.isOutputShutdown();
}
 
Example 18
Source Project: p4ic4idea   File: RpcSocketPool.java    License: Apache License 2.0 4 votes vote down vote up
private boolean isAlive(Socket socket) {
	return socket != null && socket.isBound() && !socket.isClosed()
			&& socket.isConnected() && !socket.isInputShutdown()
			&& !socket.isOutputShutdown();
}
 
Example 19
Source Project: p4ic4idea   File: RpcSocketPool.java    License: Apache License 2.0 4 votes vote down vote up
private boolean isAlive(Socket socket) {
	return socket != null && socket.isBound() && !socket.isClosed()
			&& socket.isConnected() && !socket.isInputShutdown()
			&& !socket.isOutputShutdown();
}
 
Example 20
Source Project: p4ic4idea   File: RpcSocketPool.java    License: Apache License 2.0 4 votes vote down vote up
private boolean isAlive(Socket socket) {
	return socket != null && socket.isBound() && !socket.isClosed()
			&& socket.isConnected() && !socket.isInputShutdown()
			&& !socket.isOutputShutdown();
}