Package org.pipecraft.pipes.sync.source
Class ReaderPipe
- java.lang.Object
-
- org.pipecraft.pipes.sync.source.ReaderPipe
-
- All Implemented Interfaces:
Closeable,AutoCloseable,BasePipe,Pipe<String>
public class ReaderPipe extends Object implements Pipe<String>
A source pipe that reads lines from a given reader. Note that since this class is based on a textual input stream only, it can't support progress tracking. Subclasses are encouraged to use the stream origin for supporting progress tracking.- Author:
- Eyal Schneider
-
-
Constructor Summary
Constructors Constructor Description ReaderPipe(Reader r)ConstructorReaderPipe(Reader r, int bufferSize)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()floatgetProgress()Stringnext()Stringpeek()voidstart()Performs pre-processing prior to item flow throw the pipe.
-
-
-
Constructor Detail
-
ReaderPipe
public ReaderPipe(Reader r)
Constructor- Parameters:
r- The reader to read from. Wrapped by a BufferedReader by this class.
-
ReaderPipe
public ReaderPipe(Reader r, int bufferSize)
Constructor- Parameters:
r- The reader to read from. Wrapped by a BufferedReader by this class.bufferSize- The buffer size of the wrapping BufferedReader, in bytes
-
-
Method Detail
-
start
public void start() throws PipeExceptionDescription 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.
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
next
public String next() throws PipeException
- Specified by:
nextin interfacePipe<String>- Returns:
- The next item in this pipe output, or null if the output end has been reached. May be a blocking operation.
- Throws:
PipeException- In case of pipe errors in this pipe or somewhere up-stream while trying to prepare next item to return.
-
peek
public String peek()
-
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.
-
-