aboutsummaryrefslogtreecommitdiff
path: root/nailgun_launcher/ThreadLocalOutputStream.java
blob: c12b775d56bb811f5127652cd6bbfc4b7926e315 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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);
  }
}