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

The following examples show how to use java.net.Socket#shutdownInput() . 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: ShutdownInput.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void test(Socket s1, Socket s2, String mesg) throws Exception {
    OutputStream os = s1.getOutputStream();
    os.write("This is a message".getBytes("US-ASCII"));

    InputStream in = s2.getInputStream();
    s2.shutdownInput();

    if (in.available() != 0) {
        failed = true;
        System.out.println(mesg + ":" + s2 + " in.available() should be 0, " +
                           "but returns "+ in.available());
    }

    byte[] ba = new byte[2];
    if (in.read() != -1 ||
        in.read(ba) != -1 ||
        in.read(ba, 0, ba.length) != -1) {

        failed = true;
        System.out.append(mesg + ":" + s2 + " in.read() should be -1");
    }
}
 
Example 2
Source File: ShutdownInput.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void test(Socket s1, Socket s2, String mesg) throws Exception {
    OutputStream os = s1.getOutputStream();
    os.write("This is a message".getBytes("US-ASCII"));

    InputStream in = s2.getInputStream();
    s2.shutdownInput();

    if (in.available() != 0) {
        failed = true;
        System.out.println(mesg + ":" + s2 + " in.available() should be 0, " +
                           "but returns "+ in.available());
    }

    byte[] ba = new byte[2];
    if (in.read() != -1 ||
        in.read(ba) != -1 ||
        in.read(ba, 0, ba.length) != -1) {

        failed = true;
        System.out.append(mesg + ":" + s2 + " in.read() should be -1");
    }
}
 
Example 3
Source File: ShutdownInput.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void test(Socket s1, Socket s2, String mesg) throws Exception {
    OutputStream os = s1.getOutputStream();
    os.write("This is a message".getBytes("US-ASCII"));

    InputStream in = s2.getInputStream();
    s2.shutdownInput();

    if (in.available() != 0) {
        failed = true;
        System.out.println(mesg + ":" + s2 + " in.available() should be 0, " +
                           "but returns "+ in.available());
    }

    byte[] ba = new byte[2];
    if (in.read() != -1 ||
        in.read(ba) != -1 ||
        in.read(ba, 0, ba.length) != -1) {

        failed = true;
        System.out.append(mesg + ":" + s2 + " in.read() should be -1");
    }
}
 
Example 4
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 5
Source File: ShutdownInput.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void test(Socket s1, Socket s2, String mesg) throws Exception {
    OutputStream os = s1.getOutputStream();
    os.write("This is a message".getBytes("US-ASCII"));

    InputStream in = s2.getInputStream();
    s2.shutdownInput();

    if (in.available() != 0) {
        failed = true;
        System.out.println(mesg + ":" + s2 + " in.available() should be 0, " +
                           "but returns "+ in.available());
    }

    byte[] ba = new byte[2];
    if (in.read() != -1 ||
        in.read(ba) != -1 ||
        in.read(ba, 0, ba.length) != -1) {

        failed = true;
        System.out.append(mesg + ":" + s2 + " in.read() should be -1");
    }
}
 
Example 6
Source File: ShutdownInput.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void test(Socket s1, Socket s2, String mesg) throws Exception {
    OutputStream os = s1.getOutputStream();
    os.write("This is a message".getBytes("US-ASCII"));

    InputStream in = s2.getInputStream();
    s2.shutdownInput();

    if (in.available() != 0) {
        failed = true;
        System.out.println(mesg + ":" + s2 + " in.available() should be 0, " +
                           "but returns "+ in.available());
    }

    byte[] ba = new byte[2];
    if (in.read() != -1 ||
        in.read(ba) != -1 ||
        in.read(ba, 0, ba.length) != -1) {

        failed = true;
        System.out.append(mesg + ":" + s2 + " in.read() should be -1");
    }
}
 
