1 /*
2  * Copyright (c) 1997, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /**/
25 
26 import java.io.*;
27 
28 
29 class LineLengthsSource implements Runnable {
30 
31     DataOutputStream uo;
32     BufferedWriter to;
33     PrintWriter log;
34 
LineLengthsSource(OutputStream us, BufferedWriter ts, PrintWriter log)35     public LineLengthsSource(OutputStream us, BufferedWriter ts,
36                              PrintWriter log)
37         throws IOException
38     {
39         uo = new DataOutputStream(us);
40         to = ts;
41         this.log = log;
42     }
43 
flush()44     private void flush() throws IOException {
45         uo.flush();
46         Thread.currentThread().yield();
47         to.flush();
48         Thread.currentThread().yield();
49     }
50 
termString(int t)51     private String termString(int t) {
52         switch (t) {
53         case 0: return "\n";
54         case 1: return "\r";
55         case 2: return "\r\n";
56         default: return "";
57         }
58     }
59 
termName(int t)60     private String termName(int t) {
61         switch (t) {
62         case 0: return "\\n";
63         case 1: return "\\r";
64         case 2: return "\\r\\n";
65         default: return "";
66         }
67     }
68 
go(int t)69     private void go(int t) throws IOException {
70         for (int ln = 0; ln < 128; ln++) {
71             String ts = termString(t);
72             StringBuffer s = new StringBuffer(ln + ts.length());
73             for (int i = 0; i < ln; i++)
74                 s.append('x');
75             log.println("[" + ln + "]" + termName(t));
76             uo.writeUTF(s.toString());
77             s.append(ts);
78             to.write(s.toString());
79             flush();
80         }
81     }
82 
run()83     public void run() {
84         try {
85             go(0);
86             go(1);
87             go(2);
88             uo.close();
89             Thread.currentThread().yield();
90             to.close();
91             Thread.currentThread().yield();
92         }
93         catch (IOException x) {
94             return;             /* Probably pipe broken */
95         }
96     }
97 
98 }
99