Package org.apache.karaf.util.process
Class StreamPumper
- java.lang.Object
-
- org.apache.karaf.util.process.StreamPumper
-
-
Constructor Summary
Constructors Constructor Description StreamPumper(InputStream in, OutputStream out)Create a new stream pumper.StreamPumper(InputStream in, OutputStream out, boolean closeWhenExhausted)Create a new stream pumper.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetBufferSize()Get the size in bytes of the read buffer.ThrowablegetException()Get the exception encountered, if any.InputStreamgetIn()InputStreamgetInputStream()OutputStreamgetOut()booleanisFinished()Tell whether the end of the stream has been reached.voidrun()Copy data from the input stream to the output stream.voidsetAutoflush(boolean autoflush)Set whether data should be flushed through to the output stream.voidsetBufferSize(int bufferSize)Set the size in bytes of the read buffer.voidsetNonBlocking(boolean nonBlocking)Set whether data should be read in a non blocking way.voidstop()Stop the pumper as soon as possible.voidwaitFor()This method blocks until the stream pumper finishes.
-
-
-
Constructor Detail
-
StreamPumper
public StreamPumper(InputStream in, OutputStream out, boolean closeWhenExhausted)
Create a new stream pumper.- Parameters:
in- The input stream to read data from.out- The output stream to write data to.closeWhenExhausted- If true, the output stream will be closed when the input is exhausted.
-
StreamPumper
public StreamPumper(InputStream in, OutputStream out)
Create a new stream pumper.- Parameters:
in- The input stream to read data from.out- The output stream to write data to.
-
-
Method Detail
-
getIn
public InputStream getIn()
-
getOut
public OutputStream getOut()
-
setAutoflush
public void setAutoflush(boolean autoflush)
Set whether data should be flushed through to the output stream.- Parameters:
autoflush- If true, push through data; if false, let it be buffered.
-
setNonBlocking
public void setNonBlocking(boolean nonBlocking)
Set whether data should be read in a non blocking way.- Parameters:
nonBlocking- If true, data will be read in a non blocking mode.
-
run
public void run()
Copy data from the input stream to the output stream. Terminate as soon as the input stream is closed or an error occurs.
-
isFinished
public boolean isFinished()
Tell whether the end of the stream has been reached.- Returns:
- true if the stream has been exhausted.
-
waitFor
public void waitFor() throws InterruptedExceptionThis method blocks until the stream pumper finishes.- Throws:
InterruptedException- if the stream pumper has been interrupted.- See Also:
isFinished()
-
setBufferSize
public void setBufferSize(int bufferSize)
Set the size in bytes of the read buffer.- Parameters:
bufferSize- the buffer size to use.
-
getBufferSize
public int getBufferSize()
Get the size in bytes of the read buffer.- Returns:
- The size of the read buffer.
-
getException
public Throwable getException()
Get the exception encountered, if any.- Returns:
- The Exception encountered; or null if there was none.
-
stop
public void stop()
Stop the pumper as soon as possible. Note that it may continue to block on the input stream but it will really stop the thread as soon as it gets EOF or any byte, and it will be marked as finished.
-
getInputStream
public InputStream getInputStream()
-
-