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 aRereadableContent
and provides the necessary logic for serialisation. The usage ofRereadableContent
allows toclose()
thisUDTValue
while continue to use the created streams. Obviously, after closing thisUDTValue
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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Cleanup<IOException>
cleanup
The clean-up called after as post-mortem action of thisADEPT2UDTValue
.protected org.apache.commons.lang3.mutable.Mutable<RereadableContent>
data
The value of thisUDTValue
asRereadableContent
.protected String
userDefinedTypeName
The name of the user-defined type.
-
Constructor Summary
Constructors Constructor Description ADEPT2UDTValue(byte[] value, String userDefinedType)
Creates a new UDTValue with the designated name and the designated value (byte array).ADEPT2UDTValue(UDTValue udt)
Creates a newUDTValue
with the properties and the content of the designatedUDTValue
.ADEPT2UDTValue(InputStream stream, long size, String userDefinedType)
Creates a new UDTValue with the designated name and the designated value (input stream) having the designated size.ADEPT2UDTValue(InputStream stream, String userDefinedType)
Creates a new UDTValue with the designated name and the designated value (input stream).ADEPT2UDTValue(String userDefinedType, byte[] value)
Deprecated, for removal: This API element is subject to removal in a future version.UseADEPT2UDTValue(byte[], String)
instead.ADEPT2UDTValue(String userDefinedType, InputStream stream)
Deprecated, for removal: This API element is subject to removal in a future version.UseADEPT2UDTValue(InputStream, String)
instead.ADEPT2UDTValue(String userDefinedType, InputStream stream, boolean eager)
Deprecated, for removal: This API element is subject to removal in a future version.UseADEPT2UDTValue(InputStream, String)
instead.ADEPT2UDTValue(String userDefinedType, InputStream stream, int length)
Deprecated, for removal: This API element is subject to removal in a future version.UseADEPT2UDTValue(byte[], String)
with aBoundedInputStream
instead.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ADEPT2UDTValue
clone()
Clones thisUDTValue
in case it isCloneable
, otherwise aCloneNotSupportedException
will be thrown (which is what this default implementation does).static UDTValue
clone(UDTValue udt, boolean forceRecreation)
Clones or recreates the designatedUDTValue
depending on the designatedrecreate
and whether ccloning is supported.static UDTValue
cloneUnchecked(UDTValue udt, boolean forceRecreation)
Clones or recreates the designatedUDTValue
depending on the designatedrecreate
and whether ccloning is supported.void
close()
Closes the rereadable content and thus all created input streams (if not closed yet).boolean
equals(Object obj)
byte[]
getBytes()
Gets the value as a byte array of this user-defined data type.AttributedInputStream
getInputStream()
Gets the value as anInputStream
of this user-defined data type.Long
getSize()
Gets the size of this UDT value if it is known.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.AttributedInputStream
getValueAsStream()
Gets the value as anInputStream
of this user-defined data type.int
hashCode()
String
toString()
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface de.aristaflow.adept2.model.datamanagement.UDTValue
getContentString, getSize, isEmpty
-
-
-
-
Field Detail
-
userDefinedTypeName
protected String userDefinedTypeName
The name of the user-defined type.
-
data
protected org.apache.commons.lang3.mutable.Mutable<RereadableContent> data
The value of thisUDTValue
asRereadableContent
. This is always completely initialised.
The field will be serialised asbyte[]
.
-
cleanup
protected transient Cleanup<IOException> cleanup
The clean-up called after as post-mortem action of thisADEPT2UDTValue
. Since this is the same logic, it is also used byclose()
.
-
-
Constructor Detail
-
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.UseADEPT2UDTValue(byte[], String)
instead.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 thisUDTValue
. 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 thisUDTValue
. 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 theRereadableContent
, anIOException
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.UseADEPT2UDTValue(InputStream, String)
instead.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 thisUDTValue
. 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 thisUDTValue
. 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 theRereadableContent
, anIOException
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 thisUDTValue
. 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 theRereadableContent
, anIOException
will be thrown.
-
ADEPT2UDTValue
public ADEPT2UDTValue(UDTValue udt) throws IOException
Creates a newUDTValue
with the properties and the content of the designatedUDTValue
.
You can also clone() anADEPT2UDTValue
. This works similar to this constructor but wraps theIOexception
in anUncheckedIOException
.- Parameters:
udt
- TheUDTValue
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 theRereadableContent
, anIOException
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.UseADEPT2UDTValue(InputStream, String)
instead.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 thisUDTValue
. 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.UseADEPT2UDTValue(byte[], String)
with aBoundedInputStream
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 thisUDTValue
. 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, 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 AttributedInputStream getValueAsStream()
Description copied from interface:UDTValue
Gets the value as anInputStream
of this user-defined data type.
You have to close the stream after usage.- Specified by:
getValueAsStream
in interfaceUDTValue
- 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 anInputStream
of this user-defined data type.
You have to close the stream after usage. Usually you should notUDTValue.close()
thisUDTValue
before all created input streams have been consumed. Implementations may deviate so that closing theUDTValue
does not affect the created input streams. closing will not affect theInputStream
.- Specified by:
getInputStream
in interfaceUDTValue
- 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 correspondingInputStream
, anIOException
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 interfaceUDTValue
- 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 andnull
will be returned.
-
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 interfaceUDTValue
- 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, anIOException
will be thrown.
-
clone
public ADEPT2UDTValue clone()
Description copied from interface:UDTValue
Clones thisUDTValue
in case it isCloneable
, otherwise aCloneNotSupportedException
will be thrown (which is what this default implementation does). Subclasses should provide a corresponding implementation and also extendCloneable
. Those which do not, should forward to this default implementation.- Specified by:
clone
in interfaceTypedCloneable<ADEPT2UDTValue>
- Specified by:
clone
in interfaceUDTValue
- Overrides:
clone
in classObject
- Returns:
- A clone of this
UDTValue
instance.
-
close
public void close() throws IOException
Closes the rereadable content and thus all created input streams (if not closed yet).- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceUDTValue
- Throws:
IOException
-
clone
public static UDTValue clone(UDTValue udt, boolean forceRecreation) throws IOException
Clones or recreates the designatedUDTValue
depending on the designatedrecreate
and whether ccloning is supported. Ifrecreate
or cloning is not supported or fails, the designatedUDTValue
will be recreated as new instance ofADEPT2UDTValue
.- Parameters:
udt
- TheUDTValue
which to clone or recreate. This may benull
.forceRecreation
- Whether recreating asADEPT2UDTValue
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
ornull
. - Throws:
IOException
- If there are problems creating a newADEPT2UDTValue
(may be a consequence of unsuccessful cloning), the correspondingIOException
will be thrown.
-
cloneUnchecked
public static UDTValue cloneUnchecked(UDTValue udt, boolean forceRecreation)
Clones or recreates the designatedUDTValue
depending on the designatedrecreate
and whether ccloning is supported. Ifrecreate
or cloning is not supported or fails, the designatedUDTValue
will be recreated as new instance ofADEPT2UDTValue
.- Parameters:
udt
- TheUDTValue
which to clone or recreate. This may benull
.forceRecreation
- Whether recreating asADEPT2UDTValue
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
ornull
. - Throws:
UncheckedIOException
- If there are problems creating a newADEPT2UDTValue
(may be a consequence of unsuccessful cloning), the correspondingIOException
will be wrapped with anUncheckedIOException
and re-thrown.
-
-