Class DataBinaryReader
- java.lang.Object
-
- cds.savot.binary.DataBinaryReader
-
- All Implemented Interfaces:
SavotDataReader
,java.io.Closeable
,java.lang.AutoCloseable
public final class DataBinaryReader extends java.lang.Object implements SavotDataReader
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 aFieldSet
which lists all fields (or cells) that are expected in the data. ASavotStream
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
Constructors Modifier Constructor Description protected
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, java.lang.String parentDirectory)
Builds a DataBinaryReader with aSavotStream
.DataBinaryReader(java.io.InputStream decodedData, FieldSet fields)
Builds a DataBinaryReader with anInputStream
on the DECODED data.DataBinaryReader(java.io.InputStream encodedData, java.lang.String encoding, FieldSet fields)
Builds a DataBinaryReader with anInputStream
on the ENCODED data.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
java.lang.Object
getCell(int indColumn)
Gets the specified cell of the last read row.java.lang.String
getCellAsString(int indColumn)
Gets the specified cell of the last read row as a String.java.lang.Object[]
getRow()
Gets the last read row.SavotTD
getTD(int indColumn)
Gets the specified cell of the last read row asSavotTD
.SavotTR
getTR()
Gets the last read row as aSavotTR
object.boolean
next()
Reads to the next row.
-
-
-
Constructor Detail
-
DataBinaryReader
public DataBinaryReader(SavotStream stream, FieldSet fields) throws java.io.IOException
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:
java.io.IOException
- If an error occurs while building the input stream.- See Also:
DataBinaryReader(SavotStream, FieldSet, boolean, String)
-
DataBinaryReader
public DataBinaryReader(SavotStream stream, FieldSet fields, boolean ignoreExpiryDate) throws java.io.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:
java.io.IOException
- If an error occurs while building the input stream.- See Also:
DataBinaryReader(SavotStream, FieldSet, boolean, String)
-
DataBinaryReader
public DataBinaryReader(SavotStream stream, FieldSet fields, boolean ignoreExpiryDate, java.lang.String parentDirectory) throws java.io.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:
java.io.IOException
- If an error occurs while building the input stream.- See Also:
DataBinaryReader(FieldSet)
,getData(SavotStream, boolean, String)
-
DataBinaryReader
public DataBinaryReader(java.io.InputStream encodedData, java.lang.String encoding, FieldSet fields) throws java.io.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:
java.io.IOException
- If an error occurs while building the input stream.- See Also:
DataBinaryReader(FieldSet)
,getDecodedStream(InputStream, String)
-
DataBinaryReader
public DataBinaryReader(java.io.InputStream decodedData, FieldSet fields) throws BinaryInterpreterException
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(FieldSet)
-
DataBinaryReader
protected DataBinaryReader(FieldSet fields) throws BinaryInterpreterException
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:
BinaryFieldInterpreter.createInterpreter(SavotField)
-
-
Method Detail
-
next
public boolean next() throws java.io.IOException
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:
java.io.IOException
-
getRow
public java.lang.Object[] getRow() throws java.lang.IllegalStateException
Description copied from interface:SavotDataReader
Gets the last read row.- Specified by:
getRow
in interfaceSavotDataReader
- Returns:
- an Object
- Throws:
java.lang.IllegalStateException
-
getTR
public SavotTR getTR() throws java.lang.IllegalStateException
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:
java.lang.IllegalStateException
-
getCell
public java.lang.Object getCell(int indColumn) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalStateException
Description copied from interface:SavotDataReader
Gets the specified cell of the last read row.- Specified by:
getCell
in interfaceSavotDataReader
- Parameters:
indColumn
-- Returns:
- Object
- Throws:
java.lang.IndexOutOfBoundsException
java.lang.IllegalStateException
java.lang.ArrayIndexOutOfBoundsException
- If the given index is less than 0 or is greater than the number of available cell.
-
getCellAsString
public java.lang.String getCellAsString(int indColumn) throws java.lang.IndexOutOfBoundsException, java.lang.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:
java.lang.IndexOutOfBoundsException
java.lang.IllegalStateException
java.lang.ArrayIndexOutOfBoundsException
- If the given index is less than 0 or is greater than the number of available cell.
-
getTD
public SavotTD getTD(int indColumn) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalStateException
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:
java.lang.IndexOutOfBoundsException
java.lang.IllegalStateException
java.lang.ArrayIndexOutOfBoundsException
- If the given index is less than 0 or is greater than the number of available cell.
-
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
-
-