Package gov.nasa.pds.objectAccess
Class TableReader
- java.lang.Object
-
- gov.nasa.pds.objectAccess.TableReader
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
RawTableReader
public class TableReader extends java.lang.Object implements java.io.CloseableTheTableReaderclass defines methods for reading table records.
-
-
Field Summary
Fields Modifier and Type Field Description protected ByteWiseFileAccessoraccessorprotected DataObjectLocationdataObjectLocation
-
Constructor Summary
Constructors Constructor Description TableReader(java.lang.Object table, java.io.File dataFile)TableReader(java.lang.Object table, java.net.URL dataFile)Constructs aTableReaderinstance for reading records from a data file associated with a table object.TableReader(java.lang.Object table, java.net.URL dataFile, boolean checkSize)TableReader(java.lang.Object table, java.net.URL dataFile, boolean checkSize, boolean readEntireFile)TableReader(java.lang.Object table, java.net.URL dataFile, DataObjectLocation location, boolean checkSize, boolean readEntireFile, boolean keepQuotationsFlag)TableReader(java.lang.Object table, java.net.URL dataFile, DataObjectLocation location, boolean checkSize, boolean readEntireFile, boolean keepQuotationsFlag, java.io.RandomAccessFile raf, java.io.InputStream inputStream)Constructs aTableReaderinstance for reading records from a data file associated with a table object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()ByteWiseFileAccessorgetAccessor()TableAdaptergetAdapter()longgetCurrentRow()DataObjectLocationgetDataObjectLocation()java.util.Map<java.lang.String,java.lang.Integer>getFieldMap()FieldDescription[]getFields()Gets the field descriptions for fields in the table.java.io.InputStreamgetInputStream()longgetOffset()TableRecordgetRecord(int index)Gets access to the table record given the index.TableRecordgetRecord(long index, boolean keepQuotationsFlag)Gets access to the table record given the index.longgetRecordSize(java.net.URL dataFile, java.lang.Object table)TableRecordreadNext()Reads the next record from the data file.voidsetCurrentRow(int row)Sets the current row.voidsetCurrentRow(long row)Sets the current row.voidsetDataObjectLocation(DataObjectLocation dataObjectLocation)
-
-
-
Field Detail
-
accessor
protected ByteWiseFileAccessor accessor
-
dataObjectLocation
protected DataObjectLocation dataObjectLocation
-
-
Constructor Detail
-
TableReader
public TableReader(java.lang.Object table, java.io.File dataFile) throws java.lang.Exception- Throws:
java.lang.Exception
-
TableReader
public TableReader(java.lang.Object table, java.net.URL dataFile) throws java.lang.ExceptionConstructs aTableReaderinstance for reading records from a data file associated with a table object.- Parameters:
table- a table objectdataFile- an input data file- Throws:
java.lang.NullPointerException- if table offset is nulljava.lang.Exception
-
TableReader
public TableReader(java.lang.Object table, java.net.URL dataFile, boolean checkSize) throws InvalidTableException, java.lang.Exception- Throws:
InvalidTableExceptionjava.lang.Exception
-
TableReader
public TableReader(java.lang.Object table, java.net.URL dataFile, boolean checkSize, boolean readEntireFile) throws InvalidTableException, java.lang.Exception- Throws:
InvalidTableExceptionjava.lang.Exception
-
TableReader
public TableReader(java.lang.Object table, java.net.URL dataFile, DataObjectLocation location, boolean checkSize, boolean readEntireFile, boolean keepQuotationsFlag) throws InvalidTableException, java.lang.Exception- Throws:
InvalidTableExceptionjava.lang.Exception
-
TableReader
public TableReader(java.lang.Object table, java.net.URL dataFile, DataObjectLocation location, boolean checkSize, boolean readEntireFile, boolean keepQuotationsFlag, java.io.RandomAccessFile raf, java.io.InputStream inputStream) throws InvalidTableException, java.lang.ExceptionConstructs aTableReaderinstance for reading records from a data file associated with a table object.- Parameters:
table- a table objectdataFile- an input data filecheckSize- check that the size of the data file is equal to the size of the table (length * records) + offset.readEntireFile- flag to read an entire filekeepQuotationsFlag- flag to keep the starting/ending quotes- Throws:
java.lang.NullPointerException- if table offset is nullInvalidTableExceptionjava.lang.Exception
-
-
Method Detail
-
getAdapter
public TableAdapter getAdapter()
-
getFields
public FieldDescription[] getFields()
Gets the field descriptions for fields in the table.- Returns:
- an array of field descriptions
-
getFieldMap
public java.util.Map<java.lang.String,java.lang.Integer> getFieldMap()
- Returns:
- the field map.
-
readNext
public TableRecord readNext() throws java.io.IOException, com.opencsv.exceptions.CsvValidationException
Reads the next record from the data file.- Returns:
- the next record, or null if no further records.
- Throws:
com.opencsv.exceptions.CsvValidationExceptionjava.io.IOException
-
getRecord
public TableRecord getRecord(int index) throws java.lang.IllegalArgumentException, java.io.IOException, com.opencsv.exceptions.CsvValidationException
Gets access to the table record given the index. The current row is set to this index, thus, subsequent call to readNext() gets the next record from this position.- Parameters:
index- the record index (1-relative)- Returns:
- an instance of
TableRecord - Throws:
java.lang.IllegalArgumentException- if index is greater than the record numbercom.opencsv.exceptions.CsvValidationExceptionjava.io.IOException
-
getRecord
public TableRecord getRecord(long index, boolean keepQuotationsFlag) throws java.lang.IllegalArgumentException, java.io.IOException, com.opencsv.exceptions.CsvValidationException
Gets access to the table record given the index. The current row is set to this index, thus, subsequent call to readNext() gets the next record from this position.- Parameters:
index- the record index (1-relative)keepQuotationsFlag- flag to keep the starting/ending quotes or not.- Returns:
- an instance of
TableRecord - Throws:
java.lang.IllegalArgumentException- if index is greater than the record numbercom.opencsv.exceptions.CsvValidationExceptionjava.io.IOException
-
setCurrentRow
public void setCurrentRow(int row)
Sets the current row.- Parameters:
row- The row to set.
-
setCurrentRow
public void setCurrentRow(long row)
Sets the current row.- Parameters:
row- The row to set.
-
getCurrentRow
public long getCurrentRow()
- Returns:
- the current row.
-
getAccessor
public ByteWiseFileAccessor getAccessor()
-
getInputStream
public java.io.InputStream getInputStream()
-
getRecordSize
public long getRecordSize(java.net.URL dataFile, java.lang.Object table) throws java.lang.Exception- Returns:
- the size of record (i.e. number of lines)
- Throws:
java.lang.Exception
-
getOffset
public long getOffset()
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
getDataObjectLocation
public DataObjectLocation getDataObjectLocation()
-
setDataObjectLocation
public void setDataObjectLocation(DataObjectLocation dataObjectLocation)
-
-