Class DelimitedFileDataSource
- java.lang.Object
-
- repast.simphony.freezedry.AbstractDataSource<DFRowData>
-
- repast.simphony.freezedry.datasource.DelimitedFileDataSource
-
- All Implemented Interfaces:
FreezeDryedDataSource
public class DelimitedFileDataSource extends AbstractDataSource<DFRowData>
-
-
Field Summary
Fields Modifier and Type Field Description static char
DEFAULT_DELIMITER
protected String
path
protected boolean
reading
protected HashMap<String,au.com.bytecode.opencsv.CSVWriter>
writerMap
-
Fields inherited from class repast.simphony.freezedry.AbstractDataSource
ARRAY_MARKER, BYTES_MARKER, CHILD_CLASS_COL, CHILD_ID_COL, CHILD_ID_MARKER, CHILDREN_MARKER, CLASS_MARKER, ID_COL, PARENT_ID_COL, SPECIAL_COL_MARKER
-
-
Constructor Summary
Constructors Constructor Description DelimitedFileDataSource(String zipFileName)
DelimitedFileDataSource(String zipFileName, char delimiter)
DelimitedFileDataSource(String zipFileName, char delimiter, boolean read)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<String>
buildHeader(String[] header)
void
close()
Closes this data source.protected Object
convert(String field, String val)
protected void
endTypeRead(Class clazz)
Finishes the reading of the specified class.protected void
finishChildrenRead(FreezeDryedObject parent)
Ends the reading of the children for the specifiedFreezeDryedObject
.protected void
finishChildrenWrite(FreezeDryedObject fdo)
Finishes the writing of the children for the specifiedFreezeDryedObject
.protected void
finishTypeWrite(FreezeDryedObject object)
Finishes the writing of the specifiedFreezeDryedObject
.char
getDelimiter()
protected List<String>
getFields(String type)
Retrieves the fields for a specified type.protected Object
getFieldValue(DFRowData row, String field)
Retrieves the value of the specified field in the specified row of data.String
getPath()
protected au.com.bytecode.opencsv.CSVReader
getReader(String className)
protected byte[]
readByteArray(FreezeDryedObject fdo, String field, Object bytesId)
Reads in a byte[] that corresponds to the specified bytesId and will be loaded into the specified fdo through the specified field.protected DFRowData
readChildsRow(FreezeDryedObject parent, String id)
Reads in a row of data about a child of the specifiedFreezeDryedObject
.protected DFRowData
readRow(Class clazz, String key)
Reads in a row of data that will be parsed by the use of#getFieldValue(X, String)
andAbstractDataSource.getFields(String)
.void
reset()
Resets this data source by deleting all the files in the current directory.protected void
startChildrenRead(FreezeDryedObject fdo)
Initializes the reading of the children of a specifiedFreezeDryedObject
.protected void
startChildrenWrite(FreezeDryedObject fdo)
Initiates the writing of the children for the specifiedFreezeDryedObject
.protected void
startTypeRead(Class clazz)
Initiates the reading of the specified class.protected void
startTypeWrite(FreezeDryedObject object)
This is called at the start of a call to write.protected String
writeByteArray(FreezeDryedObject object, String fieldName, byte[] bs)
Writes a byte array retrieved from the specifiedFreezeDryedObject
with the specified fieldName.protected void
writeChildData(FreezeDryedObject fdo, HashMap<String,Object> child)
Writes the data for a child of the specifiedFreezeDryedObject
.protected void
writeRow(FreezeDryedObject object, Map<String,Object> row)
This writes a row of data out which was generated by the specifiedFreezeDryedObject
.-
Methods inherited from class repast.simphony.freezedry.AbstractDataSource
getArrayType, getArrayValue, getChildrenColumnName, getColumnKeysetPairs, getColumns, getTrueFieldName, getType, getType, getValue, getValue, getValue, getValueArray, pair, parseChildRow, parseRow, read, read, readChildren, readFreezeDryedParentChild, write, writeChildren
-
-
-
-
Field Detail
-
DEFAULT_DELIMITER
public static final char DEFAULT_DELIMITER
- See Also:
- Constant Field Values
-
path
protected String path
-
reading
protected boolean reading
-
-
Method Detail
-
reset
public void reset()
Resets this data source by deleting all the files in the current directory.- Specified by:
reset
in interfaceFreezeDryedDataSource
- Overrides:
reset
in classAbstractDataSource<DFRowData>
-
close
public void close() throws FreezeDryingException
Closes this data source.- Specified by:
close
in interfaceFreezeDryedDataSource
- Overrides:
close
in classAbstractDataSource<DFRowData>
- Throws:
FreezeDryingException
-
startTypeRead
protected void startTypeRead(Class clazz) throws FreezeDryingException
Description copied from class:AbstractDataSource
Initiates the reading of the specified class. This class represents is of a type that was at some point written out through aFreezeDryedObject
.- Specified by:
startTypeRead
in classAbstractDataSource<DFRowData>
- Parameters:
clazz
- the class that was the type returned byFreezeDryedObject.getType()
- Throws:
FreezeDryingException
-
readRow
protected DFRowData readRow(Class clazz, String key) throws FreezeDryingException
Description copied from class:AbstractDataSource
Reads in a row of data that will be parsed by the use of#getFieldValue(X, String)
andAbstractDataSource.getFields(String)
. If the data source can find an object with the specified key it should return data for reading that object, otherwise it may return any object.- Specified by:
readRow
in classAbstractDataSource<DFRowData>
- Parameters:
clazz
- the class the data will be used forkey
- the key of the object we're looking for, if null it should be ignored- Returns:
- a row of data
- Throws:
FreezeDryingException
-
getReader
protected au.com.bytecode.opencsv.CSVReader getReader(String className) throws FreezeDryingException
- Throws:
FreezeDryingException
-
endTypeRead
protected void endTypeRead(Class clazz)
Description copied from class:AbstractDataSource
Finishes the reading of the specified class.- Specified by:
endTypeRead
in classAbstractDataSource<DFRowData>
- Parameters:
clazz
- the class whose reading has completed
-
startTypeWrite
protected void startTypeWrite(FreezeDryedObject object) throws FreezeDryingException
Description copied from class:AbstractDataSource
This is called at the start of a call to write. This should cause any needed preparation for reading this type to occur. It will be followed by calls toAbstractDataSource.writeRow(FreezeDryedObject, Map)
and a call toAbstractDataSource.finishTypeWrite(FreezeDryedObject)
.- Specified by:
startTypeWrite
in classAbstractDataSource<DFRowData>
- Parameters:
object
- theFreezeDryedObject
who will begin to be written- Throws:
FreezeDryingException
- when there's an error
-
writeRow
protected void writeRow(FreezeDryedObject object, Map<String,Object> row) throws FreezeDryingException
Description copied from class:AbstractDataSource
This writes a row of data out which was generated by the specifiedFreezeDryedObject
. This will be preceded by acall and will be followed by calls to {@link #writeRow(FreezeDryedObject, Map)} and a call to {@link #finishTypeWrite(FreezeDryedObject)}.
- Specified by:
writeRow
in classAbstractDataSource<DFRowData>
row
- the data for the specifiedFreezeDryedObject
- Throws:
FreezeDryingException
- when there's an error
-
finishTypeWrite
protected void finishTypeWrite(FreezeDryedObject object) throws FreezeDryingException
Description copied from class:AbstractDataSource
Finishes the writing of the specifiedFreezeDryedObject
. This will be preceded by acall and calls to {@link #writeRow(FreezeDryedObject, Map)} (along with the other child and byte methods).
- Specified by:
finishTypeWrite
in classAbstractDataSource<DFRowData>
- Throws:
FreezeDryingException
- when there's an error
-
getFieldValue
protected Object getFieldValue(DFRowData row, String field)
Description copied from class:AbstractDataSource
Retrieves the value of the specified field in the specified row of data.- Specified by:
getFieldValue
in classAbstractDataSource<DFRowData>
- Parameters:
row
- the row (returned by#readRow(Class)
).field
- the field we're reading- Returns:
- the value of that field
-
startChildrenRead
protected void startChildrenRead(FreezeDryedObject fdo) throws FreezeDryingException
Description copied from class:AbstractDataSource
Initializes the reading of the children of a specifiedFreezeDryedObject
.- Specified by:
startChildrenRead
in classAbstractDataSource<DFRowData>
- Parameters:
fdo
- theFreezeDryedObject
whose children will be read- Throws:
FreezeDryingException
-
readChildsRow
protected DFRowData readChildsRow(FreezeDryedObject parent, String id) throws FreezeDryingException
Description copied from class:AbstractDataSource
Reads in a row of data about a child of the specifiedFreezeDryedObject
.- Specified by:
readChildsRow
in classAbstractDataSource<DFRowData>
- Parameters:
parent
- the parent of the child that will be readid
- the id of the child we're concerned with- Returns:
- a row of data on the child
- Throws:
FreezeDryingException
-
finishChildrenRead
protected void finishChildrenRead(FreezeDryedObject parent)
Description copied from class:AbstractDataSource
Ends the reading of the children for the specifiedFreezeDryedObject
.- Specified by:
finishChildrenRead
in classAbstractDataSource<DFRowData>
- Parameters:
parent
- theFreezeDryedObject
whose children have been read
-
writeByteArray
protected String writeByteArray(FreezeDryedObject object, String fieldName, byte[] bs) throws FreezeDryingException
Description copied from class:AbstractDataSource
Writes a byte array retrieved from the specifiedFreezeDryedObject
with the specified fieldName.- Specified by:
writeByteArray
in classAbstractDataSource<DFRowData>
- Parameters:
object
- the source of the datafieldName
- the field this data is assosciated withbs
- the data itself- Returns:
- the value to be written to the subclass for the fieldName (this could potentially just be an id, or it could just be the bytes themselves)
- Throws:
FreezeDryingException
-
readByteArray
protected byte[] readByteArray(FreezeDryedObject fdo, String field, Object bytesId) throws FreezeDryingException
Description copied from class:AbstractDataSource
Reads in a byte[] that corresponds to the specified bytesId and will be loaded into the specified fdo through the specified field.- Specified by:
readByteArray
in classAbstractDataSource<DFRowData>
- Parameters:
fdo
- the object that the bytes are going to be stored infield
- the field the bytes[] are for- Returns:
- the read in byte[]
- Throws:
FreezeDryingException
-
startChildrenWrite
protected void startChildrenWrite(FreezeDryedObject fdo) throws FreezeDryingException
Description copied from class:AbstractDataSource
Initiates the writing of the children for the specifiedFreezeDryedObject
.- Specified by:
startChildrenWrite
in classAbstractDataSource<DFRowData>
- Parameters:
fdo
- thewhose children will be written
- Throws:
FreezeDryingException
-
writeChildData
protected void writeChildData(FreezeDryedObject fdo, HashMap<String,Object> child) throws FreezeDryingException
Description copied from class:AbstractDataSource
Writes the data for a child of the specifiedFreezeDryedObject
.- Specified by:
writeChildData
in classAbstractDataSource<DFRowData>
- Parameters:
fdo
- the parentchild
- the data from the child- Throws:
FreezeDryingException
-
finishChildrenWrite
protected void finishChildrenWrite(FreezeDryedObject fdo)
Description copied from class:AbstractDataSource
Finishes the writing of the children for the specifiedFreezeDryedObject
.- Specified by:
finishChildrenWrite
in classAbstractDataSource<DFRowData>
-
getFields
protected List<String> getFields(String type)
Description copied from class:AbstractDataSource
Retrieves the fields for a specified type. Generally these should be read in and stored during theAbstractDataSource.startTypeRead(Class)
call.- Specified by:
getFields
in classAbstractDataSource<DFRowData>
- Parameters:
type
- the type of theFreezeDryedObject
(fromAbstractDataSource.getType(Class)
).- Returns:
- the list of fields of that type
-
getDelimiter
public char getDelimiter()
-
getPath
public String getPath()
-
-