Path: blob/master/test/jdk/java/io/PrintWriter/ClearErrorWriter.java
41149 views
/*1* Copyright (c) 2005, 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* @test25* @bug 449125526* @summary Test for a new protected method PrintWriter.clearError()27* to reset its internal error state28*/2930import java.io.*;3132public class ClearErrorWriter extends PrintWriter {333435public ClearErrorWriter(Writer w, boolean autoFlush) {36super(w, autoFlush);37}3839public static void main(String[] args) throws Exception {4041File f = new File(System.getProperty("test.dir", "."),42"print-writer.out");43f.deleteOnExit();44ClearErrorWriter out = new ClearErrorWriter(new BufferedWriter(45new FileWriter(f)),46true);47out.println("Hello World!");48out.close();49out.println("Writing after close");5051if (out.checkError()) {52System.out.println("An error occured");53out.clearError();5455if (!out.checkError()) {56System.out.println("Error status cleared");57} else {58throw new Exception("Error Status unchanged");59}60}61else {62System.out.println(" No error occured");63}64}65}666768