Class ADEPT2UDTValue

  • All Implemented Interfaces:
    UDTValue, Serializable
    Direct Known Subclasses:
    FileUDTValue, JsonUdtValue

    public class ADEPT2UDTValue
    extends Object
    implements UDTValue
    This class provides a lightweight implementation for a user-defined data type (UDT). It encapsulates the value as a byte-array and provides the necessary logic for serialisation. To prevent external modifications, the byte array is cloned before it is stored or returned.
    This implementation supports laziness: the data is not read from the input stream unless needed. However, unless just retrieving the stream, all other methods require the data. This includes serialising this value, comparing and even determining the hash code.
    See Also:
    Serialized Form
    • Field Detail

      • userDefinedTypeName

        protected String userDefinedTypeName
        The name of the user-defined type.
      • value

        protected byte[] value
        The value of this UDTValue as byte array. This is null in case an input stream for lazy retrieval has been provided and retrieval has not occurred yet.
      • stream

        protected InputStream stream
        The input stream providing the data as long as the data has not been read from the stream. Afterwards this is set to null.
    • Constructor Detail

      • ADEPT2UDTValue

        public ADEPT2UDTValue​(String userDefinedType,
                              byte[] value)
        Creates a new UDTValue with the designated name and the designated value (byte array).
        Parameters:
        userDefinedType - The name of the user-defined type of the value. the name of the user defined type
        value - The bytes representing the value of this UDTValue. Please take care of the encoding.
      • ADEPT2UDTValue

        public ADEPT2UDTValue​(String userDefinedType,
                              InputStream stream)
        Creates a new UDTValue with the designated name and the designated value (input stream). The content of the designated stream will be completely read. Note that the stream will be closed by this constructor!
        Parameters:
        userDefinedType - The name of the user-defined type of the value. the name of the user defined type
        stream - The input stream containing the value of this UDTValue. Please take care of the encoding. The stream will be closed after the creation.
      • ADEPT2UDTValue

        public ADEPT2UDTValue​(String userDefinedType,
                              InputStream stream,
                              boolean eager)
        Creates a new UDTValue with the designated name and the designated value (input stream). The content of the designated stream may be read now or lazy, that is as soon as required. Note that the stream will be closed after reading!
        Use the laziness of this constructor only, if you are really knowing, what you are doing. The stream must not be changed and it must not be closed from outside. Additionally, it cannot be determined when the stream is closed!
        Parameters:
        userDefinedType - The name of the user-defined type of the value. the name of the user defined type
        stream - The input stream containing the value of this UDTValue. Please take care of the encoding.
        eager - Whether the data should be read from the stream now or lazily.
      • ADEPT2UDTValue

        public ADEPT2UDTValue​(String userDefinedType,
                              InputStream stream,
                              int length)
        Creates a new UDTValue with the designated name and the designated value (input stream). The content of the designated stream will be read by the designated length eagerly. If the stream contains more content, the remaining content will be ignored. Note that the stream will not be closed!
        Parameters:
        userDefinedType - The name of the user-defined type of the value. the name of the user defined type
        stream - The input stream containing the value of this UDTValue. Please take care of the encoding. The stream will not be closed after the creation.
        length - The number of bytes to be read from the designated input stream.
        Throws:
        IllegalArgumentException - If the designated number of bytes cannot be read from the stream, an IllegalArgumentException will be thrown.
    • Method Detail

      • getUserDefinedType

        public String getUserDefinedType()
        Description copied from interface: UDTValue
        Gets the name (a string) of the user-defined type of this value.
        Specified by:
        getUserDefinedType in interface UDTValue
        Returns:
        The name of the user-defined data type of this value.
      • getValueAsStream

        public InputStream getValueAsStream()
        Description copied from interface: UDTValue
        Gets the value as an InputStream of this user-defined data type.
        Specified by:
        getValueAsStream in interface UDTValue
        Returns:
        The value of a (this) user-defined data type as an InputStream.
      • getValueAsArray

        public byte[] getValueAsArray()
        Description copied from interface: UDTValue
        Gets the value as a byte array of this user-defined data type.
        Specified by:
        getValueAsArray in interface UDTValue
        Returns:
        The value of a (this) user-defined data type as an array of bytes.
      • readStream

        protected void readStream()
        Reads all the data provided by the stream if not done yet. This needs to be called before the value can be accessed as byte array.
        Note that this method is called from the constructor when eagerly loading! userDefinedTypeName and stream will be set but no other field.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • finalize

        protected void finalize()
                         throws IOException
        Closes the input stream if the stream still exists and thus the data has not been read yet.
        Overrides:
        finalize in class Object
        Throws:
        IOException