Path: blob/master/test/jdk/javax/net/ssl/SSLSocket/OutputStreamClosure.java
41152 views
/*1* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223//24// Please run in othervm mode. SunJSSE does not support dynamic system25// properties, no way to re-use system properties in samevm/agentvm mode.26//2728/*29* @test30* @bug 821632631* @modules jdk.crypto.ec32* @library /javax/net/ssl/templates33* @summary SSLSocket stream close() does not close the associated socket34* @run main/othervm OutputStreamClosure35*/36import java.io.InputStream;37import java.io.OutputStream;38import javax.net.ssl.SSLSocket;3940public class OutputStreamClosure extends SSLSocketTemplate {4142// Run the test case.43public static void main(String[] args) throws Exception {44(new OutputStreamClosure()).run();45}4647@Override48protected void runServerApplication(SSLSocket socket) throws Exception {49// here comes the test logic50InputStream sslIS = socket.getInputStream();51OutputStream sslOS = socket.getOutputStream();5253sslIS.read();54sslOS.write(85);55sslOS.flush();56}5758/*59* Define the client side application of the test for the specified socket.60* This method is used if the returned value of61* isCustomizedClientConnection() is false.62*63* @param socket may be null is no client socket is generated.64*65* @see #isCustomizedClientConnection()66*/67protected void runClientApplication(SSLSocket socket) throws Exception {68InputStream sslIS = socket.getInputStream();69OutputStream sslOS = socket.getOutputStream();7071sslOS.write(280);72sslOS.flush();73sslIS.read();7475sslOS.close();76if (!socket.isClosed()) {77throw new Exception("Closing the SSLSocket OutputStream does " +78"not close the associated socket");79}80}81}828384