Class DataBinaryReader
- All Implemented Interfaces:
SavotDataReader
,Closeable
,AutoCloseable
Lets read binary data (that is to say: a votable.resource.table.data.binary node).
A DataBinaryReader must be initialized with a SavotStream
object which contains all information to access and read the data,
and with a FieldSet
which lists all fields (or cells) that are expected in the data.
A SavotStream
has several attributes that are more or less managed by a DataBinaryReader:
- href: path to the resource which contains the binary data. This attribute is fully MANAGED !
- encoding: it specifies how binary data have been encoded. This attribute is MANAGED WITH the value "base64", "gzip" and "dynamic" !
- expires: data expiration date. After this date, data are supposed to be not valid any more. This attribute is fully MANAGED and can be ignored on demand !
- rights: it expresses authentication information (i.e. password). This attribute is NOT MANAGED !
- actuate: it indicates when data have to be fetched (onRequest (by default) or onLoad). This attribute is NOT MANAGED !
HREF attribute
The following protocols are accepted in the "href" attribute: http, https, httpg (not tested at all), ftp and file. If the "href" attribute contains a relative path to a local file, the parent directory must be specified to the reader.
Encoding attribute
The following STREAM encoding are managed: base64, gzip, dynamic. If no encoding is specified, the data will be merely considered as just binary data.
The "dynamic" encoding implies that the data is in a remote resource (specified by the "href" attribute), and the encoding will be delivered with the header of the data. This occurs with the http protocol, where the MIME header (http header field "Content-Encoding") indicates the type of encoding that has been used. In this case only base64 and gzip are accepted.
Expires attribute
If the date given by this attribute has been reached, no data will be read and an IOException
will be thrown.
However, this attribute can be ignored at the creation of a DataBinaryReader if needed.
- Since:
- 09/2011
- Author:
- Gregory Mantelet (CDS)
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
DataBinaryReader
(FieldSet fields) Builds one binary decoder per field and initializes the variable which aims to contains the read row after anext()
call.DataBinaryReader
(SavotStream stream, FieldSet fields) Builds a DataBinaryReader with aSavotStream
.DataBinaryReader
(SavotStream stream, FieldSet fields, boolean ignoreExpiryDate) Builds a DataBinaryReader with aSavotStream
.DataBinaryReader
(SavotStream stream, FieldSet fields, boolean ignoreExpiryDate, String parentDirectory) Builds a DataBinaryReader with aSavotStream
.DataBinaryReader
(InputStream decodedData, FieldSet fields) Builds a DataBinaryReader with anInputStream
on the DECODED data.DataBinaryReader
(InputStream encodedData, String encoding, FieldSet fields) Builds a DataBinaryReader with anInputStream
on the ENCODED data. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
getCell
(int indColumn) Gets the specified cell of the last read row.getCellAsString
(int indColumn) Gets the specified cell of the last read row as a String.Object[]
getRow()
Gets the last read row.getTD
(int indColumn) Gets the specified cell of the last read row asSavotTD
.getTR()
Gets the last read row as aSavotTR
object.boolean
next()
Reads to the next row.
-
Constructor Details
-
DataBinaryReader
Builds a DataBinaryReader with a
SavotStream
.NOTE: The expiration date is NOT ignored and there is no parent directory.
- Parameters:
stream
- TheSavotStream
which contains data to read.fields
- List of fields metadata (one per cell).- Throws:
IOException
- If an error occurs while building the input stream.- See Also:
-
DataBinaryReader
public DataBinaryReader(SavotStream stream, FieldSet fields, boolean ignoreExpiryDate) throws IOException Builds a DataBinaryReader with a
SavotStream
.NOTE: There is no parent directory.
- Parameters:
stream
- TheSavotStream
which contains data to read.fields
- List of fields metadata (one per cell).ignoreExpiryDate
- true to ignore the "expires" attribute, false otherwise.- Throws:
IOException
- If an error occurs while building the input stream.- See Also:
-
DataBinaryReader
public DataBinaryReader(SavotStream stream, FieldSet fields, boolean ignoreExpiryDate, String parentDirectory) throws IOException Builds a DataBinaryReader with a
SavotStream
.- Parameters:
stream
- TheSavotStream
which contains data to read.fields
- List of fields metadata (one per cell).ignoreExpiryDate
- true to ignore the "expires" attribute, false otherwise.parentDirectory
- Directory which contains the data file if the path given in the "href" attribute is relative.- Throws:
IOException
- If an error occurs while building the input stream.- See Also:
-
DataBinaryReader
public DataBinaryReader(InputStream encodedData, String encoding, FieldSet fields) throws IOException Builds a DataBinaryReader with an
InputStream
on the ENCODED data.- Parameters:
encodedData
- Encoded data.encoding
- Encoding of the data (base64, gzip ornull
).fields
- List of fields metadata (one per cell).- Throws:
IOException
- If an error occurs while building the input stream.- See Also:
-
DataBinaryReader
Builds a DataBinaryReader with an
InputStream
on the DECODED data.- Parameters:
decodedData
- Decoded data.fields
- List of fields metadata (one per cell).- Throws:
BinaryInterpreterException
- If it is impossible to build a field decoder.- See Also:
-
DataBinaryReader
Builds one binary decoder per field and initializes the variable which aims to contains the read row after a
next()
call.WARNING: The
data
attribute is not initialized ! This constructor is just designed to initialize the decoders list. Thus it must be called by another constructor which will be able to initialize the data input stream.- Parameters:
fields
- List of fields metadata (one per cell).- Throws:
BinaryInterpreterException
- It it is impossible to build a field decoder.- See Also:
-
-
Method Details
-
next
Description copied from interface:SavotDataReader
Reads to the next row.
Once this function called, you can get the full row with
SavotDataReader.getRow()
orSavotDataReader.getTR()
, or get specific cells withSavotDataReader.getCell(int)
,SavotDataReader.getCellAsString(int)
orSavotDataReader.getTD(int)
.- Specified by:
next
in interfaceSavotDataReader
- Returns:
- true if the next row has been successfully fetched, false otherwise.
- Throws:
IOException
-
getRow
Description copied from interface:SavotDataReader
Gets the last read row.- Specified by:
getRow
in interfaceSavotDataReader
- Returns:
- an Object
- Throws:
IllegalStateException
-
getTR
Description copied from interface:SavotDataReader
Gets the last read row as aSavotTR
object.- Specified by:
getTR
in interfaceSavotDataReader
- Returns:
- a SAVOT TR internal model object
- Throws:
IllegalStateException
-
getCell
Description copied from interface:SavotDataReader
Gets the specified cell of the last read row.- Specified by:
getCell
in interfaceSavotDataReader
- Parameters:
indColumn
-- Returns:
- Object
- Throws:
IndexOutOfBoundsException
IllegalStateException
-
getCellAsString
public String getCellAsString(int indColumn) throws IndexOutOfBoundsException, IllegalStateException Description copied from interface:SavotDataReader
Gets the specified cell of the last read row as a String.- Specified by:
getCellAsString
in interfaceSavotDataReader
- Parameters:
indColumn
-- Returns:
- String
- Throws:
IndexOutOfBoundsException
IllegalStateException
-
getTD
Description copied from interface:SavotDataReader
Gets the specified cell of the last read row asSavotTD
.- Specified by:
getTD
in interfaceSavotDataReader
- Parameters:
indColumn
-- Returns:
- SavotTD SAVOT TD internal model object
- Throws:
IndexOutOfBoundsException
IllegalStateException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-