Package csv.util
Class ObjectWriter<T>
java.lang.Object
csv.util.ObjectWriter<T>
Writes Objects into a table.
This class is different to BeanWriter as it asks a converter to convert the object to a row first.
// Create an instance of your table writer
TableWriter tableWriter = ...;
// Get an instance of your object converter
ObjectConverter<MyClass> converter = new MyClassConverter();
// Get an instance of your table header provider (if you need it)
TableHeaderProvider headerProvider = new MyTableHeaderProvider();
// Now write to the table stream
ObjectWriter<MyClass> writer = new ObjectWriter(tableWriter, converter, headerProvider);
writer.write(object1);
writer.write(object2);
writer.write(new MyClass[] { object1, object2, object 3 });
// Close the writer
writer.close();
- Author:
- ralph
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ObjectConverter<T> protected TableHeaderProviderprotected booleanprotected TableWriter -
Constructor Summary
ConstructorsConstructorDescriptionObjectWriter(TableWriter writer, ObjectConverter<T> converter) Constructor.ObjectWriter(TableWriter writer, ObjectConverter<T> converter, TableHeaderProvider headerProvider) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the stream.Returns the row converter.Returns the table header provider.Returns the table writer.voidsetConverter(ObjectConverter<T> converter) Sets the row converter.voidsetHeaderProvider(TableHeaderProvider headerProvider) Sets the table header provider.voidWrites multiple objects to the stream.voidWrites the object to the stream.voidWrites multiple objects to the stream.voidwriteHeader(String[] headerRow) Writes the header row.
-
Field Details
-
writer
-
converter
-
headerProvider
-
rowsWritten
protected boolean rowsWritten
-
-
Constructor Details
-
ObjectWriter
Constructor.- Parameters:
writer- - the writer to write toconverter- - the converter to be used
-
ObjectWriter
public ObjectWriter(TableWriter writer, ObjectConverter<T> converter, TableHeaderProvider headerProvider) Constructor.- Parameters:
writer- - the writer to write toconverter- - the converter to be usedheaderProvider- - the header provider (can be null)
-
-
Method Details
-
getConverter
Returns the row converter.- Returns:
- the row converter
-
setConverter
Sets the row converter.- Parameters:
converter- the row converter to be used
-
getHeaderProvider
Returns the table header provider.- Returns:
- the table header provider
-
setHeaderProvider
Sets the table header provider.- Parameters:
headerProvider- the table header provider to be used.
-
getWriter
Returns the table writer.- Returns:
- the table writer
-
writeHeader
Writes the header row. -
write
Writes multiple objects to the stream. -
write
Writes multiple objects to the stream. -
write
Writes the object to the stream. -
close
public void close()Closes the stream.
-