1 // Copied from ICU4J 57.1
2 /**
3  *******************************************************************************
4  * Copyright (C) 2005-2008, International Business Machines Corporation and    *
5  * others. All Rights Reserved.                                                *
6  *******************************************************************************
7  */
8 package com.ibm.icu.dev.test;
9 
10 import java.io.IOException;
11 import java.io.Writer;
12 
13 public final class TestLogWriter extends Writer {
14     private TestLog log;
15     private int level;
16     private boolean closed;
17 
TestLogWriter(TestLog log, int level)18     public TestLogWriter(TestLog log, int level) {
19     this.log = log;
20     this.level = level;
21     }
22 
23     @Override
write(char cbuf[], int off, int len)24     public void write(char cbuf[], int off, int len) throws IOException {
25         write(new String(cbuf, off, len));
26     }
27 
28     @Override
write(String str)29     public void write(String str) throws IOException {
30         if (closed) {
31             throw new IOException("stream closed");
32         }
33         if ("\r\n".indexOf(str) != -1) {
34             log.msg("", level, level == TestLog.ERR, true);
35         } else {
36             log.msg(str, level, level == TestLog.ERR, false);
37         }
38     }
39 
40     @Override
flush()41     public void flush() throws IOException {
42     }
43 
44     @Override
close()45     public void close() throws IOException {
46         closed = true;
47     }
48 }
49