Class ADEPT2UDTValue

java.lang.Object
de.aristaflow.adept2.model.datamanagement.ADEPT2UDTValue
All Implemented Interfaces:
UDTValue, TypedCloneable<ADEPT2UDTValue>, Closeable, Serializable, AutoCloseable, Cloneable
Direct Known Subclasses:
FileUDTValue, JsonUdtValue

public class ADEPT2UDTValue extends Object implements UDTValue, TypedCloneable<ADEPT2UDTValue>
This class provides a lightweight implementation for a user-defined data type (UDT). It encapsulates the value as a RereadableContent and provides the necessary logic for serialisation. The usage of RereadableContent allows to close() this UDTValue while continue to use the created streams. Obviously, after closing this UDTValue you cannot create new streams any more.
This implementation reads the complete data at creation time. It then resides either in memory or in a file. Equality is based on a SHA-512 hash and not on the content itself.

Note that a closed ADEPT2UDTValue cannot be serialised.

See Also:
  • Field Details

    • userDefinedTypeName

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

      protected org.apache.commons.lang3.mutable.Mutable<RereadableContent> data
      The value of this UDTValue as RereadableContent. This is always completely initialised.
      The field will be serialised as byte[].
    • cleanup

      protected transient Cleanup<IOException> cleanup
      The clean-up called after as post-mortem action of this ADEPT2UDTValue. Since this is the same logic, it is also used by close().
  • Constructor Details

    • ADEPT2UDTValue

      @Deprecated(since="15.0.0", forRemoval=true) public ADEPT2UDTValue(String userDefinedType, byte[] value)
      Deprecated, for removal: This API element is subject to removal in a future version.
      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.
      value - The bytes representing the value of this UDTValue. Please take care of the encoding.
    • ADEPT2UDTValue

      public ADEPT2UDTValue(byte[] value, String userDefinedType) throws IOException
      Creates a new UDTValue with the designated name and the designated value (byte array).
      Parameters:
      value - The bytes representing the value of this UDTValue. Please take care of the encoding.
      userDefinedType - The name of the user-defined type of the value.
      Throws:
      IOException - If there are problems creating the data structures for the content or the hash within the RereadableContent, an IOException will be thrown.
    • ADEPT2UDTValue

      @Deprecated(since="15.0.0", forRemoval=true) public ADEPT2UDTValue(String userDefinedType, InputStream stream)
      Deprecated, for removal: This API element is subject to removal in a future version.
      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.
      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(InputStream stream, String userDefinedType) throws IOException
      Creates a new UDTValue with the designated name and the designated value (input stream). Note that the stream will be closed by this constructor!
      Parameters:
      stream - The input stream containing the value of this UDTValue. Please take care of the encoding. The stream will be closed after the creation.
      userDefinedType - The name of the user-defined type of the value.
      Throws:
      IOException - If there are problems creating the data structures for the content or the hash within the RereadableContent, an IOException will be thrown.
    • ADEPT2UDTValue

      public ADEPT2UDTValue(InputStream stream, long size, String userDefinedType) throws IOException
      Creates a new UDTValue with the designated name and the designated value (input stream) having the designated size. Note that the stream will be closed by this constructor!
      Parameters:
      stream - The input stream containing the value of this UDTValue. Please take care of the encoding. The stream will be closed after the creation.
      size - The estimated size of (the contents of) the created stream. Use a negative value if the size is unknown.
      userDefinedType - The name of the user-defined type of the value.
      Throws:
      IOException - If there are problems creating the data structures for the content or the hash within the RereadableContent, an IOException will be thrown.
    • ADEPT2UDTValue

      public ADEPT2UDTValue(UDTValue udt) throws IOException
      Creates a new UDTValue with the properties and the content of the designated UDTValue.
      You can also clone() an ADEPT2UDTValue. This works similar to this constructor but wraps the IOexception in an UncheckedIOException.
      Parameters:
      udt - The UDTValue which to clone. The caller is responsible for closing.
      Throws:
      IOException - If there are problems creating the data structures for the content or the hash within the RereadableContent, an IOException will be thrown.
    • ADEPT2UDTValue

      @Deprecated(since="15.0.0", forRemoval=true) public ADEPT2UDTValue(String userDefinedType, InputStream stream, boolean eager)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Creates a new UDTValue with the designated name and the designated value (input stream). Note that the stream will be closed by this constructor!
      No laziness is supported any more, the complete data will be read immediately.
      Parameters:
      userDefinedType - The name of the user-defined type of the value.
      stream - The input stream containing the value of this UDTValue. Please take care of the encoding. The stream will be closed after the creation.
      eager - Ignored.
    • ADEPT2UDTValue

      @Deprecated(since="15.0.0", forRemoval=true) public ADEPT2UDTValue(String userDefinedType, InputStream stream, int length)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use ADEPT2UDTValue(byte[], String) with a BoundedInputStream instead.
      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.
      stream - The input stream containing the value of this UDTValue. Please take care of the encoding. The stream will 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 Details

    • 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 AttributedInputStream getValueAsStream()
      Description copied from interface: UDTValue
      Gets the value as an InputStream of this user-defined data type.
      You have to close the stream after usage.
      Specified by:
      getValueAsStream in interface UDTValue
      Returns:
      The value of a (this) user-defined data type as an InputStream. The caller is responsible for closing.
    • getInputStream

      public AttributedInputStream getInputStream() throws IOException
      Gets the value as an InputStream of this user-defined data type.
      You have to close the stream after usage. Usually you should not UDTValue.close() this UDTValue before all created input streams have been consumed. Implementations may deviate so that closing the UDTValue does not affect the created input streams. closing will not affect the InputStream.
      Specified by:
      getInputStream in interface UDTValue
      Returns:
      The value of a (this) user-defined data type as an InputStream. The caller is responsible for closing.
      Throws:
      IOException - If there are problems creating a corresponding InputStream, an IOException will be thrown.
    • 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.
    • getSize

      public Long getSize()
      Description copied from interface: UDTValue
      Gets the size of this UDT value if it is known. For instance, if the content stems from a stream and the stream is not read yet, the size cannot be determined and null will be returned.
      Specified by:
      getSize in interface UDTValue
      Returns:
      The size of the content of this UDT value, null if the content is not known yet, for instance, it has not been read from the input stream yet.
    • getBytes

      public byte[] getBytes() throws IOException
      Description copied from interface: UDTValue
      Gets the value as a byte array of this user-defined data type.
      Specified by:
      getBytes in interface UDTValue
      Returns:
      The value of a (this) user-defined data type as an array of bytes.
      Throws:
      IOException - If there are problems retrieving the corresponding array, e. g the length of the data exceeds the maximum length of an array, an IOException will be thrown.
    • clone

      public ADEPT2UDTValue clone()
      Description copied from interface: UDTValue
      Clones this UDTValue in case it is Cloneable, otherwise a CloneNotSupportedException will be thrown (which is what this default implementation does). Subclasses should provide a corresponding implementation and also extend Cloneable. Those which do not, should forward to this default implementation.
      Specified by:
      clone in interface TypedCloneable<ADEPT2UDTValue>
      Specified by:
      clone in interface UDTValue
      Overrides:
      clone in class Object
      Returns:
      A clone of this UDTValue instance.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

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

      public void close() throws IOException
      Closes the rereadable content and thus all created input streams (if not closed yet).
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface UDTValue
      Throws:
      IOException
    • clone

      public static UDTValue clone(UDTValue udt, boolean forceRecreation) throws IOException
      Clones or recreates the designated UDTValue depending on the designated recreate and whether ccloning is supported. If recreate or cloning is not supported or fails, the designated UDTValue will be recreated as new instance of ADEPT2UDTValue.
      Parameters:
      udt - The UDTValue which to clone or recreate. This may be null.
      forceRecreation - Whether recreating as ADEPT2UDTValue should be enforced. Otherwise cloning will be preferred with a fallback to recreation in case of failure.
      Returns:
      A clone or recreation of the designated UDTValue or null.
      Throws:
      IOException - If there are problems creating a new ADEPT2UDTValue (may be a consequence of unsuccessful cloning), the corresponding IOException will be thrown.
    • cloneUnchecked

      public static UDTValue cloneUnchecked(UDTValue udt, boolean forceRecreation)
      Clones or recreates the designated UDTValue depending on the designated recreate and whether ccloning is supported. If recreate or cloning is not supported or fails, the designated UDTValue will be recreated as new instance of ADEPT2UDTValue.
      Parameters:
      udt - The UDTValue which to clone or recreate. This may be null.
      forceRecreation - Whether recreating as ADEPT2UDTValue should be enforced. Otherwise cloning will be preferred with a fallback to recreation in case of failure.
      Returns:
      A clone or recreation of the designated UDTValue or null.
      Throws:
      UncheckedIOException - If there are problems creating a new ADEPT2UDTValue (may be a consequence of unsuccessful cloning), the corresponding IOException will be wrapped with an UncheckedIOException and re-thrown.