hudson.remoting
Class StandardOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by hudson.remoting.StandardOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class StandardOutputStream
extends java.io.OutputStream

Hint that indicates that we are using stdout with fd=1 as the stream to write to for the channel.

Using stdin/stdout pair for the communication is very convenient for setting up a remote channel, so Jenkins tends to do that, but even with our using System.setOut(PrintStream) to avoid other parts of the Java code to accidentally corrupt the stream, file descriptor 1 continues to point to the stream we use, so native code in JVM can still accidentally pollute the stream.

Fixing that requires the use of dup and close POSIX API calls, which we can only do after the communication gets established and JNA is brought in via remoting. Having Launcher uses this wrapper class allows us to do that without recreating the stream.

Author:
Kohsuke Kawaguchi

Constructor Summary
StandardOutputStream()
           
 
Method Summary
 void close()
           
 void flush()
           
 boolean isSwapped()
           
 java.io.OutputStream swap(java.io.OutputStream another)
          Atomically swaps the underlying stream to another stream and returns it.
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StandardOutputStream

public StandardOutputStream()
Method Detail

swap

public java.io.OutputStream swap(java.io.OutputStream another)
Atomically swaps the underlying stream to another stream and returns it.


isSwapped

public boolean isSwapped()

write

public void write(int b)
           throws java.io.IOException
Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException


Copyright © 2012. All Rights Reserved.