Package com.univocity.parsers.common
Class Format
- java.lang.Object
-
- com.univocity.parsers.common.Format
-
- All Implemented Interfaces:
java.lang.Cloneable
- Direct Known Subclasses:
CsvFormat,FixedWidthFormat,TsvFormat
public abstract class Format extends java.lang.Object implements java.lang.CloneableThis is the parent class for all configuration classes that define a text format.By default, all parsers and writers have to handle, at least, the following format definitions:
- lineSeparator: the 1-2 character sequence that indicates the end of a line. Newline sequences are different across operating systems. Typically:
- Windows uses carriage return and line feed: \r\n
- Linux/Unix uses line feed only: \n
- MacOS uses carriage return only: \r
lineSeparatordefaults to the system line separator - normalizedNewline: a single character used to represent the end of a line uniformly in any parsed content. It has the following implications:
- When reading a text-based input, the sequence of characters defined in
lineSeparatorwill be replaced by this character. - When writing to a text-based output, this character will be replaced by the sequence of characters defined in
lineSeparator.
normalizedNewlinedefaults to '\n'. - When reading a text-based input, the sequence of characters defined in
- comment:a character that, if found in the beginning of a line of text, represents comment in any text-based input supported by univocity-parsers.
commentdefaults to '#'.
- Author:
- Univocity Software Pty Ltd - parsers@univocity.com
- See Also:
CsvFormat,FixedWidthFormat
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedFormat()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected Formatclone()chargetComment()Returns the character that represents a line comment.protected abstract java.util.TreeMap<java.lang.String,java.lang.Object>getConfiguration()char[]getLineSeparator()Returns the current line separator character sequence, which can contain 1 to 2 characters.java.lang.StringgetLineSeparatorString()Returns the current line separator sequence as a String of 1 to 2 characters.chargetNormalizedNewline()Returns the normalized newline character, which is automatically replaced bylineSeparatorwhen reading/writing.static char[]getSystemLineSeparator()Returns the system's line separator sequence, which can contain 1 to 2 characters.booleanisComment(char ch)Identifies whether or not a given character represents a commentbooleanisNewLine(char ch)Compares the given character against thenormalizedNewlinecharacter.voidsetComment(char comment)Defines the character that represents a line comment when found in the beginning of a line of text.voidsetLineSeparator(char[] lineSeparator)Defines the line separator sequence that should be used for parsing and writing.voidsetLineSeparator(java.lang.String lineSeparator)Defines the line separator sequence that should be used for parsing and writing.voidsetNormalizedNewline(char normalizedNewline)Sets the normalized newline character, which is automatically replaced bylineSeparatorwhen reading/writingjava.lang.StringtoString()
-
-
-
Method Detail
-
getLineSeparator
public char[] getLineSeparator()
Returns the current line separator character sequence, which can contain 1 to 2 characters. Defaults to the system's line separator sequence (usually '\r\n' in Windows, '\r' in MacOS, and '\n' in Linux/Unix).- Returns:
- the sequence of 1 to 2 characters that identifies the end of a line
-
getSystemLineSeparator
public static char[] getSystemLineSeparator()
Returns the system's line separator sequence, which can contain 1 to 2 characters.- Returns:
- a sequence of 1 to 2 characters used as the system's line ending.
-
getLineSeparatorString
public java.lang.String getLineSeparatorString()
Returns the current line separator sequence as a String of 1 to 2 characters. Defaults to the system's line separator sequence (usually "\r\n" in Windows, "\r" in MacOS, and "\n" in Linux/Unix).- Returns:
- the sequence of 1 to 2 characters that identifies the end of a line
-
setLineSeparator
public void setLineSeparator(java.lang.String lineSeparator)
Defines the line separator sequence that should be used for parsing and writing.- Parameters:
lineSeparator- a sequence of 1 to 2 characters that identifies the end of a line
-
setLineSeparator
public void setLineSeparator(char[] lineSeparator)
Defines the line separator sequence that should be used for parsing and writing.- Parameters:
lineSeparator- a sequence of 1 to 2 characters that identifies the end of a line
-
getNormalizedNewline
public char getNormalizedNewline()
Returns the normalized newline character, which is automatically replaced bylineSeparatorwhen reading/writing. Defaults to '\n'.- Returns:
- the normalized newline character
-
setNormalizedNewline
public void setNormalizedNewline(char normalizedNewline)
Sets the normalized newline character, which is automatically replaced bylineSeparatorwhen reading/writing- Parameters:
normalizedNewline- a single character used to represent a line separator.
-
isNewLine
public boolean isNewLine(char ch)
Compares the given character against thenormalizedNewlinecharacter.- Parameters:
ch- the character to be verified- Returns:
- true if the given character is the normalized newline character, false otherwise
-
getComment
public char getComment()
Returns the character that represents a line comment. Defaults to '#'Set it to '\0' to disable comment skipping.
- Returns:
- the comment character
-
setComment
public void setComment(char comment)
Defines the character that represents a line comment when found in the beginning of a line of text. Defaults to '#'Use '\0' to disable comment skipping.
- Parameters:
comment- the comment character
-
isComment
public boolean isComment(char ch)
Identifies whether or not a given character represents a comment- Parameters:
ch- the character to be verified- Returns:
- true if the given character is the comment character, false otherwise
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getConfiguration
protected abstract java.util.TreeMap<java.lang.String,java.lang.Object> getConfiguration()
-
clone
protected Format clone()
- Overrides:
clonein classjava.lang.Object
-
-