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

public abstract Class AbstractCharInputReader

extends Object
implements CharInputReader
Class Inheritance
All Implemented Interfaces
com.univocity.parsers.common.input.CharInputReader, com.univocity.parsers.common.input.CharInput
Known Direct Subclasses
com.univocity.parsers.common.input.DefaultCharInputReader, com.univocity.parsers.common.input.concurrent.ConcurrentCharInputReader
Imports
com.univocity.parsers.common.*, java.io.*, java.util.*

The base class for implementing different flavours of CharInputReader.

It provides the essential conversion of sequences of newline characters defined by Format#getLineSeparator() into the normalized newline character provided in Format#getNormalizedNewline().

It also provides a default implementation for most of the methods specified by the CharInputReader interface.

Extending classes must essentially read characters from a given java.io.Reader and assign it to the public AbstractCharInputReader#buffer when requested (in the AbstractCharInputReader#reloadBuffer() method).

Author
Univocity Software Pty Ltd - [email protected]
See Also
com.univocity.parsers.common.Format, com.univocity.parsers.common.input.DefaultCharInputReader, com.univocity.parsers.common.input.concurrent.ConcurrentCharInputReader

Field Summary

Modifier and TypeField and Description
public char[]
buffer

The buffer itself

private char
private long
protected final boolean
private boolean
private final boolean
public int
i

Current position in the buffer

private boolean
private List<InputAnalysisProcess>
public int
length

Number of characters available in the buffer.

private long
private char
private char
private boolean
private final char
private boolean
private int
private boolean
private final ExpandingCharAppender
pack-priv final int

Constructor Summary

