com.univocity.parsers.common.routine
Class AbstractRoutines<P extends CommonParserSettings<?>,W extends CommonWriterSettings<?>>

java.lang.Object
  extended by com.univocity.parsers.common.routine.AbstractRoutines<P,W>
Type Parameters:
P - parser configuration class
W - writer configuration class
Direct Known Subclasses:
CsvRoutines, FixedWidthRoutines, TsvRoutines

public abstract class AbstractRoutines<P extends CommonParserSettings<?>,W extends CommonWriterSettings<?>>
extends Object

Basic implementation of commonly used routines around parsing/writing of data that can be reused and extended by parsers/writers of any supported format.


Constructor Summary
AbstractRoutines(String routineDescription)
          Creates a new instance of this routine class.
AbstractRoutines(String routineDescription, P parserSettings)
          Creates a new instance of this routine class.
AbstractRoutines(String routineDescription, P parserSettings, W writerSettings)
          Creates a new instance of this routine class.
AbstractRoutines(String routineDescription, W writerSettings)
          Creates a new instance of this routine class.
 
Method Summary
protected  void adjustColumnLengths(String[] headers, int[] lengths)
          Allows writers of any given format to adjust its settings to take into account column headers and lengths prior to writing data in any routine.
protected abstract  P createDefaultParserSettings()
          Creates a default parser settings configuration
protected abstract  W createDefaultWriterSettings()
          Creates a default writer settings configuration
protected abstract  AbstractParser<P> createParser(P parserSettings)
          Creates a new parser implementation using the given parser configuration
protected abstract  AbstractWriter<W> createWriter(Writer output, W writerSettings)
          Creates a new writer implementation using the given writer configuration
 P getParserSettings()
          Returns the parser configuration (if any) used by the routines of this utility class.
 W getWriterSettings()
          Returns the writer configuration (if any) used by the routines of this utility class.
<T> Iterable<T>
iterate(Class<T> beanType, File input)
          Iterates over a file to produce instances of annotated java beans on demand.
<T> Iterable<T>
iterate(Class<T> beanType, File input, Charset encoding)
          Iterates over a file to produce instances of annotated java beans on demand.
<T> Iterable<T>
iterate(Class<T> beanType, File input, String encoding)
          Iterates over a file to produce instances of annotated java beans on demand.
<T> Iterable<T>
iterate(Class<T> beanType, InputStream input)
          Iterates over an input stream to produce instances of annotated java beans on demand.
<T> Iterable<T>
iterate(Class<T> beanType, InputStream input, Charset encoding)
          Iterates over an input stream to produce instances of annotated java beans on demand.
<T> Iterable<T>
iterate(Class<T> beanType, InputStream input, String encoding)
          Iterates over an input stream to produce instances of annotated java beans on demand.
<T> Iterable<T>
iterate(Class<T> beanType, Reader input)
          Iterates over an input to produce instances of annotated java beans on demand.
<T> List<T>
parseAll(Class<T> beanType, File input)
          Parses a file into a list of annotated java beans
<T> List<T>
parseAll(Class<T> beanType, File input, Charset encoding)
          Parses a file into a list of annotated java beans
<T> List<T>
parseAll(Class<T> beanType, File input, String encoding)
          Parses a file into a list of annotated java beans
<T> List<T>
parseAll(Class<T> beanType, InputStream input)
          Parses an input stream into a list of annotated java beans
<T> List<T>
parseAll(Class<T> beanType, InputStream input, Charset encoding)
          Parses an input stream into a list of annotated java beans
<T> List<T>
parseAll(Class<T> beanType, InputStream input, String encoding)
          Parses an input stream into a list of annotated java beans
