jdk/test/java/net/Socket/UrgentDataTest.java
changeset 6115 7c523cf2bc8a
parent 5506 202f599c92aa
child 7668 d4a77089c587
--- a/jdk/test/java/net/Socket/UrgentDataTest.java	Tue Jul 20 10:41:50 2010 -0400
+++ b/jdk/test/java/net/Socket/UrgentDataTest.java	Wed Jul 21 13:29:26 2010 +0100
@@ -90,63 +90,64 @@
     }
 
     public void run () throws Exception {
-        if (isClient) {
-            client = new Socket (clHost, clPort);
-            clis = client.getInputStream();
-            clos = client.getOutputStream();
-            client.setOOBInline (true);
-            if (client.getOOBInline() != true) {
-                throw new RuntimeException ("Setting OOBINLINE failed");
-            }
-        }
-        if (isServer) {
-            server = listener.accept ();
-            sis = server.getInputStream();
-            sos = server.getOutputStream();
-        }
-        if (isClient) {
-            clos.write ("Hello".getBytes ());
-            client.sendUrgentData (100);
-            clos.write ("world".getBytes ());
-        }
-        // read Hello world from server (during which oob byte must have been dropped)
-        String s = "Helloworld";
-        if (isServer) {
-            for (int y=0; y<s.length(); y++) {
-                int c = sis.read ();
-                if (c != (int)s.charAt (y)) {
-                    throw new RuntimeException ("Unexpected character read");
+        try {
+            if (isClient) {
+                client = new Socket (clHost, clPort);
+                clis = client.getInputStream();
+                clos = client.getOutputStream();
+                client.setOOBInline (true);
+                if (client.getOOBInline() != true) {
+                    throw new RuntimeException ("Setting OOBINLINE failed");
                 }
             }
-            // Do the same from server to client
-            sos.write ("Hello".getBytes ());
-            server.sendUrgentData (101);
-            sos.write ("World".getBytes ());
-        }
-        if (isClient) {
-            // read Hello world from client (during which oob byte must have been read)
-            s="Hello";
-            for (int y=0; y<s.length(); y++) {
-                int c = clis.read ();
-                if (c != (int)s.charAt (y)) {
-                    throw new RuntimeException ("Unexpected character read");
+            if (isServer) {
+                server = listener.accept ();
+                sis = server.getInputStream();
+                sos = server.getOutputStream();
+            }
+            if (isClient) {
+                clos.write ("Hello".getBytes ());
+                client.sendUrgentData (100);
+                clos.write ("world".getBytes ());
+            }
+            // read Hello world from server (during which oob byte must have been dropped)
+            String s = "Helloworld";
+            if (isServer) {
+                for (int y=0; y<s.length(); y++) {
+                    int c = sis.read ();
+                    if (c != (int)s.charAt (y)) {
+                        throw new RuntimeException ("Unexpected character read");
+                    }
+                }
+                // Do the same from server to client
+                sos.write ("Hello".getBytes ());
+                server.sendUrgentData (101);
+                sos.write ("World".getBytes ());
+            }
+            if (isClient) {
+                // read Hello world from client (during which oob byte must have been read)
+                s="Hello";
+                for (int y=0; y<s.length(); y++) {
+                    int c = clis.read ();
+                    if (c != (int)s.charAt (y)) {
+                        throw new RuntimeException ("Unexpected character read");
+                    }
+                }
+                if (clis.read() != 101) {
+                    throw new RuntimeException ("OOB byte not received");
+                }
+                s="World";
+                for (int y=0; y<s.length(); y++) {
+                    int c = clis.read ();
+                    if (c != (int)s.charAt (y)) {
+                        throw new RuntimeException ("Unexpected character read");
+                    }
                 }
             }
-            if (clis.read() != 101) {
-                throw new RuntimeException ("OOB byte not received");
-            }
-            s="World";
-            for (int y=0; y<s.length(); y++) {
-                int c = clis.read ();
-                if (c != (int)s.charAt (y)) {
-                    throw new RuntimeException ("Unexpected character read");
-                }
-            }
+        } finally {
+            if (listener != null) listener.close();
+            if (client != null) client.close ();
+            if (server != null) server.close ();
         }
-
-        if (isClient)
-            client.close ();
-        if (isServer)
-            server.close ();
     }
 }