AccessConstructor and Description
public
AbstractCharInputReader(char
the normalized newline character (as defined in Format#getNormalizedNewline()) that is used to replace any lineSeparator sequence found in the input.
normalizedLineSeparator
,
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 that attempts to detect the newlines used in the input automatically.

public
AbstractCharInputReader(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
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
public final void
addInputAnalysisProcess(InputAnalysisProcess
a custom process to analyze the contents of the input buffer.
inputAnalysisProcess
)

Submits a custom InputAnalysisProcess to analyze the input buffer and potentially discover configuration options such as column separators is CSV, data formats, etc. The process will be execute only once.

public final long
charCount()

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

Returns the number of characters returned by CharInputReader#nextChar() at any given time.
public final String
currentParsedContent()

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

Returns a String with the input character sequence parsed to produce the current record.
public final int
currentParsedContentLength()

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

Returns the length of the character sequence parsed to produce the current record.
public final void
enableNormalizeLineEndings(boolean
flag indicating that the parser is escaping values and line separators are to be returned as-is.
normalizeLineEndings
)

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

Indicates to the input reader that the parser is running in "escape" mode and new lines should be returned as-is to prevent modifying the content of the parsed value.
public final char
getChar()

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

Returns the last character returned by the nextChar() method.
public char[]
getLineSeparator()

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

Returns the line separator by this character input reader.
public final String
getQuotedString(char
the quote character
quote
,
char
the quote escape character
escape
,
char
the escape of the quote escape character
escapeEscape
,
int
the maximum length of the String to be returned. If the length exceeds this limit, null will be returned
maxLength
,
char
the first stop character that identifies the end of the content to be collected
stop1
,
char
the second stop character that identifies the end of the content to be collected
stop2
,
boolean
flag to indicate the quotes that wrap the resulting String should be kept.
keepQuotes
,
boolean
flag to indicate that escape sequences should be kept
keepEscape
,
boolean
flag to indicate leading whitespaces should be trimmed
trimLeading
,
boolean
flag to indicate that trailing whitespaces should be trimmed
trimTrailing
)

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

Attempts to collect a quoted String from the current position until a closing quote or stop character is found on the input, or a line ending is reached.
public final String
getString(char
the current character to be considered. If equal to the stop character the nullValue will be returned
ch
,
char
the stop character that identifies the end of the content to be collected
stop
,
boolean
flag indicating whether or not trailing whitespaces should be discarded
trim
,
String
value to return when the length of the content to be returned is 0.
nullValue
,
int
the maximum length of the String to be returned. If the length exceeds this limit, null will be returned
maxLength
)

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

Attempts to collect a String from the current position until a stop character is found on the input, or a line ending is reached.
public final int
lastIndexOf(char
the character to look for
ch
)

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

Returns the last index of a given character in the current parsed content
public final long
lineCount()

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

Returns the number of newlines read so far.
public final void
markRecordStart()

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

Marks the start of a new record in the input, used internally to calculate the result of currentParsedContent()
public final char
nextChar()

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

Returns the next character in the input provided by the active java.io.Reader.
public String
readComment()

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

Collects the comment line found on the input.
protected abstract void
reloadBuffer()

Informs the extending class that the buffer has been read entirely and requests for another batch of characters.

private void
setLineSeparator(char[] lineSeparator)

protected abstract void
setReader(Reader reader)

Passes the java.io.Reader provided in the AbstractCharInputReader#start(Reader) method to the extending class so it can begin loading characters from it.

public final void
skipLines(long
the number of lines to skip from the current location in the input
lines
)

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

Skips characters in the input until the given number of lines is discarded.
public final boolean
skipQuotedString(char
the quote character
quote
,
char
the quote escape character
escape
,
char
the first stop character that identifies the end of the content to be collected
stop1
,
char
the second stop character that identifies the end of the content to be collected
stop2
)

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

Attempts to skip a quoted String from the current position until a stop character is found on the input, or a line ending is reached.
public final boolean
skipString(char
the current character to be considered. If equal to the stop character false will be returned
ch
,
char
the stop character that identifies the end of the content to be collected
stop
)

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

Attempts to skip a String from the current position until a stop character is found on the input, or a line ending is reached.
public final char
skipWhitespace(char
the current character of the input
ch
,
char
the first stop character (which can be a whitespace)
stopChar1
,
char
the second character (which can be a whitespace)
stopChar2
)

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

Skips characters from the current input position, until a non-whitespace character, or a stop character is found
private void
start(Reader reader, boolean resetTmp)

public final void
start(Reader
A java.io.Reader that provides access to the input.
reader
)

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

Initializes the CharInputReader implementation with a java.io.Reader which provides access to the input.
private void
private void
protected final void
private void
updateBuffer()

Requests the next batch of characters from the implementing class and updates the character count.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferback to summary
public char[] buffer

The buffer itself

chback to summary
private char ch
charCountback to summary
private long charCount
closeOnStopback to summary
protected final boolean closeOnStop
commentProcessingback to summary
private boolean commentProcessing
detectLineSeparatorback to summary
private final boolean detectLineSeparator
iback to summary
public int i

Current position in the buffer

incrementLineCountback to summary
private boolean incrementLineCount
inputAnalysisProcessesback to summary
private List<InputAnalysisProcess> inputAnalysisProcesses
lengthback to summary
public int length

Number of characters available in the buffer.

lineCountback to summary
private long lineCount
lineSeparator1back to summary
private char lineSeparator1
lineSeparator2back to summary
private char lineSeparator2
lineSeparatorDetectedback to summary
private boolean lineSeparatorDetected
normalizedLineSeparatorback to summary
private final char normalizedLineSeparator
normalizeLineEndingsback to summary
private boolean normalizeLineEndings
recordStartback to summary
private int recordStart
skippingback to summary
private boolean skipping
tmpback to summary
private final ExpandingCharAppender tmp
whitespaceRangeStartback to summary
pack-priv final int whitespaceRangeStart

Constructor Detail

AbstractCharInputReaderback to summary
public AbstractCharInputReader(char normalizedLineSeparator, int whitespaceRangeStart, boolean closeOnStop)

Creates a new instance that attempts to detect the newlines used in the input 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.

whitespaceRangeStart:int

starting range of characters considered to be whitespace.

closeOnStop:boolean

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

AbstractCharInputReaderback to summary
public AbstractCharInputReader(char[] lineSeparator, char normalizedLineSeparator, 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.

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

addInputAnalysisProcessback to summary
public final void addInputAnalysisProcess(InputAnalysisProcess inputAnalysisProcess)

Submits a custom InputAnalysisProcess to analyze the input buffer and potentially discover configuration options such as column separators is CSV, data formats, etc. The process will be execute only once.

Parameters
inputAnalysisProcess:InputAnalysisProcess

a custom process to analyze the contents of the input buffer.

charCountback to summary
public final long charCount()

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

Doc from com.univocity.parsers.common.input.CharInputReader.charCount.

Returns the number of characters returned by CharInputReader#nextChar() at any given time.

Returns:long

the number of characters returned by CharInputReader#nextChar()

Annotations
@Override
currentParsedContentback to summary
public final String currentParsedContent()

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

Doc from com.univocity.parsers.common.input.CharInputReader.currentParsedContent.

Returns a String with the input character sequence parsed to produce the current record.

Returns:String

the text content parsed for the current input record.

Annotations
@Override
currentParsedContentLengthback to summary
public final int currentParsedContentLength()

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

Doc from com.univocity.parsers.common.input.CharInputReader.currentParsedContentLength.

Returns the length of the character sequence parsed to produce the current record.

Returns:int

the length of the text content parsed for the current input record

Annotations
@Override
enableNormalizeLineEndingsback to summary
public final void enableNormalizeLineEndings(boolean normalizeLineEndings)

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

Doc from com.univocity.parsers.common.input.CharInputReader.enableNormalizeLineEndings.

Indicates to the input reader that the parser is running in "escape" mode and new lines should be returned as-is to prevent modifying the content of the parsed value.

Parameters
normalizeLineEndings:boolean

flag indicating that the parser is escaping values and line separators are to be returned as-is.

Annotations
@Override
getCharback to summary
public final char getChar()

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

Doc from com.univocity.parsers.common.input.CharInputReader.getChar.

Returns the last character returned by the nextChar() method.

Returns:char

the last character returned by the nextChar() method.'\0' if there are no more characters in the input or if the CharInputReader was stopped.

Annotations
@Override
getLineSeparatorback to summary
public char[] getLineSeparator()

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

Doc from com.univocity.parsers.common.input.CharInputReader.getLineSeparator.

Returns the line separator by this character input reader. This could be the line separator defined in the Format#getLineSeparator() configuration, or the line separator sequence identified automatically when CommonParserSettings#isLineSeparatorDetectionEnabled() evaluates to true.

Returns:char[]

the line separator in use.

Annotations
@Override
getQuotedStringback to summary
public final String getQuotedString(char quote, char escape, char escapeEscape, int maxLength, char stop1, char stop2, boolean keepQuotes, boolean keepEscape, boolean trimLeading, boolean trimTrailing)

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

Doc from com.univocity.parsers.common.input.CharInputReader.getQuotedString.

Attempts to collect a quoted String from the current position until a closing quote or stop character is found on the input, or a line ending is reached. If the String can be obtained, the current position of the parser will be updated to the last consumed character. If the internal buffer needs to be reloaded, this method will return null and the current position of the buffer will remain unchanged.

Parameters
quote:char

the quote character

escape:char

the quote escape character

escapeEscape:char

the escape of the quote escape character

maxLength:int

the maximum length of the String to be returned. If the length exceeds this limit, null will be returned

stop1:char

the first stop character that identifies the end of the content to be collected

stop2:char

the second stop character that identifies the end of the content to be collected

keepQuotes:boolean

flag to indicate the quotes that wrap the resulting String should be kept.

keepEscape:boolean

flag to indicate that escape sequences should be kept

trimLeading:boolean

flag to indicate leading whitespaces should be trimmed

trimTrailing:boolean

flag to indicate that trailing whitespaces should be trimmed

Returns:String

the String found on the input, or null if the buffer needs to reloaded or the maximum length has been exceeded.

Annotations
@Override
getStringback to summary
public final String getString(char ch, char stop, boolean trim, String nullValue, int maxLength)

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

Doc from com.univocity.parsers.common.input.CharInputReader.getString.

Attempts to collect a String from the current position until a stop character is found on the input, or a line ending is reached. If the String can be obtained, the current position of the parser will be updated to the last consumed character. If the internal buffer needs to be reloaded, this method will return null and the current position of the buffer will remain unchanged.

Parameters
ch:char

the current character to be considered. If equal to the stop character the nullValue will be returned

stop:char

the stop character that identifies the end of the content to be collected

trim:boolean

flag indicating whether or not trailing whitespaces should be discarded

nullValue:String

value to return when the length of the content to be returned is 0.

maxLength:int

the maximum length of the String to be returned. If the length exceeds this limit, null will be returned

Returns:String

the String found on the input, or null if the buffer needs to reloaded or the maximum length has been exceeded.

Annotations
@Override
lastIndexOfback to summary
public final int lastIndexOf(char ch)

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

Doc from com.univocity.parsers.common.input.CharInputReader.lastIndexOf.

Returns the last index of a given character in the current parsed content

Parameters
ch:char

the character to look for

Returns:int

the last position of the given character in the current parsed content, or -1 if not found.

Annotations
@Override
lineCountback to summary
public final long lineCount()

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

Doc from com.univocity.parsers.common.input.CharInputReader.lineCount.

Returns the number of newlines read so far.

Returns:long

the number of newlines read so far.

Annotations
@Override
markRecordStartback to summary
public final void markRecordStart()

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

Doc from com.univocity.parsers.common.input.CharInputReader.markRecordStart.

Marks the start of a new record in the input, used internally to calculate the result of currentParsedContent()

Annotations
@Override
nextCharback to summary
public final char nextChar()

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

Doc from com.univocity.parsers.common.input.CharInputReader.nextChar.

Returns the next character in the input provided by the active java.io.Reader.

If the input contains a sequence of newline characters (defined by Format#getLineSeparator()), this method will automatically converted them to the newline character specified in Format#getNormalizedNewline().

A subsequent call to this method will return the character after the newline sequence.

Returns:char

the next character in the input. '\0' if there are no more characters in the input or if the CharInputReader was stopped.

Annotations
@Override
readCommentback to summary
public String readComment()

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

Doc from com.univocity.parsers.common.input.CharInputReader.readComment.

Collects the comment line found on the input.

Returns:String

the text found in the comment from the current position.

Annotations
@Override
reloadBufferback to summary
protected abstract void reloadBuffer()

Informs the extending class that the buffer has been read entirely and requests for another batch of characters. Implementors must assign the new character buffer to the public AbstractCharInputReader#buffer attribute, as well as the number of characters available to the public AbstractCharInputReader#length attribute. To notify the input does not have any more characters, AbstractCharInputReader#length must receive the -1 value

setLineSeparatorback to summary
private void setLineSeparator(char[] lineSeparator)
setReaderback to summary
protected abstract void setReader(Reader reader)

Passes the java.io.Reader provided in the AbstractCharInputReader#start(Reader) method to the extending class so it can begin loading characters from it.

Parameters
reader:Reader

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

skipLinesback to summary
public final void skipLines(long lines)

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

Doc from com.univocity.parsers.common.input.CharInputReader.skipLines.

Skips characters in the input until the given number of lines is discarded.

Parameters
lines:long

the number of lines to skip from the current location in the input

Annotations
@Override
skipQuotedStringback to summary
public final boolean skipQuotedString(char quote, char escape, char stop1, char stop2)

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

Doc from com.univocity.parsers.common.input.CharInputReader.skipQuotedString.

Attempts to skip a quoted String from the current position until a stop character is found on the input, or a line ending is reached. If the String can be skipped, the current position of the parser will be updated to the last consumed character. If the internal buffer needs to be reloaded, this method will return false and the current position of the buffer will remain unchanged.

Parameters
quote:char

the quote character

escape:char

the quote escape character

stop1:char

the first stop character that identifies the end of the content to be collected

stop2:char

the second stop character that identifies the end of the content to be collected

Returns:boolean

true if an entire String value was found on the input and skipped, or false if the buffer needs to reloaded.

skipStringback to summary
public final boolean skipString(char ch, char stop)

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

Doc from com.univocity.parsers.common.input.CharInputReader.skipString.

Attempts to skip a String from the current position until a stop character is found on the input, or a line ending is reached. If the String can be skipped, the current position of the parser will be updated to the last consumed character. If the internal buffer needs to be reloaded, this method will return false and the current position of the buffer will remain unchanged.

Parameters
ch:char

the current character to be considered. If equal to the stop character false will be returned

stop:char

the stop character that identifies the end of the content to be collected

Returns:boolean

true if an entire String value was found on the input and skipped, or false if the buffer needs to reloaded.

Annotations
@Override
skipWhitespaceback to summary
public final char skipWhitespace(char ch, char stopChar1, char stopChar2)

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

Doc from com.univocity.parsers.common.input.CharInputReader.skipWhitespace.

Skips characters from the current input position, until a non-whitespace character, or a stop character is found

Parameters
ch:char

the current character of the input

stopChar1:char

the first stop character (which can be a whitespace)

stopChar2:char

the second character (which can be a whitespace)

Returns:char

the first non-whitespace character (or delimiter) found in the input.

Annotations
@Override
startback to summary
private void start(Reader reader, boolean resetTmp)
startback to summary
public final void start(Reader reader)

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

Doc from com.univocity.parsers.common.input.CharInputReader.start.

Initializes the CharInputReader implementation with a java.io.Reader which provides access to the input.

Parameters
reader:Reader

A java.io.Reader that provides access to the input.

Annotations
@Override
submitLineSeparatorDetectorback to summary
private void submitLineSeparatorDetector()
throwEOFExceptionback to summary
private void throwEOFException()
unwrapInputStreamback to summary
protected final void unwrapInputStream(BomInput.BytesProcessedNotification notification)
updateBufferback to summary
private void updateBuffer()

Requests the next batch of characters from the implementing class and updates the character count.

If there are no more characters in the input, the reading will stop by invoking the AbstractCharInputReader#stop() method.