<T> List<T>
parseAll(Class<T> beanType, Reader input)
          Parses the input into a list of annotated java beans
 void parseAndWrite(Reader input, Writer output)
          Reads all data from a given input and writes it to an output.
 void setParserSettings(P parserSettings)
          Defines the parser configuration to be used by the routines of this utility class.
 void setWriterSettings(W writerSettings)
          Defines the writer configuration to be used by the routines of this utility class.
 String toString()
           
 void write(ResultSet rs, File output)
          Dumps the content of a ResultSet into a file.
 void write(ResultSet rs, File output, Charset encoding)
          Dumps the content of a ResultSet into a file.
 void write(ResultSet rs, File output, String encoding)
          Dumps the content of a ResultSet into a file.
 void write(ResultSet rs, OutputStream output)
          Dumps the content of a ResultSet into an output stream.
 void write(ResultSet rs, OutputStream output, Charset encoding)
          Dumps the content of a ResultSet into an output stream.
 void write(ResultSet rs, OutputStream output, String encoding)
          Dumps the content of a ResultSet into an output stream.
 void write(ResultSet rs, Writer output)
          Dumps the content of a ResultSet.
<T> void
writeAll(Iterable<T> elements, Class<T> beanType, File output, Charset encoding, String... headers)
          Writes a collection of annotated java beans to a given output.
<T> void
writeAll(Iterable<T> elements, Class<T> beanType, File output, String... headers)
          Writes a collection of annotated java beans to a given output.
<T> void
writeAll(Iterable<T> elements, Class<T> beanType, File output, String encoding, String[] headers)
          Writes a collection of annotated java beans to a given output.
<T> void
writeAll(Iterable<T> elements, Class<T> beanType, OutputStream output, Charset encoding, String... headers)
          Writes a collection of annotated java beans to a given output.
<T> void
writeAll(Iterable<T> elements, Class<T> beanType, OutputStream output, String... headers)
          Writes a collection of annotated java beans to a given output.
<T> void
writeAll(Iterable<T> elements, Class<T> beanType, OutputStream output, String encoding, String[] headers)
          Writes a collection of annotated java beans to a given output.
<T> void
writeAll(Iterable<T> elements, Class<T> beanType, Writer output, String... headers)
          Writes a collection of annotated java beans to a given output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractRoutines

public AbstractRoutines(String routineDescription)
Creates a new instance of this routine class.

Parameters:
routineDescription - description of the routines for a given format

AbstractRoutines

public AbstractRoutines(String routineDescription,
                        P parserSettings)
Creates a new instance of this routine class.

Parameters:
routineDescription - description of the routines for a given format
parserSettings - configuration to use for parsing

AbstractRoutines

public AbstractRoutines(String routineDescription,
                        W writerSettings)
Creates a new instance of this routine class.

Parameters:
routineDescription - description of the routines for a given format
writerSettings - configuration to use for writing

AbstractRoutines

public AbstractRoutines(String routineDescription,
                        P parserSettings,
                        W writerSettings)
Creates a new instance of this routine class.

Parameters:
routineDescription - description of the routines for a given format
parserSettings - configuration to use for parsing
writerSettings - configuration to use for writing
Method Detail

createParser

protected abstract AbstractParser<P> createParser(P parserSettings)
Creates a new parser implementation using the given parser configuration

Parameters:
parserSettings - the configuration for new parser
Returns:
a parser implementation configured according to the given settings object.

createWriter

protected abstract AbstractWriter<W> createWriter(Writer output,
                                                  W writerSettings)
Creates a new writer implementation using the given writer configuration

Parameters:
output - target output of the routine.
writerSettings - the configuration for new writer
Returns:
a writer implementation configured according to the given settings object.

createDefaultParserSettings

protected abstract P createDefaultParserSettings()
Creates a default parser settings configuration

Returns:
a new instance of a usable parser configuration.

createDefaultWriterSettings

protected abstract W createDefaultWriterSettings()
Creates a default writer settings configuration

Returns:
a new instance of a usable writer configuration.

getParserSettings

public final P getParserSettings()
Returns the parser configuration (if any) used by the routines of this utility class.

Returns:
the parser configuration.

