List of usage examples for java.net Socket isOutputShutdown
public boolean isOutputShutdown()
From source file:Main.java
public static void main(String[] args) throws Exception { Socket client = new Socket("google.com", 80); System.out.println(client.isOutputShutdown()); client.close();/*from ww w .j a va2 s . com*/ }
From source file:com.sharneng.net.NetUtils.java
/** * Quietly shutdown the output of a {@linkplain Socket}. Exceptions are ignored. * /*from w ww .j a va 2s. co m*/ * @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); } }
From source file:com.googlecode.jmxtrans.connections.SocketFactory.java
/** * Validates that the socket is good.// w w w. j a v a 2 s . co m */ @Override public boolean validateObject(InetSocketAddress address, Socket socket) { if (socket == null) { log.error("Socket is null [{}]", address); return false; } if (!socket.isBound()) { log.error("Socket is not bound [{}]", address); return false; } if (socket.isClosed()) { log.error("Socket is closed [{}]", address); return false; } if (!socket.isConnected()) { log.error("Socket is not connected [{}]", address); return false; } if (socket.isInputShutdown()) { log.error("Socket input is shutdown [{}]", address); return false; } if (socket.isOutputShutdown()) { log.error("Socket output is shutdown [{}]", address); return false; } return true; }
From source file:com.symbian.driver.core.controller.tasks.TEFTask.java
/** * @param aVisitor/*from w w w . j a v a 2 s. c o m*/ * @param aTestExecuteScript * @param lExecuteOnDevice * @param aTask * @return The last execption raised when running UCC. * @throws JStatException */ private boolean runUCC(List<String> aArgs, Task aTask) { boolean lReturn = true; Socket lUccSocket = null; DataOutputStream lSocketOut = null; DataInputStream lSocketIn = null; int lRunNumber = 0; int lUccPort = -1; String lUccAddress = null; IDeviceComms.ISymbianProcess lProcess = null; try { String[] lUccSplit = TDConfig.getInstance().getPreference(TDConfig.UCC_IP_ADDRESS).split(":"); lRunNumber = TDConfig.getInstance().getPreferenceInteger(TDConfig.RUN_NUMBER); lUccAddress = lUccSplit[0]; lUccPort = Integer.parseInt(lUccSplit[1]); } catch (ParseException lParseException) { LOGGER.log(Level.SEVERE, "Could not get configuration for UCC.", lParseException); iExceptions.put(lParseException, ESeverity.ERROR); lReturn = false; } catch (NumberFormatException lNumberFormatException) { LOGGER.log(Level.SEVERE, "Could not parse the port number for UCC.", lNumberFormatException); iExceptions.put(lNumberFormatException, ESeverity.ERROR); lReturn = false; } if (lUccAddress == null || lUccAddress.equals("") || lUccPort < 0) { iExceptions.put( new UnknownHostException("Please specify a valid UCC address for example 192.168.0.1:3000"), ESeverity.ERROR); return false; } // Run the test try { LOGGER.info("Running UCC with:\n\tAddress: " + lUccAddress + "\n\tUCC Port:" + lUccPort); lUccSocket = new Socket(lUccAddress, lUccPort); lSocketOut = new DataOutputStream(lUccSocket.getOutputStream()); lSocketIn = new DataInputStream(lUccSocket.getInputStream()); LOGGER.fine("Starting UCC while still polling"); lProcess = iDeviceProxy.createSymbianProcess(); if (lProcess != null) { // run and don't wait if (!lProcess.runCommand(TEST_EXECUTE, aArgs, aTask.getTimeout() * 1000, false)) { iExceptions.put(new Exception("Failed to run TEF for UCC."), ESeverity.ERROR); lReturn = false; } // Tell UCC that the test has started. LOGGER.fine("Writing to UCC socket: " + lRunNumber); lSocketOut.writeInt(lRunNumber); lSocketOut.flush(); int lUCCReply = lSocketIn.readInt(); LOGGER.fine("UCC Reply: " + lUCCReply); } } catch (UnknownHostException lUnknownHostException) { LOGGER.log(Level.SEVERE, "Could not find UCC host", lUnknownHostException); iExceptions.put(lUnknownHostException, ESeverity.ERROR); return false; } catch (IOException lIOException) { LOGGER.log(Level.SEVERE, "IO Exception during UCC testing: " + lIOException.getMessage() + (lUccSocket != null ? "\nUcc Socket Connected: " + lUccSocket.isConnected() + "\nUcc Socket InputShutdown: " + lUccSocket.isInputShutdown() + "\nUcc Socket OutputShutdown:" + lUccSocket.isOutputShutdown() + "\nUcc Socket Bound: " + lUccSocket.isBound() : "\nUcc Socket is NULL"), lIOException); iExceptions.put(lIOException, ESeverity.ERROR); return false; } finally { // Close UCC if (lSocketOut != null) { try { LOGGER.log(Level.FINE, "Closing Socket Out."); lUccSocket.shutdownInput(); lUccSocket.shutdownOutput(); lSocketOut.close(); } catch (IOException lIOException) { LOGGER.log(Level.SEVERE, "Could not close UCC Out socket.", lIOException); iExceptions.put(lIOException, ESeverity.ERROR); } } if (lSocketIn != null) { try { LOGGER.log(Level.FINE, "Closing Socket In."); lSocketIn.close(); } catch (IOException lIOException) { LOGGER.log(Level.SEVERE, "Could not close UCC In socket.", lIOException); iExceptions.put(lIOException, ESeverity.ERROR); } } if (lUccSocket != null) { try { LOGGER.log(Level.FINE, "Closing Socket UCC."); lUccSocket.close(); } catch (IOException lIOException) { LOGGER.log(Level.SEVERE, "Could not close UCC socket.", lIOException); iExceptions.put(lIOException, ESeverity.ERROR); } } if (!lUccSocket.isClosed()) { LOGGER.warning("Could not close the UCC sockets properly."); } lSocketOut = null; lSocketIn = null; lUccSocket = null; // Poll TEF Test if (!lProcess.join()) { iExceptions.put(new Exception("Coud not join UCC-TEF Process"), ESeverity.ERROR); lReturn = false; } } return lReturn; }
From source file:org.apache.jmeter.visualizers.backend.graphite.SocketOutputStreamPoolFactory.java
/** *///from www. j a v a 2 s . c o m @Override public boolean validateObject(SocketConnectionInfos hostAndPort, PooledObject<SocketOutputStream> socketOutputStream) { Socket socket = socketOutputStream.getObject().getSocket(); return socket.isConnected() && socket.isBound() && !socket.isClosed() && !socket.isInputShutdown() && !socket.isOutputShutdown(); }
From source file:org.jmxtrans.embedded.util.pool.SocketOutputStreamPoolFactory.java
/** * Defensive approach: we test all the "<code>Socket.isXXX()</code>" flags. *///w ww. j a va2 s . c om @Override public boolean validateObject(HostAndPort hostAndPort, PooledObject<SocketOutputStream> socketOutputStreamRef) { Socket socket = socketOutputStreamRef.getObject().getSocket(); return socket.isConnected() && socket.isBound() && !socket.isClosed() && !socket.isInputShutdown() && !socket.isOutputShutdown(); }
From source file:org.jmxtrans.embedded.util.pool.SocketWriterPoolFactory.java
/** * Defensive approach: we test all the "<code>Socket.isXXX()</code>" flags. *///w w w. j a va 2s . c o m @Override public boolean validateObject(HostAndPort hostAndPort, PooledObject<SocketWriter> socketWriterRef) { Socket socket = socketWriterRef.getObject().getSocket(); return socket.isConnected() && socket.isBound() && !socket.isClosed() && !socket.isInputShutdown() && !socket.isOutputShutdown(); }