Package com.saperion.bean
Class ContentStream
- java.lang.Object
-
- com.saperion.common.io.InputStreamDescriptor
-
- com.saperion.bean.ContentStream
-
public class ContentStream extends InputStreamDescriptor
The document content stream. This stream provides hash and length validation mechanisms.
Hashing mechanism: IfhashWithis 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 methodexpectedLength.
In order to enable the content-hash-validation, set a required hash via the methodexpectHashand state a hash-method via the methodhashWith.- Author:
- tfr
-
-
Field Summary
Fields Modifier and Type Field Description protected booleancalculateHashprotected java.lang.StringexpectedHashprotected longexpectedLengthprotected java.security.MessageDigesthashAlgorithmstatic intMODE_APPENDValue for position: given content is appended to the last existing content element in the document structure.static intMODE_CLEARValue for position: deletes existing content, leaving an empty document structure.static intMODE_CLEAR_AND_CREATEValue for position: deletes existing content, adding given content as first element.protected java.lang.IntegerposPosition in document structure.protected java.lang.Booleanstreamingtrue if streaming for content should be switched on.protected java.util.Map<java.lang.String,java.lang.String>variablesVariable of this content.
-
Constructor Summary
Constructors Constructor Description ContentStream(java.io.InputStream inputStream, java.lang.String fileName)Constructor.ContentStream(java.io.InputStream inputStream, java.lang.String fileName, java.lang.Integer position)Constructor.ContentStream(java.io.InputStream inputStream, java.net.URL url)ContentStream(java.io.InputStream inputStream, java.net.URL url, int position)ContentStream(java.lang.Integer position)Constructor, creates empty ContentStream with given position.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ContentStreamaddVariable(java.lang.String varName, java.lang.String varValue)Adds a Variable to this Binary Object, which will be stored on a Media.booleandoCheckLength()Indicates if an expected content length was set and if actual content length should be checked against it.booleandoCheckLengthLimit()Returns true if the length limit should be check.booleandoHashing()Get the flag if the hash should be calculated while archiving.ContentStreamexpectedLength(long expectedLength)Sets the expected length (number of bytes) of the content.ContentStreamexpectHash(java.lang.String hash)Set the hash which is expected to be calculated while archiving the content.static ContentStreamfromDescriptor(InputStreamDescriptor descriptor)java.lang.StringgetExpectedHash()Get the hash which was set by client which tries to archive the content.java.lang.LonggetExpectedLength()Returns the expected length (number of bytes) of this stream.java.lang.StringgetFileName()java.security.MessageDigestgetHashAlgorithm()Get the MessageDigest which will be used for calculating the hashjava.io.InputStreamgetInputStream()Gets theInputStreamthis instance holds information about.java.lang.LonggetLengthLimit()Returns the max allowed stream length limit.java.lang.IntegergetPosition()java.lang.BooleangetStreaming()Gets the streaming option.java.util.Map<java.lang.String,java.lang.String>getVariables()ContentStreamhashWith(java.lang.String algorithm)Set the algorithm which should be used for calculating the hash while archiving this content stream.ContentStreamlengthLimit(long maxLength)Sets the max allowed stream length limit.voidsetFileName(java.lang.String fileName)voidsetInputStream(java.io.InputStream inputStream)Sets theInputStreamthis instance holds information about.voidsetPosition(java.lang.Integer position)voidsetStreaming(java.lang.Boolean doStreaming)Sets the streaming option.voidsetUrl(java.net.URL url)Sets the url that defines the streams location.-
Methods inherited from class com.saperion.common.io.InputStreamDescriptor
getUrl, toString
-
-
-
-
Field Detail
-
MODE_CLEAR
public static final int MODE_CLEAR
Value for position: deletes existing content, leaving an empty document structure.- See Also:
- Constant Field Values
-
MODE_CLEAR_AND_CREATE
public static final int MODE_CLEAR_AND_CREATE
Value for position: deletes existing content, adding given content as first element.- See Also:
- Constant Field Values
-
MODE_APPEND
public static final int MODE_APPEND
Value for position: given content is appended to the last existing content element in the document structure.- See Also:
- Constant Field Values
-
pos
protected java.lang.Integer pos
Position in document structure.
-
variables
protected java.util.Map<java.lang.String,java.lang.String> variables
Variable of this content.
-
streaming
protected java.lang.Boolean streaming
true if streaming for content should be switched on.
-
calculateHash
protected boolean calculateHash
-
expectedHash
protected java.lang.String expectedHash
-
expectedLength
protected long expectedLength
-
hashAlgorithm
protected java.security.MessageDigest hashAlgorithm
-
-
Constructor Detail
-
ContentStream
public ContentStream(java.lang.Integer position)
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
public ContentStream(java.io.InputStream inputStream, java.lang.String fileName)Constructor.- Parameters:
inputStream- content streamfileName- file name of content
-
ContentStream
public ContentStream(java.io.InputStream inputStream, java.lang.String fileName, java.lang.Integer position)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
public ContentStream(java.io.InputStream inputStream, java.net.URL url)
-
ContentStream
public ContentStream(java.io.InputStream inputStream, java.net.URL url, int position)
-
-
Method Detail
-
getInputStream
public java.io.InputStream getInputStream()
Gets theInputStreamthis instance holds information about.- Overrides:
getInputStreamin classInputStreamDescriptor- Returns:
- the
InputStreamthis instance holds information about.
-
setInputStream
public void setInputStream(java.io.InputStream inputStream)
Sets theInputStreamthis instance holds information about. WhileInputStreamDescriptoritself does not change itsInputStreamit does allow subclasses to change it, but still assures that theInputStreamis not null.- Overrides:
setInputStreamin classInputStreamDescriptor- Parameters:
inputStream- TheInputStreamthis instance holds information about. Must not be null.
-
getFileName
public java.lang.String getFileName()
- Returns:
- file name
-
setFileName
public void setFileName(java.lang.String fileName)
- Parameters:
fileName- original file name of content
-
setUrl
public void setUrl(java.net.URL url)
Sets the url that defines the streams location. WhileInputStreamDescriptoritself does not change itsURLit does allow subclasses to change it.- Overrides:
setUrlin classInputStreamDescriptor- Parameters:
url- The url that defines the streams location.
-
getPosition
public java.lang.Integer getPosition()
- Returns:
- position
-
setPosition
public void setPosition(java.lang.Integer position)
- Parameters:
position- content's position in document structure
-
getVariables
public java.util.Map<java.lang.String,java.lang.String> getVariables()
- Returns:
- returns the Variables, which will be stored on a Media belonging to this Binary Object
-
addVariable
public ContentStream addVariable(java.lang.String varName, java.lang.String varValue)
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
public ContentStream hashWith(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException
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:
java.security.NoSuchAlgorithmException- if the given algorithm name does not exist.
-
expectHash
public ContentStream expectHash(java.lang.String hash)
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
public ContentStream expectedLength(long 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
public ContentStream lengthLimit(long maxLength)
Sets the max allowed stream length limit.- Parameters:
maxLength- the stream length limit to set.- Returns:
- the
ContentStreaminstance
-
getLengthLimit
public java.lang.Long getLengthLimit()
Returns the max allowed stream length limit.- Returns:
- the max allowed stream length limit of this
ContentStreamobject.
-
getExpectedLength
public java.lang.Long 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
public java.lang.String getExpectedHash()
Get the hash which was set by client which tries to archive the content.- Returns:
- hash which is expected
-
getHashAlgorithm
public java.security.MessageDigest getHashAlgorithm()
Get the MessageDigest which will be used for calculating the hash- Returns:
- actual used hash algorithm
-
getStreaming
public java.lang.Boolean getStreaming()
Gets the streaming option. If true, the backend will always store the document content with streaming option.- Returns:
- the do streaming
-
setStreaming
public void setStreaming(java.lang.Boolean doStreaming)
Sets the streaming option. If set to true, the backend will always store the document content with streaming.- Parameters:
doStreaming- the streaming option
-
fromDescriptor
public static ContentStream fromDescriptor(InputStreamDescriptor descriptor)
-
-