setParserSettings

public final void setParserSettings(P parserSettings)
Defines the parser configuration to be used by the routines of this utility class.

Parameters:
parserSettings - the parser configuration.

getWriterSettings

public final W getWriterSettings()
Returns the writer configuration (if any) used by the routines of this utility class.

Returns:
the writer configuration.

setWriterSettings

public final void setWriterSettings(W writerSettings)
Defines the writer configuration to be used by the routines of this utility class.

Parameters:
writerSettings - the parser configuration.

adjustColumnLengths

protected void adjustColumnLengths(String[] headers,
                                   int[] lengths)
Allows writers of any given format to adjust its settings to take into account column headers and lengths prior to writing data in any routine.

Parameters:
headers - headers to be written
lengths - the corresponding lengths of each header

write

public final void write(ResultSet rs,
                        File output)
Dumps the content of a ResultSet into a file.

Parameters:
rs - the ResultSet whose contents should be read and written to a given output
output - the output file that will store the data in the given ResultSet in the format specified by concrete implementations of this class.

write

public final void write(ResultSet rs,
                        File output,
                        String encoding)
Dumps the content of a ResultSet into a file.

Parameters:
rs - the ResultSet whose contents should be read and written to a given output
output - the output file that will store the data in the given ResultSet in the format specified by concrete implementations of this class.
encoding - the output encoding of the file

write

public final void write(ResultSet rs,
                        File output,
                        Charset encoding)
Dumps the content of a ResultSet into a file.

Parameters:
rs - the ResultSet whose contents should be read and written to a given output
output - the output file that will store the data in the given ResultSet in the format specified by concrete implementations of this class.
encoding - the output encoding of the file

write

public final void write(ResultSet rs,
                        OutputStream output)
Dumps the content of a ResultSet into an output stream.

Parameters:
rs - the ResultSet whose contents should be read and written to a given output
output - the output stream that will store the data in the given ResultSet in the format specified by concrete implementations of this class.

write

public final void write(ResultSet rs,
                        OutputStream output,
                        String encoding)
Dumps the content of a ResultSet into an output stream.

Parameters:
rs - the ResultSet whose contents should be read and written to a given output
output - the output file that will store the data in the given ResultSet in the format specified by concrete implementations of this class.
encoding - the output encoding of the output stream

write

public final void write(ResultSet rs,
                        OutputStream output,
                        Charset encoding)
Dumps the content of a ResultSet into an output stream.

Parameters:
rs - the ResultSet whose contents should be read and written to a given output
output - the output file that will store the data in the given ResultSet in the format specified by concrete implementations of this class.
encoding - the output encoding of the output stream

write

public final void write(ResultSet rs,
                        Writer output)
Dumps the content of a ResultSet.

Parameters:
rs - the ResultSet whose contents should be read and written to a given output
output - the output that will store the data in the given ResultSet in the format specified by concrete implementations of this class.

parseAndWrite

public final void parseAndWrite(Reader input,
                                Writer output)
Reads all data from a given input and writes it to an output.

Parameters:
input - the input data to be parsed using the settings provided in getParserSettings()
output - the output into where the input data should be written, using the format provided in getWriterSettings()

writeAll

public <T> void writeAll(Iterable<T> elements,
                         Class<T> beanType,
                         File output,
                         String... headers)
Writes a collection of annotated java beans to a given output.

Type Parameters:
T - the type of element in the given collection
Parameters:
elements - the elements to write to the output
beanType - the type of element in the given collection
output - the output into which the given elements will be written
headers - headers to use in the first row of the written result.

writeAll

public <T> void writeAll(Iterable<T> elements,
                         Class<T> beanType,
                         File output,
                         String encoding,
                         String[] headers)
Writes a collection of annotated java beans to a given output.

Type Parameters:
T - the type of element in the given collection
Parameters:
elements - the elements to write to the output
beanType - the type of element in the given collection
output - the output into which the given elements will be written
encoding - the output encoding to use for writing
headers - headers to use in the first row of the written result.

