Package com.saperion.bean
Class ContentStream
java.lang.Object
com.saperion.common.io.InputStreamDescriptor
com.saperion.bean.ContentStream
The document content stream. This stream provides hash and length validation mechanisms.
Hashing mechanism: If
Validation mechanism: If enabled, the validation takes place when the stream content is serialized to the Java Core Server.
In order to enable the length-validation, set a required length via the method
In order to enable the content-hash-validation, set a required hash via the method
Hashing mechanism: If
hashWith
is called with a valid hash-method-name a
content-hash is generated and stored in the content-variables 'SvHashAlgorithm' and 'SvHash'. Validation mechanism: If enabled, the validation takes place when the stream content is serialized to the Java Core Server.
In order to enable the length-validation, set a required length via the method
expectedLength
.
In order to enable the content-hash-validation, set a required hash via the method
expectHash
and state a hash-method via the method hashWith
.- Author:
- tfr
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
protected String
protected long
protected MessageDigest
static final int
Value for position: given content is appended to the last existing content element in the document structure.static final int
Value for position: deletes existing content, leaving an empty document structure.static final int
Value for position: deletes existing content, adding given content as first element.protected Integer
Position in document structure.protected Boolean
true if streaming for content should be switched on.Variable of this content. -
Constructor Summary
ConstructorsConstructorDescriptionContentStream
(InputStream inputStream, String fileName) Constructor.ContentStream
(InputStream inputStream, String fileName, Integer position) Constructor.ContentStream
(InputStream inputStream, URL url) ContentStream
(InputStream inputStream, URL url, int position) ContentStream
(Integer position) Constructor, creates empty ContentStream with given position. -
Method Summary
Modifier and TypeMethodDescriptionaddVariable
(String varName, String varValue) Adds a Variable to this Binary Object, which will be stored on a Media.boolean
Indicates if an expected content length was set and if actual content length should be checked against it.boolean
Returns true if the length limit should be check.boolean
Get the flag if the hash should be calculated while archiving.expectedLength
(long expectedLength) Sets the expected length (number of bytes) of the content.expectHash
(String hash) Set the hash which is expected to be calculated while archiving the content.static ContentStream
fromDescriptor
(InputStreamDescriptor descriptor) Get the hash which was set by client which tries to archive the content.Returns the expected length (number of bytes) of this stream.Get the MessageDigest which will be used for calculating the hashGets theInputStream
this instance holds information about.Returns the max allowed stream length limit.Gets the streaming option.Set the algorithm which should be used for calculating the hash while archiving this content stream.lengthLimit
(long maxLength) Sets the max allowed stream length limit.void
setFileName
(String fileName) void
setInputStream
(InputStream inputStream) Sets theInputStream
this instance holds information about.void
setPosition
(Integer position) void
setStreaming
(Boolean doStreaming) Sets the streaming option.void
Sets the url that defines the streams location.Methods inherited from class com.saperion.common.io.InputStreamDescriptor
getUrl, toString
-
Field Details
-
MODE_CLEAR
public static final int MODE_CLEARValue for position: deletes existing content, leaving an empty document structure.- See Also:
-
MODE_CLEAR_AND_CREATE
public static final int MODE_CLEAR_AND_CREATEValue for position: deletes existing content, adding given content as first element.- See Also:
-
MODE_APPEND
public static final int MODE_APPENDValue for position: given content is appended to the last existing content element in the document structure.- See Also:
-
pos
Position in document structure. -
variables
Variable of this content. -
streaming
true if streaming for content should be switched on. -
calculateHash
protected boolean calculateHash -
expectedHash
-
expectedLength
protected long expectedLength -
hashAlgorithm
-
-
Constructor Details
-
ContentStream
Constructor, creates empty ContentStream with given position.- Parameters:
position
- position in document structure:- -2 : Deletes existing content, leaving an empty document structure
- -1 : Deletes existing content, adding given content as first element
- 0 : Given content is appended to the last existing content element in the document structure
- >0 : Replace the numbered content element with the given content. The overall number of content elements remains the same.
-
ContentStream
Constructor.- Parameters:
inputStream
- content streamfileName
- file name of content
-
ContentStream
Constructor.- Parameters:
inputStream
- content streamfileName
- file name of contentposition
- position in document structure:- -2 : Deletes existing content, leaving an empty document structure
- -1 : Deletes existing content, adding given content as first element
- 0 : Given content is appended to the last existing content element in the document structure
- >0 : Replace the numbered content element with the given content. The overall number of content elements remains the same.
-
ContentStream
-
ContentStream
-
-
Method Details
-
getInputStream
Gets theInputStream
this instance holds information about.- Overrides:
getInputStream
in classInputStreamDescriptor
- Returns:
- the
InputStream
this instance holds information about.
-
setInputStream
Sets theInputStream
this instance holds information about. WhileInputStreamDescriptor
itself does not change itsInputStream
it does allow subclasses to change it, but still assures that theInputStream
is not null.- Overrides:
setInputStream
in classInputStreamDescriptor
- Parameters:
inputStream
- TheInputStream
this instance holds information about. Must not be null.
-
getFileName
- Returns:
- file name
-
setFileName
- Parameters:
fileName
- original file name of content
-
setUrl
Sets the url that defines the streams location. WhileInputStreamDescriptor
itself does not change itsURL
it does allow subclasses to change it.- Overrides:
setUrl
in classInputStreamDescriptor
- Parameters:
url
- The url that defines the streams location.
-
getPosition
- Returns:
- position
-
setPosition
- Parameters:
position
- content's position in document structure
-
getVariables
- Returns:
- returns the Variables, which will be stored on a Media belonging to this Binary Object
-
addVariable
Adds a Variable to this Binary Object, which will be stored on a Media.- Parameters:
varName
- Name of the Variable.varValue
- Value for this Variable.- Returns:
- The Object, where the Variable will be attached to
-
hashWith
Set the algorithm which should be used for calculating the hash while archiving this content stream.- Parameters:
algorithm
- the name of the hash algorithm to use.- Returns:
- this content stream.
- Throws:
NoSuchAlgorithmException
- if the given algorithm name does not exist.
-
expectHash
Set the hash which is expected to be calculated while archiving the content. Activates the content-hash validation. Caution: The hash-string needs to be in HEX-format.- Parameters:
hash
- the HEX hash string.- Returns:
- this content stream.
-
expectedLength
Sets the expected length (number of bytes) of the content. Activates the content-length validation.- Parameters:
expectedLength
- the expected length of the content.- Returns:
- the ContentStream instance itself.
-
lengthLimit
Sets the max allowed stream length limit.- Parameters:
maxLength
- the stream length limit to set.- Returns:
- the
ContentStream
instance
-
getLengthLimit
Returns the max allowed stream length limit.- Returns:
- the max allowed stream length limit of this
ContentStream
object.
-
getExpectedLength
Returns the expected length (number of bytes) of this stream.- Returns:
- expected stream length.
-
doCheckLength
public boolean doCheckLength()Indicates if an expected content length was set and if actual content length should be checked against it.- Returns:
- true if the content length should be checked, false otherwise.
-
doCheckLengthLimit
public boolean doCheckLengthLimit()Returns true if the length limit should be check.Indicates if an max content length limit was set and should be checked during stream serialization.
- Returns:
- true, if the max allowed length limit should be checked, otherwise false.
-
doHashing
public boolean doHashing()Get the flag if the hash should be calculated while archiving.- Returns:
- true if the hash should be calculated, false otherwise.
-
getExpectedHash
Get the hash which was set by client which tries to archive the content.- Returns:
- hash which is expected
-
getHashAlgorithm
Get the MessageDigest which will be used for calculating the hash- Returns:
- actual used hash algorithm
-
getStreaming
Gets the streaming option. If true, the backend will always store the document content with streaming option.- Returns:
- the do streaming
-
setStreaming
Sets the streaming option. If set to true, the backend will always store the document content with streaming.- Parameters:
doStreaming
- the streaming option
-
fromDescriptor
-