Package csv.mapper

Class StreamMapper

java.lang.Object
csv.mapper.StreamMapper

public class StreamMapper extends Object
The stream mapper is the central place to convert column objects from or into a table stream.

It has a register of type converters that can be used with a table reader or writer. Text-based table readers/writers use the StringMappings converters by default. But you can change or replace them by your own mappings:

   ExcelReader in = new ExcelReader(file);
   StreamMapper mapper = new StreamMapper(myMappings);
   mapper.add(otherMappings);
   mapper.remove(anyConverter);
   in.setMapper(myMapper);
   
   // start using the reader now...
   
   ExcelWriter out = new ExcelWriter(file);
   StreamMapper mapper = new StreamMapper(myMappings);
   mapper.add(otherMappings);
   mapper.remove(anyConverter);
   out.setMapper(myMapper);
   
   // start using the writer now...
 
Author:
ralph
  • Field Details

  • Constructor Details

    • StreamMapper

      public StreamMapper()
      Default constructor.
    • StreamMapper

      public StreamMapper(MappingCollection... collections)
      Constructor to ease construction of mapper objects.
      Parameters:
      collections - - collections to be added to this mapper.
    • StreamMapper

      public StreamMapper(TypeConverter... converters)
      Constructor to ease construction of mapper objects.
      Parameters:
      converters - - converters to be added to this mapper.
  • Method Details

    • add

      public void add(MappingCollection collection)
      Add the mappings of the given collection.
      Parameters:
      collection - the collection to be added.
    • remove

      public void remove(MappingCollection collection)
      Remove the mappings of the given collection.
      Parameters:
      collection - the collection to be removed.
    • add

      public void add(TypeConverter converter)
      Add another converter to this collection.
      Parameters:
      converter - converter to be added
    • remove

      public void remove(TypeConverter converter)
      Remove a converter from this collection.
      Parameters:
      converter - converter to be removed
    • remove

      public void remove(Class<?> type)
      Remove a converter from this collection.
      Parameters:
      type - type to be removed
    • getConverter

      protected TypeConverter getConverter(Class<?> type)
      Returns a type conversion handler for the given type.
      Parameters:
      type - type to get a handler for
      Returns:
      conversion handler
    • toStream

      public Object toStream(Object value)
      Converts the value to its stream representation.
      Parameters:
      value - object
      Returns:
      stream representation
    • fromStream

      public Object fromStream(Class<?> targetClass, Object value)
      Converts the value from its stream representation.
      Parameters:
      targetClass - - the target class to be returned
      value - object - stream representation
      Returns:
      client representation