Package csv

Class CSVFactory

java.lang.Object
csv.CSVFactory

public class CSVFactory extends Object
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 Details

    • CSVFactory

      protected CSVFactory()
      Creates the factory and initializes.
  • Method Details

    • getFactory

      public static CSVFactory 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

      public void register(MimeTypeInfo mimeTypeInfo)
      Registers a new MIME type.
      Parameters:
      mimeTypeInfo - the info to register
    • getReader

      public TableReader getReader(String file) throws IOException
      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

      public TableReader getReader(File file) throws IOException
      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

      public AbstractStreamTableReader getMimeTypeReader(String mimeType)
      Returns a reader for the given MIME type.
      Parameters:
      mimeType - MIME type
      Returns:
      reader to be used
    • getWriter

      public AbstractStreamTableWriter getWriter(String file) throws IOException
      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

      public AbstractStreamTableWriter getWriter(File file) throws IOException
      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

      public AbstractStreamTableWriter getMimeTypeWriter(String mimeType)
      Returns a writer for the given MIME type.
      Parameters:
      mimeType - MIME type
      Returns:
      writer to be used
    • getMimeType

      public String getMimeType(File file)
      Returns the MIME type for the given file.
      Parameters:
      file - file to check
      Returns:
      MIME type of file