| 1 |
/* |
| 2 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 |
* contributor license agreements. See the NOTICE file distributed with |
| 4 |
* this work for additional information regarding copyright ownership. |
| 5 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 |
* (the "License"); you may not use this file except in compliance with |
| 7 |
* the License. You may obtain a copy of the License at |
| 8 |
* |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing permissions and |
| 15 |
* limitations under the License. |
| 16 |
*/ |
| 17 |
package org.apache.lucene.gradle; |
| 18 |
|
| 19 |
import java.io.IOException; |
| 20 |
import java.io.PrintStream; |
| 21 |
import java.io.Writer; |
| 22 |
|
| 23 |
class StdOutTeeWriter extends Writer { |
| 24 |
private final Writer delegate; |
| 25 |
private final PrintStream out = System.out; |
| 26 |
|
| 27 |
public StdOutTeeWriter(Writer delegate) { |
| 28 |
this.delegate = delegate; |
| 29 |
} |
| 30 |
|
| 31 |
@Override |
| 32 |
public void write(int c) throws IOException { |
| 33 |
delegate.write(c); |
| 34 |
out.write(c); |
| 35 |
} |
| 36 |
|
| 37 |
@Override |
| 38 |
public void write(char[] cbuf) throws IOException { |
| 39 |
delegate.write(cbuf); |
| 40 |
out.print(cbuf); |
| 41 |
} |
| 42 |
|
| 43 |
@Override |
| 44 |
public void write(String str) throws IOException { |
| 45 |
delegate.write(str); |
| 46 |
out.print(str); |
| 47 |
} |
| 48 |
|
| 49 |
@Override |
| 50 |
public void write(String str, int off, int len) throws IOException { |
| 51 |
delegate.write(str, off, len); |
| 52 |
out.append(str, off, len); |
| 53 |
} |
| 54 |
|
| 55 |
@Override |
| 56 |
public Writer append(CharSequence csq) throws IOException { |
| 57 |
delegate.append(csq); |
| 58 |
out.append(csq); |
| 59 |
return this; |
| 60 |
} |
| 61 |
|
| 62 |
@Override |
| 63 |
public Writer append(CharSequence csq, int start, int end) throws IOException { |
| 64 |
delegate.append(csq, start, end); |
| 65 |
out.append(csq, start, end); |
| 66 |
return this; |
| 67 |
} |
| 68 |
|
| 69 |
@Override |
| 70 |
public Writer append(char c) throws IOException { |
| 71 |
delegate.append(c); |
| 72 |
out.append(c); |
| 73 |
return this; |
| 74 |
} |
| 75 |
|
| 76 |
@Override |
| 77 |
public void write(char[] cbuf, int off, int len) throws IOException { |
| 78 |
delegate.write(cbuf, off, len); |
| 79 |
out.print(new String(cbuf, off, len)); |
| 80 |
} |
| 81 |
|
| 82 |
@Override |
| 83 |
public void flush() throws IOException { |
| 84 |
delegate.flush(); |
| 85 |
out.flush(); |
| 86 |
} |
| 87 |
|
| 88 |
@Override |
| 89 |
public void close() throws IOException { |
| 90 |
delegate.close(); |
| 91 |
// Don't close the actual output. |
| 92 |
} |
| 93 |
} |