Class PofBufferReader.UserTypeReader

  • All Implemented Interfaces:
    PofConstants, PofReader
    Enclosing class:
    PofBufferReader

    public static class PofBufferReader.UserTypeReader
    extends PofBufferReader
    The UserTypeReader implementation is a contextually-aware PofReader whose purpose is to advance through the properties of a value of a specified user type. The "contextual awareness" refers to the fact that the UserTypeReader maintains state about the type identifier and version of the user type, the parser's property index position within the user type value, and a PofContext that may differ from the PofContext that provided the PofSerializer which is using this UserTypeReader to parse a user type.
    • Constructor Detail

      • UserTypeReader

        public UserTypeReader​(ReadBuffer.BufferInput in,
                              PofContext ctx,
                              int nTypeId,
                              int nVersionId)
                       throws IOException
        Construct a parser for parsing the property values of a user type.
        Parameters:
        in - the BufferInput that contains the user type data, except for the user type id itself (which is passed passed as a constructor argument)
        ctx - the PofContext to use for parsing the user type property values within the user type that this parser will be parsing
        nTypeId - the type id of the user type
        nVersionId - the version id of the user type
        Throws:
        IOException - if an I/O error occurs
      • UserTypeReader

        public UserTypeReader​(PofBufferReader parent,
                              ReadBuffer.BufferInput in,
                              PofContext ctx,
                              int nTypeId,
                              int nVersionId)
                       throws IOException
        Construct a parser for parsing the property values of a user type.
        Parameters:
        parent - the parent (ie the containing) PofBufferReader
        in - the BufferInput that contains the user type data, except for the user type id itself (which is passed passed as a constructor argument)
        ctx - the PofContext to use for parsing the user type property values within the user type that this parser will be parsing
        nTypeId - the type id of the user type
        nVersionId - the version id of the user type
        Throws:
        IOException - if an I/O error occurs
    • Method Detail

      • getUserTypeId

        public int getUserTypeId()
        Determine the user type that is currently being parsed.
        Specified by:
        getUserTypeId in interface PofReader
        Overrides:
        getUserTypeId in class PofBufferReader
        Returns:
        the user type information, or -1 if the PofReader is not currently parsing a user type
      • getVersionId

        public int getVersionId()
        Determine the version identifier of the user type that is currently being parsed.
        Specified by:
        getVersionId in interface PofReader
        Overrides:
        getVersionId in class PofBufferReader
        Returns:
        the integer version ID read from the POF stream; always non-negative
      • registerIdentity

        public void registerIdentity​(Object o)
        Register an identity for a newly created user type instance.

        If identity/reference types are enabled, an identity is used to uniquely identify a user type instance within a POF stream. The identity immediately proceeds the instance value in the POF stream and can be used later in the stream to reference the instance.

        PofSerializer implementations must call this method with the user type instance instantiated during deserialization prior to reading any properties of the instance which are user type instances themselves.

        Specified by:
        registerIdentity in interface PofReader
        Overrides:
        registerIdentity in class PofBufferReader
        Parameters:
        o - the object to register the identity for
        See Also:
        PofSerializer.deserialize(PofReader)
      • createNestedPofReader

        public PofReader createNestedPofReader​(int iProp)
                                        throws IOException
        Obtain a PofReader that can be used to read a set of properties from a single property of the current user type. The returned PofReader is only valid from the time that it is returned until the next call is made to this PofReader.
        Specified by:
        createNestedPofReader in interface PofReader
        Overrides:
        createNestedPofReader in class PofBufferReader
        Parameters:
        iProp - the property index to read from
        Returns:
        a PofReader that reads its contents from a single property of this PofReader
        Throws:
        IOException - if an I/O error occurs
      • readRemainder

        public Binary readRemainder()
                             throws IOException
        Read all remaining indexed properties of the current user type from the POF stream. As part of reading in a user type, this method must be called by the PofSerializer that is reading the user type, or the read position within the POF stream will be corrupted.

        Subsequent calls to the various readXYZ methods of this interface will fail after this method is called.

        Specified by:
        readRemainder in interface PofReader
        Overrides:
        readRemainder in class PofBufferReader
        Returns:
        a Binary object containing zero or more indexed properties in binary POF encoded form
        Throws:
        IOException - if an I/O error occurs
      • getPreviousPropertyIndex

        public int getPreviousPropertyIndex()
        Return the index of the most recent property read or (if it were missing) requested.
        Returns:
        the index of the most recent property read
      • getNextPropertyIndex

        public int getNextPropertyIndex()
                                 throws IOException
        Return the index of the next property in the POF stream.
        Returns:
        the index of the next property in the POF stream
        Throws:
        IOException - if an I/O error occurs
      • advanceTo

        protected boolean advanceTo​(int iProp)
                             throws IOException
        Advance through the POF stream until the specified property is found. If the property is found, return true, otherwise return false and advance to the first property that follows the specified property.
        Overrides:
        advanceTo in class PofBufferReader
        Parameters:
        iProp - the index of the property to advance to
        Returns:
        true if the property is found
        Throws:
        IOException - if an I/O error occurs
      • complete

        protected void complete​(int iProp)
                         throws IOException
        Register the completion of the parsing of a value.
        Overrides:
        complete in class PofBufferReader
        Parameters:
        iProp - the property index
        Throws:
        IOException - if an I/O error occurs
      • closeNested

        protected void closeNested()
                            throws IOException
        Notify the UserTypeReader that it is being "closed".
        Throws:
        IOException - if an I/O error occurs
      • getParentParser

        protected PofBufferReader getParentParser()
        If this parser is contextually within a user type, obtain the parser which created this parser in order to parse the user type.
        Overrides:
        getParentParser in class PofBufferReader
        Returns:
        the parser for the context within which this parser is operating