Example 7
Source File: ShutdownInput.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void test(Socket s1, Socket s2, String mesg) throws Exception {
    OutputStream os = s1.getOutputStream();
    os.write("This is a message".getBytes("US-ASCII"));

    InputStream in = s2.getInputStream();
    s2.shutdownInput();

    if (in.available() != 0) {
        failed = true;
        System.out.println(mesg + ":" + s2 + " in.available() should be 0, " +
                           "but returns "+ in.available());
    }

    byte[] ba = new byte[2];
    if (in.read() != -1 ||
        in.read(ba) != -1 ||
        in.read(ba, 0, ba.length) != -1) {

        failed = true;
        System.out.append(mesg + ":" + s2 + " in.read() should be -1");
    }
}
 
Example 8
Source File: ShutdownInput.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void test(Socket s1, Socket s2, String mesg) throws Exception {
    OutputStream os = s1.getOutputStream();
    os.write("This is a message".getBytes("US-ASCII"));

    InputStream in = s2.getInputStream();
    s2.shutdownInput();

    if (in.available() != 0) {
        failed = true;
        System.out.println(mesg + ":" + s2 + " in.available() should be 0, " +
                           "but returns "+ in.available());
    }

    byte[] ba = new byte[2];
    if (in.read() != -1 ||
        in.read(ba) != -1 ||
        in.read(ba, 0, ba.length) != -1) {

        failed = true;
        System.out.append(mesg + ":" + s2 + " in.read() should be -1");
    }
}
 
Example 9
Source File: SocketReconnectTest.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
public void shutdown() {
    if (!shutdown) {
        shutdown = true;
        if (server != null && server.isBound()) {
            try {
                if (client != null) {
                    Socket serverClient = client;
                    client = null;
                    serverClient.shutdownInput();
                    serverClient.shutdownOutput();
                    serverClient.setSoLinger(true, 0);
                    serverClient.close();
                }
                ServerSocket serverSocket = server;
                server = null;
                serverSocket.close();
            } catch (Exception ex) {
                System.out.println("Unable to send shutdown message");
                ex.printStackTrace();
            }
        }
        return;
    }
}
 
Example 10
Source File: ShutdownInput.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void test(Socket s1, Socket s2, String mesg) throws Exception {
    OutputStream os = s1.getOutputStream();
    os.write("This is a message".getBytes("US-ASCII"));

    InputStream in = s2.getInputStream();
    s2.shutdownInput();

    if (in.available() != 0) {
        failed = true;
        System.out.println(mesg + ":" + s2 + " in.available() should be 0, " +
                           "but returns "+ in.available());
    }

    byte[] ba = new byte[2];
    if (in.read() != -1 ||
        in.read(ba) != -1 ||
        in.read(ba, 0, ba.length) != -1) {

        failed = true;
        System.out.append(mesg + ":" + s2 + " in.read() should be -1");
    }
}
 
Example 11
Source File: ShutdownInput.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void test(Socket s1, Socket s2, String mesg) throws Exception {
    OutputStream os = s1.getOutputStream();
    os.write("This is a message".getBytes("US-ASCII"));

    InputStream in = s2.getInputStream();
    s2.shutdownInput();

    if (in.available() != 0) {
        failed = true;
        System.out.println(mesg + ":" + s2 + " in.available() should be 0, " +
                           "but returns "+ in.available());
    }

    byte[] ba = new byte[2];
    if (in.read() != -1 ||
        in.read(ba) != -1 ||
        in.read(ba, 0, ba.length) != -1) {

        failed = true;
        System.out.append(mesg + ":" + s2 + " in.read() should be -1");
    }
}
 
Example 12
Source File: ShutdownInput.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void test(Socket s1, Socket s2, String mesg) throws Exception {
    OutputStream os = s1.getOutputStream();
    os.write("This is a message".getBytes("US-ASCII"));

    InputStream in = s2.getInputStream();
    s2.shutdownInput();

    if (in.available() != 0) {
        failed = true;
        System.out.println(mesg + ":" + s2 + " in.available() should be 0, " +
                           "but returns "+ in.available());
    }

    byte[] ba = new byte[2];
    if (in.read() != -1 ||
        in.read(ba) != -1 ||
        in.read(ba, 0, ba.length) != -1) {

        failed = true;
        System.out.append(mesg + ":" + s2 + " in.read() should be -1");
    }
}
 
