Package com.stardog.stark.io
Class LineSupplier
java.lang.Object
com.stardog.stark.io.LineSupplier
A utility class that reads lines from a stream in one thread and supplies the output as
batches for
multiple threads to consume. The line numbers associated with the batches will start at 1. The definition of a line
follows the BufferedReader.readLine() definition. The lines in the resulting batches will not have any
line-termination characters in them.-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionLineSupplier(LineSupplier.InputStreamSupplier theInput, FileFormat.Compression theCompression, int queueSize) LineSupplier(InputStream theInput, FileFormat.Compression theCompression, int queueSize) LineSupplier(Path theFile, FileFormat.Compression theCompression, int queueSize) -
Method Summary
Modifier and TypeMethodDescriptionlongThe number of bytes that have been read so far.get()Retrieve the next batch available.voidsetBatchSize(int theBatchSize) Sets the number of lines that should be in every batch.voidstart()Starts the reading process.voidstop()Stops reading the lines as soon as possible.
-
Constructor Details
-
LineSupplier
-
LineSupplier
-
LineSupplier
public LineSupplier(LineSupplier.InputStreamSupplier theInput, FileFormat.Compression theCompression, int queueSize)
-
-
Method Details
-
setBatchSize
public void setBatchSize(int theBatchSize) Sets the number of lines that should be in every batch. Should be set before readingstarts. -
start
Starts the reading process. This function will return immediately and reading the input stream will be done in a thread in theshared executoruntil the stream is consumed or this supplier isstopped. If this function is called multiple times subsequent calls will have no effect.- Throws:
IOException
-
stop
public void stop()Stops reading the lines as soon as possible. Calling this function will ensure that no more batches will be produced but stopping the thread that reads the lines might not happen instantaneously. -
bytesRead
public long bytesRead()The number of bytes that have been read so far. -
get
Retrieve the next batch available. This function will block until the next batch is available. The batches will be returned in the order they are read from the stream so if they are consumed sequentially this will be equivalent to reading the stream sequentially. If the input stream has been consumed completelyan empty batchwill be returned for all subsequent calls.
-