author | alanb |
Fri, 07 Apr 2017 08:05:54 +0000 | |
changeset 44545 | 83b611b88ac8 |
parent 34428 | 39f1caf048c3 |
permissions | -rw-r--r-- |
34428
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
1 |
/* |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
4 |
* |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
8 |
* |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
13 |
* accompanied this code). |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
14 |
* |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
18 |
* |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
21 |
* questions. |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
22 |
*/ |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
23 |
|
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
24 |
import java.io.ByteArrayOutputStream; |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
25 |
import java.io.OutputStream; |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
26 |
import java.io.PrintStream; |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
27 |
|
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
28 |
import jdk.internal.logger.BootstrapLogger; |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
29 |
|
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
30 |
/** |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
31 |
* We use an instance of this class to check what the logging system has printed |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
32 |
* on System.err. |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
33 |
*/ |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
34 |
class LogStream extends OutputStream { |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
35 |
|
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
36 |
static final PrintStream err = System.err; |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
37 |
|
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
38 |
private final ByteArrayOutputStream BAOS = new ByteArrayOutputStream(); |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
39 |
|
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
40 |
LogStream() { |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
41 |
super(); |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
42 |
} |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
43 |
|
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
44 |
@Override |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
45 |
public synchronized void write(int b) { |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
46 |
BAOS.write(b); |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
47 |
err.write(b); |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
48 |
} |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
49 |
|
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
50 |
String drain() { |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
51 |
BootstrapLoggerUtils.awaitPending(); |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
52 |
synchronized (this) { |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
53 |
String txt = BAOS.toString(); |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
54 |
BAOS.reset(); |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
55 |
return txt; |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
56 |
} |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
57 |
} |
39f1caf048c3
8144460: Improve the code coverage for BootstrapLogger and SimpleConsoleLogger APIs and verify bug fix JDK-8144214
mli
parents:
diff
changeset
|
58 |
} |