Example 13
Source File: ShutdownInput.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void test(Socket s1, Socket s2, String mesg) throws Exception {
    OutputStream os = s1.getOutputStream();
    os.write("This is a message".getBytes("US-ASCII"));

    InputStream in = s2.getInputStream();
    s2.shutdownInput();

    if (in.available() != 0) {
        failed = true;
        System.out.println(mesg + ":" + s2 + " in.available() should be 0, " +
                           "but returns "+ in.available());
    }

    byte[] ba = new byte[2];
    if (in.read() != -1 ||
        in.read(ba) != -1 ||
        in.read(ba, 0, ba.length) != -1) {

        failed = true;
        System.out.append(mesg + ":" + s2 + " in.read() should be -1");
    }
}
 
Example 14
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 15
Source File: ShutdownInput.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static void test(Socket s1, Socket s2, String mesg) throws Exception {
    OutputStream os = s1.getOutputStream();
    os.write("This is a message".getBytes("US-ASCII"));

    InputStream in = s2.getInputStream();
    s2.shutdownInput();

    if (in.available() != 0) {
        failed = true;
        System.out.println(mesg + ":" + s2 + " in.available() should be 0, " +
                           "but returns "+ in.available());
    }

    byte[] ba = new byte[2];
    if (in.read() != -1 ||
        in.read(ba) != -1 ||
        in.read(ba, 0, ba.length) != -1) {

        failed = true;
        System.out.append(mesg + ":" + s2 + " in.read() should be -1");
    }
}
 
Example 16
Source File: ShutdownInput.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void test(Socket s1, Socket s2, String mesg) throws Exception {
    OutputStream os = s1.getOutputStream();
    os.write("This is a message".getBytes("US-ASCII"));

    InputStream in = s2.getInputStream();
    s2.shutdownInput();

    if (in.available() != 0) {
        failed = true;
        System.out.println(mesg + ":" + s2 + " in.available() should be 0, " +
                           "but returns "+ in.available());
    }

    byte[] ba = new byte[2];
    if (in.read() != -1 ||
        in.read(ba) != -1 ||
        in.read(ba, 0, ba.length) != -1) {

        failed = true;
        System.out.append(mesg + ":" + s2 + " in.read() should be -1");
    }
}
 
Example 17
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 18
Source File: TestSocketServlet.java    From appengine-java-vm-runtime with Apache License 2.0 5 votes vote down vote up
private void testShutDownAndClose(HttpServletResponse response)
    throws UnknownHostException, IOException {
  Socket socket = new Socket("10.1.1.1", 80);
  socket.shutdownInput();
  socket.shutdownOutput();
  socket.close();
}
 
