Class ContentStream


  • public class ContentStream
    extends InputStreamDescriptor
    The document content stream. This stream provides hash and length validation mechanisms.
    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

      Fields 
      Modifier and Type Field Description
      protected boolean calculateHash  
      protected java.lang.String expectedHash  
      protected long expectedLength  
      protected java.security.MessageDigest hashAlgorithm  
      static int MODE_APPEND
      Value for position: given content is appended to the last existing content element in the document structure.
      static int MODE_CLEAR
      Value for position: deletes existing content, leaving an empty document structure.
      static int MODE_CLEAR_AND_CREATE
      Value for position: deletes existing content, adding given content as first element.
      protected java.lang.Integer pos
      Position in document structure.
      protected java.lang.Boolean streaming
      true if streaming for content should be switched on.
      protected java.util.Map<java.lang.String,​java.lang.String> variables
      Variable 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
      ContentStream addVariable​(java.lang.String varName, java.lang.String varValue)
      Adds a Variable to this Binary Object, which will be stored on a Media.
      boolean doCheckLength()
      Indicates if an expected content length was set and if actual content length should be checked against it.
      boolean doCheckLengthLimit()
      Returns true if the length limit should be check.
      boolean doHashing()
      Get the flag if the hash should be calculated while archiving.
      ContentStream expectedLength​(long expectedLength)
      Sets the expected length (number of bytes) of the content.
      ContentStream expectHash​(java.lang.String hash)
      Set the hash which is expected to be calculated while archiving the content.
      static ContentStream fromDescriptor​(InputStreamDescriptor descriptor)  
      java.lang.String getExpectedHash()
      Get the hash which was set by client which tries to archive the content.
      java.lang.Long getExpectedLength()
      Returns the expected length (number of bytes) of this stream.
      java.lang.String getFileName()  
      java.security.MessageDigest getHashAlgorithm()
      Get the MessageDigest which will be used for calculating the hash
      java.io.InputStream getInputStream()
      Gets the InputStream this instance holds information about.
      java.lang.Long getLengthLimit()
      Returns the max allowed stream length limit.
      java.lang.Integer getPosition()  
      java.lang.Boolean getStreaming()
      Gets the streaming option.
      java.util.Map<java.lang.String,​java.lang.String> getVariables()  
      ContentStream hashWith​(java.lang.String algorithm)
      Set the algorithm which should be used for calculating the hash while archiving this content stream.
      ContentStream lengthLimit​(long maxLength)
      Sets the max allowed stream length limit.
      void setFileName​(java.lang.String fileName)  
      void setInputStream​(java.io.InputStream inputStream)
      Sets the InputStream this instance holds information about.
      void setPosition​(java.lang.Integer position)  
      void setStreaming​(java.lang.Boolean doStreaming)
      Sets the streaming option.
      void setUrl​(java.net.URL url)
      Sets the url that defines the streams location.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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 stream
        fileName - file name of content
      • ContentStream

        public ContentStream​(java.io.InputStream inputStream,
                             java.lang.String fileName,
                             java.lang.Integer position)
        Constructor.
        Parameters:
        inputStream - content stream
        fileName - file name of content
        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.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 the InputStream this instance holds information about.
        Overrides:
        getInputStream in class InputStreamDescriptor
        Returns:
        the InputStream this instance holds information about.
      • setInputStream

        public void setInputStream​(java.io.InputStream inputStream)
        Sets the InputStream this instance holds information about. While InputStreamDescriptor itself does not change its InputStream it does allow subclasses to change it, but still assures that the InputStream is not null.
        Overrides:
        setInputStream in class InputStreamDescriptor
        Parameters:
        inputStream - The InputStream this 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. While InputStreamDescriptor itself does not change its URL it does allow subclasses to change it.
        Overrides:
        setUrl in class InputStreamDescriptor
        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 ContentStream instance
      • getLengthLimit

        public java.lang.Long getLengthLimit()
        Returns the max allowed stream length limit.
        Returns:
        the max allowed stream length limit of this ContentStream object.
      • 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