writeAll

public <T> void writeAll(Iterable<T> elements,
                         Class<T> beanType,
                         File output,
                         Charset encoding,
                         String... headers)
Writes a collection of annotated java beans to a given output.

Type Parameters:
T - the type of element in the given collection
Parameters:
elements - the elements to write to the output
beanType - the type of element in the given collection
output - the output into which the given elements will be written
encoding - the output encoding to use for writing
headers - headers to use in the first row of the written result.

writeAll

public <T> void writeAll(Iterable<T> elements,
                         Class<T> beanType,
                         OutputStream output,
                         String... headers)
Writes a collection of annotated java beans to a given output.

Type Parameters:
T - the type of element in the given collection
Parameters:
elements - the elements to write to the output
beanType - the type of element in the given collection
output - the output into which the given elements will be written
headers - headers to use in the first row of the written result.

writeAll

public <T> void writeAll(Iterable<T> elements,
                         Class<T> beanType,
                         OutputStream output,
                         String encoding,
                         String[] headers)
Writes a collection of annotated java beans to a given output.

Type Parameters:
T - the type of element in the given collection
Parameters:
elements - the elements to write to the output
beanType - the type of element in the given collection
output - the output into which the given elements will be written
encoding - the output encoding to use for writing
headers - headers to use in the first row of the written result.

writeAll

public <T> void writeAll(Iterable<T> elements,
                         Class<T> beanType,
                         OutputStream output,
                         Charset encoding,
                         String... headers)
Writes a collection of annotated java beans to a given output.

Type Parameters:
T - the type of element in the given collection
Parameters:
elements - the elements to write to the output
beanType - the type of element in the given collection
output - the output into which the given elements will be written
encoding - the output encoding to use for writing
headers - headers to use in the first row of the written result.

writeAll

public <T> void writeAll(Iterable<T> elements,
                         Class<T> beanType,
                         Writer output,
                         String... headers)
Writes a collection of annotated java beans to a given output.

Type Parameters:
T - the type of element in the given collection
Parameters:
elements - the elements to write to the output
beanType - the type of element in the given collection
output - the output into which the given elements will be written
headers - headers to use in the first row of the written result.

parseAll

public <T> List<T> parseAll(Class<T> beanType,
                            File input)
Parses a file into a list of annotated java beans

Type Parameters:
T - the type of java beans to be instantiated.
Parameters:
beanType - the type of java beans to be instantiated.
input - the file to be parsed
Returns:
an Iterable that allows iterating over the input and producing instances of java beans on demand.

parseAll

public <T> List<T> parseAll(Class<T> beanType,
                            File input,
                            String encoding)
Parses a file into a list of annotated java beans

Type Parameters:
T - the type of java beans to be instantiated.
Parameters:
beanType - the type of java beans to be instantiated.
input - the file to be parsed
encoding - encoding of the given file
Returns:
an Iterable that allows iterating over the input and producing instances of java beans on demand.

parseAll

public <T> List<T> parseAll(Class<T> beanType,
                            File input,
                            Charset encoding)
Parses a file into a list of annotated java beans

Type Parameters:
T - the type of java beans to be instantiated.
Parameters:
beanType - the type of java beans to be instantiated.
input - the file to be parsed
encoding - encoding of the given file
Returns:
a list containing all java beans read from the input.

parseAll

public <T> List<T> parseAll(Class<T> beanType,
                            InputStream input)
Parses an input stream into a list of annotated java beans

Type Parameters:
T - the type of java beans to be instantiated.
Parameters:
beanType - the type of java beans to be instantiated.
input - the input stream to be parsed
Returns:
a list containing all java beans read from the input.

parseAll

public <T> List<T> parseAll(Class<T> beanType,
                            InputStream input,
                            String encoding)
Parses an input stream into a list of annotated java beans

