Class ADEPT2UDTValue
- java.lang.Object
-
- de.aristaflow.adept2.model.datamanagement.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 Summary
Fields Modifier and Type Field Description protected InputStream
stream
The input stream providing the data as long as the data has not been read from the stream.protected String
userDefinedTypeName
The name of the user-defined type.protected byte[]
value
The value of this UDTValue as byte array.
-
Constructor Summary
Constructors Constructor Description ADEPT2UDTValue(String userDefinedType, byte[] value)
Creates a new UDTValue with the designated name and the designated value (byte array).ADEPT2UDTValue(String userDefinedType, InputStream stream)
Creates a new UDTValue with the designated name and the designated value (input stream).ADEPT2UDTValue(String userDefinedType, InputStream stream, boolean eager)
Creates a new UDTValue with the designated name and the designated value (input stream).ADEPT2UDTValue(String userDefinedType, InputStream stream, int length)
Creates a new UDTValue with the designated name and the designated value (input stream).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
protected void
finalize()
Closes the input stream if the stream still exists and thus the data has not been read yet.String
getUserDefinedType()
Gets the name (a string) of the user-defined type of this value.byte[]
getValueAsArray()
Gets the value as a byte array of this user-defined data type.InputStream
getValueAsStream()
Gets the value as anInputStream
of this user-defined data type.int
hashCode()
protected void
readStream()
Reads all the data provided by the stream if not done yet.String
toString()
-
-
-
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 isnull
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 tonull
.
-
-
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 typevalue
- The bytes representing the value of thisUDTValue
. 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 typestream
- The input stream containing the value of thisUDTValue
. 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 typestream
- The input stream containing the value of thisUDTValue
. 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 typestream
- The input stream containing the value of thisUDTValue
. 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, anIllegalArgumentException
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 interfaceUDTValue
- 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 anInputStream
of this user-defined data type.- Specified by:
getValueAsStream
in interfaceUDTValue
- 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 interfaceUDTValue
- 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
andstream
will be set but no other field.
-
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 classObject
- Throws:
IOException
-
-