Top Description Fields Constructors Methods
com.univocity.parsers.common.input.concurrent

public Class ConcurrentCharInputReader

extends AbstractCharInputReader
Class Inheritance
Imports
com.univocity.parsers.common.*, com.univocity.parsers.common.input.*, java.io.*

A concurrent CharInputReader that loads batches of characters in a separate thread and assigns them to buffer in AbstractCharInputReader when requested.

This class loads "buckets" of characters in the background and provides them sequentially to the ConcurrentCharInputReader#buffer attribute in AbstractCharInputReader.

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).

Author
Univocity Software Pty Ltd - [email protected]
See Also
CharInputReader, ConcurrentCharLoader, CharBucket

Field Summary

Modifier and TypeField and Description
private ConcurrentCharLoader
private final int
private final int
private boolean
Inherited from com.univocity.parsers.common.input.AbstractCharInputReader:
buffercloseOnStopilength

Constructor Summary

AccessConstructor and Description
public
ConcurrentCharInputReader(char
the normalized newline character (as defined in Format#getNormalizedNewline()) that is used to replace any lineSeparator sequence found in the input.
normalizedLineSeparator
,
int
the size of an each individual "bucket" used to store characters read from the input.
bucketSize
,
int
the number of "buckets" to load in memory. Note the reader will stop if all buckets are full.
bucketQuantity
,
int
starting range of characters considered to be whitespace.
whitespaceRangeStart
,
boolean
indicates whether to automatically close the input when stop() is called
closeOnStop
)

Creates a new instance with the mandatory characters for handling newlines transparently.

public
ConcurrentCharInputReader(char[]
the sequence of characters that represent a newline, as defined in Format#getLineSeparator()
lineSeparator
,
char
the normalized newline character (as defined in Format#getNormalizedNewline()) that is used to replace any lineSeparator sequence found in the input.
normalizedLineSeparator
,
int
the size of an each individual "bucket" used to store characters read from the input.
bucketSize
,
int
the number of "buckets" to load in memory. Note the reader will stop if all buckets are full.
bucketQuantity
,
int
starting range of characters considered to be whitespace.
whitespaceRangeStart
,
boolean
indicates whether to automatically close the input when stop() is called
closeOnStop
)

Creates a new instance with the mandatory characters for handling newlines transparently.

Method Summary

Modifier and TypeMethod and Description
protected void
reloadBuffer()

Implements abstract com.univocity.parsers.common.input.AbstractCharInputReader.reloadBuffer.

Assigns the next "bucket" of characters to the ConcurrentCharInputReader#buffer attribute, and updates the ConcurrentCharInputReader#length to the number of characters read.
protected void
setReader(Reader reader)

Implements abstract com.univocity.parsers.common.input.AbstractCharInputReader.setReader.

Starts an input reading thread to load characters from the given reader into "buckets" of characters
public void
stop()

Implements com.univocity.parsers.common.input.CharInputReader.stop.

Stops the CharInputReader from reading characters from the java.io.Reader provided in ConcurrentCharInputReader#start(Reader) and closes it.
Inherited from com.univocity.parsers.common.input.AbstractCharInputReader:
addInputAnalysisProcesscharCountcurrentParsedContentcurrentParsedContentLengthenableNormalizeLineEndingsgetChargetLineSeparatorgetQuotedStringgetStringlastIndexOflineCountmarkRecordStartnextCharreadCommentskipLinesskipQuotedStringskipStringskipWhitespacestartunwrapInputStream

Field Detail

bucketLoaderback to summary
private ConcurrentCharLoader bucketLoader
bucketQuantityback to summary
private final int bucketQuantity
bucketSizeback to summary
private final int bucketSize
unwrappingback to summary
private boolean unwrapping

Constructor Detail

ConcurrentCharInputReaderback to summary
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:char

the normalized newline character (as defined in Format#getNormalizedNewline()) that is used to replace any lineSeparator sequence found in the input.

bucketSize:int

the size of an each individual "bucket" used to store characters read from the input.

bucketQuantity:int

the number of "buckets" to load in memory. Note the reader will stop if all buckets are full.

whitespaceRangeStart:int

starting range of characters considered to be whitespace.

closeOnStop:boolean

indicates whether to automatically close the input when stop() is called

ConcurrentCharInputReaderback to summary
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:char[]

the sequence of characters that represent a newline, as defined in Format#getLineSeparator()

normalizedLineSeparator:char

the normalized newline character (as defined in Format#getNormalizedNewline()) that is used to replace any lineSeparator sequence found in the input.

bucketSize:int

the size of an each individual "bucket" used to store characters read from the input.

bucketQuantity:int

the number of "buckets" to load in memory. Note the reader will stop if all buckets are full.

whitespaceRangeStart:int

starting range of characters considered to be whitespace.

closeOnStop:boolean

indicates whether to automatically close the input when stop() is called

Method Detail

reloadBufferback to summary
protected void reloadBuffer()

Implements abstract com.univocity.parsers.common.input.AbstractCharInputReader.reloadBuffer.

Assigns the next "bucket" of characters to the ConcurrentCharInputReader#buffer attribute, and updates the ConcurrentCharInputReader#length to the number of characters read.

Annotations
@Override
setReaderback to summary
protected void setReader(Reader reader)

Implements abstract com.univocity.parsers.common.input.AbstractCharInputReader.setReader.

Starts an input reading thread to load characters from the given reader into "buckets" of characters

Parameters
reader:Reader

Doc from com.univocity.parsers.common.input.AbstractCharInputReader.setReader.

the java.io.Reader provided in AbstractCharInputReader#start(Reader)

Annotations
@Override
stopback to summary
public void stop()

Implements com.univocity.parsers.common.input.CharInputReader.stop.

Stops the CharInputReader from reading characters from the java.io.Reader provided in ConcurrentCharInputReader#start(Reader) and closes it. Also stops the input reading thread.

Annotations
@Override