Path: blob/master/test/jdk/java/io/charStreams/LineLengthsSource.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/**/2425import java.io.*;262728class LineLengthsSource implements Runnable {2930DataOutputStream uo;31BufferedWriter to;32PrintWriter log;3334public LineLengthsSource(OutputStream us, BufferedWriter ts,35PrintWriter log)36throws IOException37{38uo = new DataOutputStream(us);39to = ts;40this.log = log;41}4243private void flush() throws IOException {44uo.flush();45Thread.currentThread().yield();46to.flush();47Thread.currentThread().yield();48}4950private String termString(int t) {51switch (t) {52case 0: return "\n";53case 1: return "\r";54case 2: return "\r\n";55default: return "";56}57}5859private String termName(int t) {60switch (t) {61case 0: return "\\n";62case 1: return "\\r";63case 2: return "\\r\\n";64default: return "";65}66}6768private void go(int t) throws IOException {69for (int ln = 0; ln < 128; ln++) {70String ts = termString(t);71StringBuffer s = new StringBuffer(ln + ts.length());72for (int i = 0; i < ln; i++)73s.append('x');74log.println("[" + ln + "]" + termName(t));75uo.writeUTF(s.toString());76s.append(ts);77to.write(s.toString());78flush();79}80}8182public void run() {83try {84go(0);85go(1);86go(2);87uo.close();88Thread.currentThread().yield();89to.close();90Thread.currentThread().yield();91}92catch (IOException x) {93return; /* Probably pipe broken */94}95}9697}9899100