Class 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 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)
    • 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 as SavotTD.
      SavotTR getTR()
      Gets the last read row as a SavotTR object.
      boolean next()
      Reads to the next row.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 - The SavotStream 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 - The SavotStream 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 - 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.
        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 or null).
        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

        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

      • getRow

        public java.lang.Object[] getRow()
                                  throws java.lang.IllegalStateException
        Description copied from interface: SavotDataReader
        Gets the last read row.
        Specified by:
        getRow in interface SavotDataReader
        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 a SavotTR object.
        Specified by:
        getTR in interface SavotDataReader
        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 interface SavotDataReader
        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 interface SavotDataReader
        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 as SavotTD.
        Specified by:
        getTD in interface SavotDataReader
        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 interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException