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 Details

    • MODE_CLEAR

      public static final int MODE_CLEAR
      Value for position: deletes existing content, leaving an empty document structure.
      See Also:
    • 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:
    • 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:
    • pos

      protected Integer pos
      Position in document structure.
    • variables

      protected Map<String,String> variables
      Variable of this content.
    • streaming

      protected Boolean streaming
      true if streaming for content should be switched on.
    • calculateHash

      protected boolean calculateHash
    • expectedHash

      protected String expectedHash
    • expectedLength

      protected long expectedLength
    • hashAlgorithm

      protected MessageDigest hashAlgorithm
  • Constructor Details

    • ContentStream

      public ContentStream(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(InputStream inputStream, String fileName)
      Constructor.
      Parameters:
      inputStream - content stream
      fileName - file name of content
    • ContentStream

      public ContentStream(InputStream inputStream, String fileName, 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(InputStream inputStream, URL url)
    • ContentStream

      public ContentStream(InputStream inputStream, URL url, int position)
  • Method Details

    • getInputStream

      public 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(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 String getFileName()
      Returns:
      file name
    • setFileName

      public void setFileName(String fileName)
      Parameters:
      fileName - original file name of content
    • setUrl

      public void setUrl(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 Integer getPosition()
      Returns:
      position
    • setPosition

      public void setPosition(Integer position)
      Parameters:
      position - content's position in document structure
    • getVariables

      public Map<String,String> getVariables()
      Returns:
      returns the Variables, which will be stored on a Media belonging to this Binary Object
    • addVariable

      public ContentStream addVariable(String varName, 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(String algorithm) throws 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:
      NoSuchAlgorithmException - if the given algorithm name does not exist.
    • expectHash

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

      public 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 String getExpectedHash()
      Get the hash which was set by client which tries to archive the content.
      Returns:
      hash which is expected
    • getHashAlgorithm

      public MessageDigest getHashAlgorithm()
      Get the MessageDigest which will be used for calculating the hash
      Returns:
      actual used hash algorithm
    • getStreaming

      public 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(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)