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.Closeable
TheTableReader
class defines methods for reading table records.
-
-
Field Summary
Fields Modifier and Type Field Description protected ByteWiseFileAccessor
accessor
protected DataObjectLocation
dataObjectLocation
-
Constructor Summary
Constructors Constructor Description TableReader(java.lang.Object table, java.io.File dataFile)
TableReader(java.lang.Object table, java.net.URL dataFile)
Constructs aTableReader
instance 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 aTableReader
instance 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 void
close()
ByteWiseFileAccessor
getAccessor()
TableAdapter
getAdapter()
long
getCurrentRow()
DataObjectLocation
getDataObjectLocation()
java.util.Map<java.lang.String,java.lang.Integer>
getFieldMap()
FieldDescription[]
getFields()
Gets the field descriptions for fields in the table.java.io.InputStream
getInputStream()
long
getOffset()
TableRecord
getRecord(int index)
Gets access to the table record given the index.TableRecord
getRecord(long index, boolean keepQuotationsFlag)
Gets access to the table record given the index.long
getRecordSize(java.net.URL dataFile, java.lang.Object table)
TableRecord
readNext()
Reads the next record from the data file.void
setCurrentRow(int row)
Sets the current row.void
setCurrentRow(long row)
Sets the current row.void
setDataObjectLocation(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.Exception
Constructs aTableReader
instance 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:
InvalidTableException
java.lang.Exception
-
TableReader
public TableReader(java.lang.Object table, java.net.URL dataFile, boolean checkSize, boolean readEntireFile) throws InvalidTableException, java.lang.Exception
- Throws:
InvalidTableException
java.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:
InvalidTableException
java.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.Exception
Constructs aTableReader
instance 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 nullInvalidTableException
java.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.CsvValidationException
java.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.CsvValidationException
java.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.CsvValidationException
java.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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
getDataObjectLocation
public DataObjectLocation getDataObjectLocation()
-
setDataObjectLocation
public void setDataObjectLocation(DataObjectLocation dataObjectLocation)
-
-