Type Parameters:
T - the type of java beans to be instantiated.
Parameters:
beanType - the type of java beans to be instantiated.
input - the input stream to be parsed
encoding - encoding of the given input stream
Returns:
a list containing all java beans read from the input.

parseAll

public <T> List<T> parseAll(Class<T> beanType,
                            InputStream input,
                            Charset encoding)
Parses an input stream into a list of annotated java beans

Type Parameters:
T - the type of java beans to be instantiated.
Parameters:
beanType - the type of java beans to be instantiated.
input - the input stream to be parsed
encoding - encoding of the given input stream
Returns:
a list containing all java beans read from the input.

parseAll

public <T> List<T> parseAll(Class<T> beanType,
                            Reader input)
Parses the input into a list of annotated java beans

Type Parameters:
T - the type of java beans to be instantiated.
Parameters:
beanType - the type of java beans to be instantiated.
input - the input to be parsed
Returns:
a list containing all java beans read from the input.

iterate

public <T> Iterable<T> iterate(Class<T> beanType,
                               File input)
Iterates over a file to produce instances of annotated java beans on demand.

Type Parameters:
T - the type of java beans to be instantiated.
Parameters:
beanType - the type of java beans to be instantiated.
input - the file to be parsed
Returns:
an Iterable that allows iterating over the input and producing instances of java beans on demand.

iterate

public <T> Iterable<T> iterate(Class<T> beanType,
                               File input,
                               String encoding)
Iterates over a file to produce instances of annotated java beans on demand.

Type Parameters:
T - the type of java beans to be instantiated.
Parameters:
beanType - the type of java beans to be instantiated.
input - the file to be parsed
encoding - encoding of the given file
Returns:
an Iterable that allows iterating over the input and producing instances of java beans on demand.

iterate

public <T> Iterable<T> iterate(Class<T> beanType,
                               File input,
                               Charset encoding)
Iterates over a file to produce instances of annotated java beans on demand.

Type Parameters:
T - the type of java beans to be instantiated.
Parameters:
beanType - the type of java beans to be instantiated.
input - the file to be parsed
encoding - encoding of the given file
Returns:
an Iterable that allows iterating over the input and producing instances of java beans on demand.

iterate

public <T> Iterable<T> iterate(Class<T> beanType,
                               InputStream input)
Iterates over an input stream to produce instances of annotated java beans on demand.

Type Parameters:
T - the type of java beans to be instantiated.
Parameters:
beanType - the type of java beans to be instantiated.
input - the input stream to be parsed
Returns:
an Iterable that allows iterating over the input and producing instances of java beans on demand.

iterate

public <T> Iterable<T> iterate(Class<T> beanType,
                               InputStream input,
                               String encoding)
Iterates over an input stream to produce instances of annotated java beans on demand.

Type Parameters:
T - the type of java beans to be instantiated.
Parameters:
beanType - the type of java beans to be instantiated.
input - the input stream to be parsed
encoding - encoding of the given input stream
Returns:
an Iterable that allows iterating over the input and producing instances of java beans on demand.

iterate

public <T> Iterable<T> iterate(Class<T> beanType,
                               InputStream input,
                               Charset encoding)
Iterates over an input stream to produce instances of annotated java beans on demand.

Type Parameters:
T - the type of java beans to be instantiated.
Parameters:
beanType - the type of java beans to be instantiated.
input - the input stream to be parsed
encoding - encoding of the given input stream
Returns:
an Iterable that allows iterating over the input and producing instances of java beans on demand.

iterate

public <T> Iterable<T> iterate(Class<T> beanType,
                               Reader input)
Iterates over an input to produce instances of annotated java beans on demand.

Type Parameters:
T - the type of java beans to be instantiated.
Parameters:
beanType - the type of java beans to be instantiated.
input - the input to be parsed
Returns:
an Iterable that allows iterating over the input and producing instances of java beans on demand.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2016 uniVocity Software Pty Ltd. All rights reserved.