Package org.pipecraft.pipes.sync.source
Class InputStreamPipe<T>
- java.lang.Object
-
- org.pipecraft.pipes.sync.source.InputStreamPipe<T>
-
- Type Parameters:
T- The Pipe's item data type
- All Implemented Interfaces:
Closeable,AutoCloseable,BasePipe,Pipe<T>
- Direct Known Subclasses:
BinInputReaderPipe,StorageTxtFileReaderPipe,TxtFileReaderPipe,URLTxtReaderPipe
public abstract class InputStreamPipe<T> extends Object implements Pipe<T>
A base class for source pipes based on some input stream. Handles progress tracking. Subclasses should override start() method, call super.start() and then perform specific pre-processing on the input stream.- Author:
- Eyal Schneider
-
-
Constructor Summary
Constructors Constructor Description InputStreamPipe(int bufferSizeBytes, Compression compression)Constructor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()protected abstract SizedInputStreamcreateInputStream()protected InputStreamgetInputStream()protected LonggetInputStreamSize()floatgetProgress()voidstart()Performs pre-processing prior to item flow throw the pipe.
-
-
-
Constructor Detail
-
InputStreamPipe
public InputStreamPipe(int bufferSizeBytes, Compression compression)Constructor- Parameters:
bufferSizeBytes- The requires buffer size, if <= 0 we don't use a buffercompression- Compression type
-
-
Method Detail
-
start
public void start() throws PipeException, InterruptedExceptionDescription copied from interface:BasePipePerforms pre-processing prior to item flow throw the pipe. Implementations must call the same method for all their input pipes before accessing their items. This is typically done here.- Specified by:
startin interfaceBasePipe- Throws:
PipeException- In case of pipe errors in this pipe or somewhere up-stream.InterruptedException- In case that the operation has been interrupted by another thread.
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
createInputStream
protected abstract SizedInputStream createInputStream() throws IOException, IOPipeException, InterruptedException
- Returns:
- A new input stream based on ctor arguments. Called once in the start() method.
Expected to be the raw input stream (without decompression or buffering layers),
but should be initialized with expected size (see
SizedInputStream). The size should be null if unknown. - Throws:
IOException- (Will be wrapped by IOPipeException)IOPipeException- (Are propagated without wrapping)InterruptedException- In case that the operation is interrupted
-
getInputStream
protected InputStream getInputStream()
- Returns:
- The input stream initialized according to the ctor parameters. Subclasses may use this stream in their start method after calling super.start().
-
getInputStreamSize
protected Long getInputStreamSize()
- Returns:
- The expected input stream size, when created. Subclasses may use this stream in their start method after calling super.start().
-
getProgress
public float getProgress()
- Specified by:
getProgressin interfaceBasePipe- Returns:
- The pipe flow progress, as a floating number between 0.0 and 1.0. Important implementation rules: 1) Calling this method before start() call is complete isn't allowed and has an undefined behavior. 2) Implementation should do best effort to provide an estimate of the progress this pipe has made (0.0 - 1.0) 3) When the pipe is fully consumed, getProgress() should return 1.0. 4) Results must be monotonous, i.e. results of consecutive calls may never be decreasing. 5) Thread safety: progress may be maintained by some thread/s but monitoring by other threads. Implementations must be thread safe.
-
-