Package csv
Class CSVFactory
java.lang.Object
csv.CSVFactory
This factory returns correct reader and writer implementations
for given files.
java.io.File f1 = new java.io.File("csv-test.csv");
java.io.File f2 = new java.io.File("excel-test.xls");
java.io.File f3 = new java.io.File("excel-test.xlsx");
java.io.File f4 = new java.io.File("xml-test.xml");
// Returns implementation for CSV file
TableReader in1 = CSVFactory.getFactory().getReader(f1);
TableWriter out1 = CSVFactory.getFactory().getWriter(f1);
// Returns implementation for classic Excel files
TableReader in2 = CSVFactory.getFactory().getReader(f2);
TableWriter out2 = CSVFactory.getFactory().getWriter(f2);
// Returns implementation for XML-based Excel files
TableReader in3 = CSVFactory.getFactory().getReader(f3);
TableWriter out3 = CSVFactory.getFactory().getWriter(f3);
// Returns implementation for XML files
TableReader in4 = CSVFactory.getFactory().getReader(f4);
TableWriter out4 = CSVFactory.getFactory().getWriter(f4);
- Author:
- RalphSchuster
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic CSVFactoryReturns the factory for rading/writing tables.getMimeType(File file) Returns the MIME type for the given file.getMimeTypeReader(String mimeType) Returns a reader for the given MIME type.getMimeTypeWriter(String mimeType) Returns a writer for the given MIME type.Returns the correct reader for the given file.Returns the correct reader for the given file.Returns the correct reader for the given file.Returns the correct reader for the given file.protected voidinit()Initializes the factory.protected voidInitializes the reader map.protected voidInitializes the writer map.voidregister(MimeTypeInfo mimeTypeInfo) Registers a new MIME type.
-
Constructor Details
-
CSVFactory
protected CSVFactory()Creates the factory and initializes.
-
-
Method Details
-
getFactory
Returns the factory for rading/writing tables.- Returns:
- factory factory object (singleton)
-
init
protected void init()Initializes the factory. -
initReaderMap
protected void initReaderMap()Initializes the reader map. -
initWriterMap
protected void initWriterMap()Initializes the writer map. -
register
Registers a new MIME type.- Parameters:
mimeTypeInfo- the info to register
-
getReader
Returns the correct reader for the given file.- Parameters:
file- filename- Returns:
- reader class instance to be used
- Throws:
IOException- when the file cannot be read
-
getReader
Returns the correct reader for the given file.- Parameters:
file- file- Returns:
- reader class instance to be used
- Throws:
IOException- when the file cannot be read
-
getMimeTypeReader
Returns a reader for the given MIME type.- Parameters:
mimeType- MIME type- Returns:
- reader to be used
-
getWriter
Returns the correct reader for the given file.- Parameters:
file- filename- Returns:
- reader class instance to be used
- Throws:
IOException- when the file cannot be written
-
getWriter
Returns the correct reader for the given file.- Parameters:
file- file- Returns:
- reader class instance to be used
- Throws:
IOException- when the file cannot be written
-
getMimeTypeWriter
Returns a writer for the given MIME type.- Parameters:
mimeType- MIME type- Returns:
- writer to be used
-
getMimeType
Returns the MIME type for the given file.- Parameters:
file- file to check- Returns:
- MIME type of file
-