test/java/io/OutputStreamWriter/Encode.java

Print this page
rev 3565 : 7022624: use try-with-resources in java.io tests
Reviewed-by: XXX

*** 54,75 **** } ServerSocket ss; public void run() { ! try { ! Socket s = ss.accept(); ! BufferedReader in = new BufferedReader( ! new InputStreamReader(s.getInputStream())); String req = in.readLine(); ! PrintStream out = new PrintStream(new BufferedOutputStream( ! s.getOutputStream())); out.print("HTTP/1.1 403 Forbidden\r\n"); out.print("\r\n"); ! out.flush(); ! s.close(); ! ss.close(); } catch (Exception e) { e.printStackTrace(); } } } --- 54,77 ---- } ServerSocket ss; public void run() { ! try (ServerSocket serv = ss; ! Socket s = serv.accept(); ! InputStream is = s.getInputStream(); ! InputStreamReader isr = new InputStreamReader(is); ! BufferedReader in = new BufferedReader(isr)) ! { String req = in.readLine(); ! try (OutputStream os = s.getOutputStream(); ! BufferedOutputStream bos = new BufferedOutputStream(os); ! PrintStream out = new PrintStream(bos)) ! { out.print("HTTP/1.1 403 Forbidden\r\n"); out.print("\r\n"); ! } } catch (Exception e) { e.printStackTrace(); } } }