Class ConcurrentCharInputReader
- java.lang.Object
-
- com.univocity.parsers.common.input.AbstractCharInputReader
-
- com.univocity.parsers.common.input.concurrent.ConcurrentCharInputReader
-
- All Implemented Interfaces:
CharInput
,CharInputReader
public class ConcurrentCharInputReader extends AbstractCharInputReader
A concurrent CharInputReader that loads batches of characters in a separate thread and assigns them to buffer inAbstractCharInputReader
when requested.This class loads "buckets" of characters in the background and provides them sequentially to the
AbstractCharInputReader.buffer
attribute inAbstractCharInputReader
.The bucket loading process will block and wait while all buckets are full.
Similarly, the reader will block while all buckets are empty. This CharInputReader implementation provides a better throughput than
DefaultCharInputReader
when reading large inputs (> 100 mb
).- See Also:
CharInputReader
,ConcurrentCharLoader
,CharBucket
-
-
Field Summary
Fields Modifier and Type Field Description private ConcurrentCharLoader
bucketLoader
private int
bucketQuantity
private int
bucketSize
private boolean
unwrapping
-
Fields inherited from class com.univocity.parsers.common.input.AbstractCharInputReader
buffer, closeOnStop, i, length
-
-
Constructor Summary
Constructors Constructor Description ConcurrentCharInputReader(char[] lineSeparator, char normalizedLineSeparator, int bucketSize, int bucketQuantity, int whitespaceRangeStart, boolean closeOnStop)
Creates a new instance with the mandatory characters for handling newlines transparently.ConcurrentCharInputReader(char normalizedLineSeparator, int bucketSize, int bucketQuantity, int whitespaceRangeStart, boolean closeOnStop)
Creates a new instance with the mandatory characters for handling newlines transparently.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
reloadBuffer()
Assigns the next "bucket" of characters to theAbstractCharInputReader.buffer
attribute, and updates theAbstractCharInputReader.length
to the number of characters read.protected void
setReader(java.io.Reader reader)
Starts an input reading thread to load characters from the given reader into "buckets" of charactersvoid
stop()
Stops the CharInputReader from reading characters from theReader
provided inAbstractCharInputReader.start(Reader)
and closes it.-
Methods inherited from class com.univocity.parsers.common.input.AbstractCharInputReader
addInputAnalysisProcess, charCount, currentParsedContent, currentParsedContentLength, enableNormalizeLineEndings, getChar, getLineSeparator, getQuotedString, getString, lastIndexOf, lineCount, markRecordStart, nextChar, readComment, skipLines, skipQuotedString, skipString, skipWhitespace, start, unwrapInputStream
-
-
-
-
Field Detail
-
bucketLoader
private ConcurrentCharLoader bucketLoader
-
bucketSize
private final int bucketSize
-
bucketQuantity
private final int bucketQuantity
-
unwrapping
private boolean unwrapping
-
-
Constructor Detail
-
ConcurrentCharInputReader
public ConcurrentCharInputReader(char normalizedLineSeparator, int bucketSize, int bucketQuantity, int whitespaceRangeStart, boolean closeOnStop)
Creates a new instance with the mandatory characters for handling newlines transparently. Line separators will be detected automatically.- Parameters:
normalizedLineSeparator
- the normalized newline character (as defined inFormat.getNormalizedNewline()
) that is used to replace any lineSeparator sequence found in the input.bucketSize
- the size of an each individual "bucket" used to store characters read from the input.bucketQuantity
- the number of "buckets" to load in memory. Note the reader will stop if all buckets are full.whitespaceRangeStart
- starting range of characters considered to be whitespace.closeOnStop
- indicates whether to automatically close the input whenstop()
is called
-
ConcurrentCharInputReader
public ConcurrentCharInputReader(char[] lineSeparator, char normalizedLineSeparator, int bucketSize, int bucketQuantity, int whitespaceRangeStart, boolean closeOnStop)
Creates a new instance with the mandatory characters for handling newlines transparently.- Parameters:
lineSeparator
- the sequence of characters that represent a newline, as defined inFormat.getLineSeparator()
normalizedLineSeparator
- the normalized newline character (as defined inFormat.getNormalizedNewline()
) that is used to replace any lineSeparator sequence found in the input.bucketSize
- the size of an each individual "bucket" used to store characters read from the input.bucketQuantity
- the number of "buckets" to load in memory. Note the reader will stop if all buckets are full.whitespaceRangeStart
- starting range of characters considered to be whitespace.closeOnStop
- indicates whether to automatically close the input whenstop()
is called
-
-
Method Detail
-
stop
public void stop()
Stops the CharInputReader from reading characters from theReader
provided inAbstractCharInputReader.start(Reader)
and closes it. Also stops the input reading thread.
-
setReader
protected void setReader(java.io.Reader reader)
Starts an input reading thread to load characters from the given reader into "buckets" of characters- Specified by:
setReader
in classAbstractCharInputReader
- Parameters:
reader
- theReader
provided inAbstractCharInputReader.start(Reader)
-
reloadBuffer
protected void reloadBuffer()
Assigns the next "bucket" of characters to theAbstractCharInputReader.buffer
attribute, and updates theAbstractCharInputReader.length
to the number of characters read.- Specified by:
reloadBuffer
in classAbstractCharInputReader
-
-