Class FastPipedOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- hudson.remoting.FastPipedOutputStream
-
- All Implemented Interfaces:
ErrorPropagatingOutputStream
,Closeable
,Flushable
,AutoCloseable
public class FastPipedOutputStream extends OutputStream implements ErrorPropagatingOutputStream
This class is equivalent tojava.io.PipedOutputStream
. In the interface it only adds a constructor which allows for specifying the buffer size. Its implementation, however, is much simpler and a lot more efficient than its equivalent. It doesn't rely on polling. Instead it uses proper synchronization with its counterpartFastPipedInputStream
.- Author:
- WD
- See Also:
- 4404700,
FastPipedOutputStream
-
-
Constructor Summary
Constructors Constructor Description FastPipedOutputStream()
Creates an unconnected PipedOutputStream.FastPipedOutputStream(FastPipedInputStream sink)
Creates a PipedOutputStream with a default buffer size and connects it tosink
.FastPipedOutputStream(FastPipedInputStream sink, int bufferSize)
Deprecated.as of 1.350 bufferSize parameter is ignored.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
connect(FastPipedInputStream sink)
void
error(Throwable e)
Closes the stream and causes the readingInputStream
to report an error.protected void
finalize()
void
flush()
void
write(byte[] b)
void
write(byte[] b, int off, int len)
void
write(int b)
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Constructor Detail
-
FastPipedOutputStream
public FastPipedOutputStream()
Creates an unconnected PipedOutputStream.
-
FastPipedOutputStream
public FastPipedOutputStream(FastPipedInputStream sink) throws IOException
Creates a PipedOutputStream with a default buffer size and connects it tosink
.- Throws:
IOException
- It was already connected.
-
FastPipedOutputStream
@Deprecated public FastPipedOutputStream(FastPipedInputStream sink, int bufferSize) throws IOException
Deprecated.as of 1.350 bufferSize parameter is ignored.Creates a PipedOutputStream with buffer sizebufferSize
and connects it tosink
.- Throws:
IOException
- It was already connected.
-
-
Method Detail
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
- The pipe is not connected.
-
error
public void error(Throwable e) throws IOException
Description copied from interface:ErrorPropagatingOutputStream
Closes the stream and causes the readingInputStream
to report an error.This method is somewhat like
OutputStream.close()
, in that it signals the end of a stream. In addition to what the close method does, this method will cause theInputStream.read()
method (or any other overloaded versions) to throw anIOException
with the given throwable as the cause.InputStream
will report an error only after all the data that has written before is read. IOW, the error will not magically jump over the data that was written.This is useful to propagate error over a pipe. If used over a channel with the remoting library that doesn't yet support this, or if the
OutputStream
isn't connecting to anInputStream
, this method behaves exactly likeOutputStream.close()
.If
OutputStream
is already closed or error state is set, this method will be no-op.- Specified by:
error
in interfaceErrorPropagatingOutputStream
- Parameters:
e
- if null, this method behaves exactly likeOutputStream.close()
- Throws:
IOException
-
connect
public void connect(FastPipedInputStream sink) throws IOException
- Throws:
IOException
- The pipe is already connected.
-
finalize
protected void finalize() throws Throwable
-
flush
public void flush() throws IOException
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
write
public void write(int b) throws IOException
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
write
public void write(@NonNull byte[] b) throws IOException
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
public void write(@NonNull byte[] b, int off, int len) throws IOException
- Overrides:
write
in classOutputStream
- Throws:
IOException
- The pipe is not connected or a reader has closed it.
-
-