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

The following examples show how to use java.net.Socket#isOutputShutdown() . 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 File: SocketUtils.java    From nifi with 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 2
Source File: SocketUtils.java    From localization_nifi with 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 3
Source File: NioSocket.java    From triplea with 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 4
Source File: SqueakTCPSocket.java    From trufflesqueak with 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 5
Source File: SslSource.java    From Azzet with 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 6
Source File: NetUtils.java    From portforward with 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 7
Source File: HttpProxyCacheServer.java    From AndroidVideoCache with Apache License 2.0 5 votes vote down vote up
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 8
Source File: MegaProxyServer.java    From megabasterd with GNU General Public License v3.0 5 votes vote down vote up
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 9
Source File: HttpProxyCacheServer.java    From GSYVideoPlayer with Apache License 2.0 5 votes vote down vote up
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 10
Source File: HttpProxyCacheServer.java    From DKVideoPlayer with Apache License 2.0 5 votes vote down vote up
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 11
Source File: HttpProxyCacheServer.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
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 12
Source File: HttpProxyCacheServer.java    From AndriodVideoCache with Apache License 2.0 5 votes vote down vote up
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 13
Source File: HttpProxyCacheServer.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
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 14
Source File: RpcSocketPool.java    From p4ic4idea with 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 15
Source File: RpcSocketPool.java    From p4ic4idea with 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 File: RpcSocketPool.java    From p4ic4idea with 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 File: RpcSocketPool.java    From p4ic4idea with 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 File: RpcSocketPool.java    From p4ic4idea with 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 File: RpcSocketPool.java    From p4ic4idea with 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 File: NioSocketChannel.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isShutdown() {
    Socket socket = javaChannel().socket();
    return socket.isInputShutdown() && socket.isOutputShutdown() || !isActive();
}