Example 19
Source File: EvolutionPanel.java    From iMetrica with GNU General Public License v3.0 4 votes vote down vote up
public void run()
     {
        System.out.println("start up IQ");
		try {
                       //
			// Launch IQFeed and Register the app with IQFeed.
// 			System.out.println("Launching IQConnect.");
// 			//Runtime.getRuntime().exec("/usr/bin/wine IQConnect.exe ‑product SIMON_OTZIGER_6345 -version 2.9.0.13 ‑login 422113 ‑password 76059316");
// 			System.out.println("Verifying if IQConnect is connected to the server");
// 			Thread.sleep(12000);
// 			// verify everything is ready to send commands.
// 			boolean bConnected = false;
// 			// connect to the admin port.
// 			Socket sockAdmin = new Socket(InetAddress.getByName("192.168.56.10"), 8300);
			
			System.out.println("Launching IQConnect.");
	
                        //Runtime.getRuntime().exec("/usr/bin/wine IQConnect.exe -product JEANPIERRE_ROBALO_11529 -version 2.9.0.13 ‑login 431660 ‑password 70433790");
                        Runtime.getRuntime().exec("/usr/bin/wine IQConnect.exe -product PRABIN_SETH_11606 -version 2.9.0.13 ‑login 438106 ‑password 64568341");
			System.out.println("Verifying if IQConnect is connected to the server");
			Thread.sleep(12000);
			//verify everything is ready to send commands.
			boolean bConnected = false;
			//connect to the admin port.
			Socket sockAdmin = new Socket(InetAddress.getByName("localhost"), 9300);			
			
			
			BufferedReader bufreadAdmin = new BufferedReader(new InputStreamReader(sockAdmin.getInputStream()));
			BufferedWriter bufwriteAdmin = new BufferedWriter(new OutputStreamWriter(sockAdmin.getOutputStream()));
			String sAdminLine = "";
			// loop while we are still connected to the admin port or until we are connected
			while (((sAdminLine = bufreadAdmin.readLine()) != null) && !bConnected)
			{
				System.out.println(sAdminLine);
				if (sAdminLine.indexOf(",Connected,") > -1)
				{
					System.out.println("IQConnect is connected to the server.");
					bConnected = true;
				}
				else if (sAdminLine.indexOf(",Not Connected,") > -1)
				{
					System.out.println("IQConnect is Not Connected.\r\nSending connect command.");
					bufwriteAdmin.write("S,CONNECT\r\n");
					bufwriteAdmin.flush();
				}
			}
			// cleanup admin port connection
			sockAdmin.shutdownOutput();
			sockAdmin.shutdownInput();
			sockAdmin.close();
			bufreadAdmin.close();
			bufwriteAdmin.close();

			// at this point, we are connected and the feed is ready.
			int total_num_assets = 8;
			
// 			for(int i = 0; i < n_basket; i++)
// 			{total_num_assets = total_num_assets + ppms[i].name.length;}
// 			
// 			total_num_assets = ppms.length*3; 
			s_outs = new BufferedWriter[total_num_assets];
			s_ins = new BufferedReader[total_num_assets];
			Socket[] socks = new Socket[total_num_assets];
			
			for(int i = 0; i < total_num_assets; i++)
                       {
                         socks[i] = new Socket(InetAddress.getByName("localhost"), 9100);
	                 //socks[i] = new Socket(InetAddress.getByName("192.168.56.10"), 8100);
	                 s_ins[i] = new BufferedReader(new InputStreamReader(socks[i].getInputStream()));
	                 s_outs[i] = new BufferedWriter(new OutputStreamWriter(socks[i].getOutputStream()));
	                 // Set the lookup port to protocol 5.0 to allow for millisecond times, 
                         // market center, trade conditions, etc
                         s_outs[i].write("S,SET PROTOCOL,5.0\r\n");
                         s_outs[i].flush();   
	               }
                        
                     }
                     catch (Exception e)
		     {e.printStackTrace();}    
    
    
      }
 
Example 20
Source File: GridNioSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Sends message and validates reply.
 *
 * @param port Port.
 * @param msg Message to send.
 */
private void validateSendMessage(int port, byte[] msg) {
    try {
        Socket s = createSocket();

        s.connect(new InetSocketAddress(U.getLocalHost(), port), 1000);

        try {
            s.getOutputStream().write(msg);

            byte[] res = new byte[MSG_SIZE];

            int rcvd = 0;

            InputStream inputStream = s.getInputStream();

            while (rcvd < res.length) {
                int cnt = inputStream.read(res, rcvd, res.length - rcvd);

                if (cnt == -1)
                    fail("Server closed connection before echo reply was fully sent");

                rcvd += cnt;
            }

            if (!(s instanceof SSLSocket)) {
                s.shutdownOutput();

                s.shutdownInput();
            }

            assertEquals(msg.length, res.length);

            for (int i = 0; i < msg.length; i++)
                assertEquals("Mismatch in position " + i, msg[i], res[i]);
        }
        finally {
            s.close();
        }
    }
    catch (Exception e) {
        fail("Exception while sending message: " + e.getMessage());
    }
}