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 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:
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.
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.
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.
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 a
next() call. |
|
DataBinaryReader(SavotStream stream,
FieldSet fields) |
Builds a DataBinaryReader with a
SavotStream . |
|
DataBinaryReader(SavotStream stream,
FieldSet fields,
boolean ignoreExpiryDate) |
Builds a DataBinaryReader with a
SavotStream . |
|
DataBinaryReader(SavotStream stream,
FieldSet fields,
boolean ignoreExpiryDate,
java.lang.String parentDirectory) |
Builds a DataBinaryReader with a
SavotStream . |
|
DataBinaryReader(java.io.InputStream decodedData,
FieldSet fields) |
Builds a DataBinaryReader with an
InputStream on the DECODED data. |
|
DataBinaryReader(java.io.InputStream encodedData,
java.lang.String encoding,
FieldSet fields) |
Builds a DataBinaryReader with an
InputStream on the ENCODED data. |
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 as
SavotTD . |
SavotTR |
getTR() |
Gets the last read row as a
SavotTR object. |
boolean |
next() |
Reads to the next row.
|
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.
stream
- The SavotStream
which contains data to read.fields
- List of fields metadata (one per cell).java.io.IOException
- If an error occurs while building the input stream.DataBinaryReader(SavotStream, FieldSet, boolean, String)
public DataBinaryReader(SavotStream stream, FieldSet fields, boolean ignoreExpiryDate) throws java.io.IOException
Builds a DataBinaryReader with a SavotStream
.
NOTE: There is no parent directory.
stream
- The SavotStream
which contains data to read.fields
- List of fields metadata (one per cell).ignoreExpiryDate
- true to ignore the "expires" attribute, false otherwise.java.io.IOException
- If an error occurs while building the input stream.DataBinaryReader(SavotStream, FieldSet, boolean, String)
public DataBinaryReader(SavotStream stream, FieldSet fields, boolean ignoreExpiryDate, java.lang.String parentDirectory) throws java.io.IOException
Builds a DataBinaryReader with a SavotStream
.
stream
- The SavotStream
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.java.io.IOException
- If an error occurs while building the input stream.DataBinaryReader(FieldSet)
,
getData(SavotStream, boolean, String)
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.
encodedData
- Encoded data.encoding
- Encoding of the data (base64, gzip or null
).fields
- List of fields metadata (one per cell).java.io.IOException
- If an error occurs while building the input stream.DataBinaryReader(FieldSet)
,
getDecodedStream(InputStream, String)
public DataBinaryReader(java.io.InputStream decodedData, FieldSet fields) throws BinaryInterpreterException
Builds a DataBinaryReader with an InputStream
on the DECODED data.
decodedData
- Decoded data.fields
- List of fields metadata (one per cell).BinaryInterpreterException
- If it is impossible to build a field decoder.DataBinaryReader(FieldSet)
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.
fields
- List of fields metadata (one per cell).BinaryInterpreterException
- It it is impossible to build a field decoder.BinaryFieldInterpreter.createInterpreter(SavotField)
public boolean next() throws java.io.IOException
SavotDataReader
Reads to the next row.
Once this function called, you can get the full row with SavotDataReader.getRow()
or SavotDataReader.getTR()
,
or get specific cells with SavotDataReader.getCell(int)
, SavotDataReader.getCellAsString(int)
or SavotDataReader.getTD(int)
.
next
in interface SavotDataReader
java.io.IOException
public java.lang.Object[] getRow() throws java.lang.IllegalStateException
SavotDataReader
getRow
in interface SavotDataReader
java.lang.IllegalStateException
public SavotTR getTR() throws java.lang.IllegalStateException
SavotDataReader
SavotTR
object.getTR
in interface SavotDataReader
java.lang.IllegalStateException
public java.lang.Object getCell(int indColumn) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalStateException
SavotDataReader
getCell
in interface SavotDataReader
indColumn
- 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.public java.lang.String getCellAsString(int indColumn) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalStateException
SavotDataReader
getCellAsString
in interface SavotDataReader
indColumn
- 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.public SavotTD getTD(int indColumn) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalStateException
SavotDataReader
SavotTD
.getTD
in interface SavotDataReader
indColumn
- 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.public void close() throws java.io.IOException
close
in interface java.lang.AutoCloseable
close
in interface java.io.Closeable
java.io.IOException