Package org.pipecraft.pipes.sync.source
Class TxtFileReaderPipe
- java.lang.Object
-
- org.pipecraft.pipes.sync.source.InputStreamPipe<String>
-
- org.pipecraft.pipes.sync.source.TxtFileReaderPipe
-
- All Implemented Interfaces:
Closeable,AutoCloseable,BasePipe,Pipe<String>
public class TxtFileReaderPipe extends InputStreamPipe<String>
A source pipe reading lines from a given local text file or input stream containing text content. Each line produces a single pipe item. Supports decompression.- Author:
- Eyal Schneider
- See Also:
TxtFileWriterPipe
-
-
Constructor Summary
Constructors Constructor Description TxtFileReaderPipe(File f)Constructor Detects the compression type by the filename extensionTxtFileReaderPipe(File f, Charset charset)Constructor Detects the compression type by the filename extensionTxtFileReaderPipe(File f, Charset charset, FileReadOptions options)ConstructorTxtFileReaderPipe(File f, FileReadOptions options)ConstructorTxtFileReaderPipe(FailableInterruptibleSupplier<SizedInputStream,IOException> isCreator, Charset charset, int bufferSizeBytes, Compression compression)ConstructorTxtFileReaderPipe(SizedInputStream is, Charset charset, int bufferSizeBytes, Compression compression)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()protected SizedInputStreamcreateInputStream()Stringnext()Stringpeek()voidstart()Performs pre-processing prior to item flow throw the pipe.-
Methods inherited from class org.pipecraft.pipes.sync.source.InputStreamPipe
getInputStream, getInputStreamSize, getProgress
-
-
-
-
Constructor Detail
-
TxtFileReaderPipe
public TxtFileReaderPipe(FailableInterruptibleSupplier<SizedInputStream,IOException> isCreator, Charset charset, int bufferSizeBytes, Compression compression)
Constructor- Parameters:
isCreator- The creator of the stream to read from. Expected to be the raw input stream (without decompression or buffering layers), but should be initialized with expected size (seeSizedInputStream). The size should be either null if unknown, or it should be the exact number of stream bytes.charset- The charset to usebufferSizeBytes- The requires buffer sizecompression- Compression type
-
TxtFileReaderPipe
public TxtFileReaderPipe(SizedInputStream is, Charset charset, int bufferSizeBytes, Compression compression)
Constructor- Parameters:
is- The input stream to read from. Expected to be the raw input stream (without decompression or buffering layers).charset- The charset to usebufferSizeBytes- The requires buffer sizecompression- Compression type
-
TxtFileReaderPipe
public TxtFileReaderPipe(File f, Charset charset, FileReadOptions options)
Constructor- Parameters:
f- The text file to read fromcharset- The charset to useoptions- The file reading options
-
TxtFileReaderPipe
public TxtFileReaderPipe(File f, Charset charset)
Constructor Detects the compression type by the filename extension- Parameters:
f- The text file to read from. Compression is inferred from file extension.charset- The charset to use
-
TxtFileReaderPipe
public TxtFileReaderPipe(File f)
Constructor Detects the compression type by the filename extension- Parameters:
f- The text file to read from. Assumed to be UTF8. Compression is inferred from file extension
-
TxtFileReaderPipe
public TxtFileReaderPipe(File f, FileReadOptions options)
Constructor- Parameters:
f- The text file to read from. Assumed to be UTF8.options- The file reading options
-
-
Method Detail
-
next
public String next() throws PipeException, InterruptedException
- 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.InterruptedException- In case that the operation has been interrupted by another thread.
-
peek
public String peek()
- Returns:
- The next item in the pipe's output. Does not remove it, so next call to next() will return it.
-
createInputStream
protected SizedInputStream createInputStream() throws IOException, InterruptedException
- Specified by:
createInputStreamin classInputStreamPipe<String>- 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)InterruptedException- In case that the operation is interrupted
-
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- Overrides:
startin classInputStreamPipe<String>- 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- Overrides:
closein classInputStreamPipe<String>- Throws:
IOException
-
-