Path: blob/master/test/jdk/java/io/charStreams/UTF8.java
41149 views
/*1* Copyright (c) 1997, 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/* @test24@bug 405968425@summary Simple heartbeat test of the UTF8 byte->char converter26*/2728import java.io.*;2930public class UTF8 {3132static String test33= "This is a simple\ntest of the UTF8\r\nbyte-to-char and char-to-byte\nconverters.";3435public static void main(String[] args) throws IOException {36ByteArrayOutputStream bo = new ByteArrayOutputStream();37Writer out = new OutputStreamWriter(bo, "UTF8");38out.write(test);39out.close();4041Reader in42= new InputStreamReader(new ByteArrayInputStream(bo.toByteArray()),43"UTF8");4445StringBuffer sb = new StringBuffer();46char buf[] = new char[1000];47int n;48while ((n = in.read(buf, 0, buf.length)) >= 0) {49sb.append(buf, 0, n);50System.err.println(n);51}52if (! sb.toString().equals(test)) {53System.err.println("In: [" + test + "]");54System.err.println("Out: [" + sb.toString() + "]");55throw new RuntimeException("Output does not match input");56}5758}5960}616263