aboutsummaryrefslogtreecommitdiff
path: root/nailgun_launcher/ThreadLocalOutputStream.java
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2016-10-13 01:29:48 +0000
committerChristopher Vogt <oss.nsp@cvogt.org>2016-10-13 23:21:04 -0400
commitcf94008b6fded5f58cea764d48beb0dcbbd4bb97 (patch)
tree5a26f2e2c50e7d5776a56c86dba62a5f129ed45f /nailgun_launcher/ThreadLocalOutputStream.java
parente7dab60a0a38f40b75b919a91b73052b510f1711 (diff)
downloadcbt-cf94008b6fded5f58cea764d48beb0dcbbd4bb97.tar.gz
cbt-cf94008b6fded5f58cea764d48beb0dcbbd4bb97.tar.bz2
cbt-cf94008b6fded5f58cea764d48beb0dcbbd4bb97.zip
swap out System.out and System.err in a way that affects JDK and Scala
Before it only affected jdk, because scala.Console captures our and err before the swap. This is needed when running main classes like Scaladoc or the compiler and wanting to redirect output to standard error
Diffstat (limited to 'nailgun_launcher/ThreadLocalOutputStream.java')
-rw-r--r--nailgun_launcher/ThreadLocalOutputStream.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/nailgun_launcher/ThreadLocalOutputStream.java b/nailgun_launcher/ThreadLocalOutputStream.java
new file mode 100644
index 0000000..c12b775
--- /dev/null
+++ b/nailgun_launcher/ThreadLocalOutputStream.java
@@ -0,0 +1,30 @@
+package cbt;
+import java.io.*;
+
+public class ThreadLocalOutputStream extends OutputStream{
+ final public ThreadLocal<OutputStream> threadLocal;
+ final private OutputStream initialValue;
+
+ public ThreadLocalOutputStream( OutputStream initialValue ){
+ this.initialValue = initialValue;
+ threadLocal = new ThreadLocal<OutputStream>() {
+ @Override protected OutputStream initialValue() {
+ return ThreadLocalOutputStream.this.initialValue;
+ }
+ };
+ }
+
+ public OutputStream get(){
+ return threadLocal.get();
+ }
+
+ public void set( OutputStream outputStream ){
+ threadLocal.set( outputStream );
+ }
+
+ public void write( int b ) throws IOException{
+ // after implementing this I realized NailgunLauncher uses the same hack,
+ // so probably this is not a problem performance
+ get().write(b);
+ }
+}