public class DelimitedText
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected java.lang.String[] |
columnNames
Delimited text column names.
|
static char |
FIELD_DELIMITER_COMMA
Standard comma (
',' ) delimiter. |
static char |
FIELD_DELIMITER_DEFAULT
Default field delimiter (
FIELD_DELIMITER_COMMA ). |
static char |
FIELD_DELIMITER_TAB
Standard tab (
'\t' ) delimiter. |
static java.lang.String |
FIELD_ELEMENT
Delimited text XML field-name element.
|
static java.lang.String |
FIELD_NAME_ATTR
Delimited text XML field element name attribute.
|
static java.lang.String |
FIELD_NAME_ELEMENT
Delimited text XML field element.
|
static char |
FIELD_QUOTE
Quote character (
'"' ). |
protected char |
fieldDelimiter
Delimited text field delimiter character.
|
protected boolean |
hasHeaderRow
Delimited text header row indicator.
|
static java.lang.String |
HEADER_ELEMENT
Delimited text XML header element.
|
static java.lang.String |
RECORD_ELEMENT
Delimited text XML record element
|
static java.lang.String |
ROOT_ELEMENT
Delimited text XML root element.
|
Constructor and Description |
---|
DelimitedText()
Construct a
DelimitedText instance with defaults. |
DelimitedText(char inFieldDelimiter)
Construct a
DelimitedText instance with a custom field delimiter character. |
DelimitedText(char inFieldDelimiter,
boolean inHasHeaderRow)
Construct a
DelimitedText instance with a custom field delimiter character. |
DelimitedText(char inFieldDelimiter,
java.lang.String[] inColumnNames)
Construct a
DelimitedText instance with a custom field delimiter character. |
Modifier and Type | Method and Description |
---|---|
void |
convertFromXML(org.w3c.dom.Document doc,
java.io.BufferedWriter output)
Convert XML to delimited text.
|
void |
convertFromXML(org.w3c.dom.Document doc,
java.io.OutputStream output)
Convert XML to delimited text.
|
void |
convertFromXML(org.w3c.dom.Document doc,
java.lang.String fileName)
Convert XML to delimited text.
|
void |
convertFromXML(org.w3c.dom.Document doc,
java.io.Writer output)
Convert XML to delimited text.
|
org.w3c.dom.Document |
convertToXML(java.io.BufferedReader input)
Convert delimited text to XML.
|
org.w3c.dom.Document |
convertToXML(java.io.InputStream input)
Convert delimited text to XML.
|
org.w3c.dom.Document |
convertToXML(java.io.Reader input)
Convert delimited text to XML.
|
org.w3c.dom.Document |
convertToXML(java.lang.String fileName)
Convert delimited text to XML.
|
protected java.lang.String |
quoteIfNeeded(java.lang.String string)
Quote a delimited text field of it contains special characters.
|
protected java.lang.String[] |
readRecord(java.io.BufferedReader input)
Read a delimited text record.
|
protected void |
writeField(org.w3c.dom.Element field,
java.io.BufferedWriter output)
Write a delimited text field.
|
protected void |
writeRecord(org.w3c.dom.Element record,
java.io.BufferedWriter output)
Write a delimited text record.
|
public static final char FIELD_DELIMITER_COMMA
','
) delimiter.public static final char FIELD_DELIMITER_TAB
'\t'
) delimiter.public static final char FIELD_DELIMITER_DEFAULT
FIELD_DELIMITER_COMMA
).public static final char FIELD_QUOTE
'"'
).public static final java.lang.String ROOT_ELEMENT
public static final java.lang.String HEADER_ELEMENT
public static final java.lang.String FIELD_NAME_ELEMENT
public static final java.lang.String RECORD_ELEMENT
public static final java.lang.String FIELD_ELEMENT
public static final java.lang.String FIELD_NAME_ATTR
protected char fieldDelimiter
protected java.lang.String[] columnNames
protected boolean hasHeaderRow
public DelimitedText()
DelimitedText
instance with defaults.public DelimitedText(char inFieldDelimiter)
DelimitedText
instance with a custom field delimiter character.inFieldDelimiter
- the field delimiter characterpublic DelimitedText(char inFieldDelimiter, boolean inHasHeaderRow)
DelimitedText
instance with a custom field delimiter character.inFieldDelimiter
- the field delimiter characterinHasHeaderRow
- true
if input/output delimited text file has a header rowpublic DelimitedText(char inFieldDelimiter, java.lang.String[] inColumnNames)
DelimitedText
instance with a custom field delimiter character.inFieldDelimiter
- the field delimiter characterinColumnNames
- list of column names to use on inputpublic org.w3c.dom.Document convertToXML(java.lang.String fileName) throws java.io.IOException, org.w3c.dom.DOMException
fileName
- name of delimited text filejava.io.IOException
- thrown if an error reading the file occursorg.w3c.dom.DOMException
- thrown if an error constructing the XML representaton occurspublic org.w3c.dom.Document convertToXML(java.io.InputStream input) throws java.io.IOException, org.w3c.dom.DOMException
input
- InputStream
containing delimited textjava.io.IOException
- thrown if an error reading the file occursorg.w3c.dom.DOMException
- thrown if an error constructing the XML representaton occurspublic org.w3c.dom.Document convertToXML(java.io.Reader input) throws java.io.IOException, org.w3c.dom.DOMException
input
- Reader
containing delimited textjava.io.IOException
- thrown if an error reading the file occursorg.w3c.dom.DOMException
- thrown if an error constructing the XML representaton occurspublic org.w3c.dom.Document convertToXML(java.io.BufferedReader input) throws java.io.IOException, org.w3c.dom.DOMException
input
- BufferedReader
containing delimited textjava.io.IOException
- thrown if an error reading the file occursorg.w3c.dom.DOMException
- thrown if an error constructing the XML representaton occursprotected java.lang.String[] readRecord(java.io.BufferedReader input) throws java.io.IOException
input
- BufferedReader
positioned at beginning of delimited text recordjava.io.IOException
- thrown if an error occurs reading from input
.public void convertFromXML(org.w3c.dom.Document doc, java.lang.String fileName) throws java.io.IOException, org.w3c.dom.DOMException
doc
- DOM document to convertfileName
- name of output delimited text filejava.io.IOException
- thrown if an error occurs writing to the fileorg.w3c.dom.DOMException
- thrown if an error occurs accessing the XMLpublic void convertFromXML(org.w3c.dom.Document doc, java.io.OutputStream output) throws java.io.IOException, org.w3c.dom.DOMException
doc
- DOM document to convertoutput
- delimited text OutputStream
java.io.IOException
- thrown if an error occurs writing to output
org.w3c.dom.DOMException
- thrown if an error occurs accessing the XMLpublic void convertFromXML(org.w3c.dom.Document doc, java.io.Writer output) throws java.io.IOException, org.w3c.dom.DOMException
doc
- DOM document to convertoutput
- delimited text Writerjava.io.IOException
- thrown if an error occurs writing to output
org.w3c.dom.DOMException
- thrown if an error occurs accessing the XMLpublic void convertFromXML(org.w3c.dom.Document doc, java.io.BufferedWriter output) throws java.io.IOException, org.w3c.dom.DOMException
doc
- DOM document to convertoutput
- delimited text BufferedWriter
java.io.IOException
- thrown if an error occurs writing to output
org.w3c.dom.DOMException
- thrown if an error occurs accessing the XMLprotected void writeRecord(org.w3c.dom.Element record, java.io.BufferedWriter output) throws java.io.IOException, org.w3c.dom.DOMException
record
- DOM record elementoutput
- delimited text BufferedWriter
java.io.IOException
- thrown if an error occurs writing to output
org.w3c.dom.DOMException
- thrown if an error occurs accessing the XMLprotected void writeField(org.w3c.dom.Element field, java.io.BufferedWriter output) throws java.io.IOException, org.w3c.dom.DOMException
field
- DOM field elementoutput
- delimited text BufferedWriter
java.io.IOException
- thrown if an error occurs writing to output
org.w3c.dom.DOMException
- thrown if an error occurs accessing the XMLprotected java.lang.String quoteIfNeeded(java.lang.String string)
string
- value to quote