Class AbstractContent

java.lang.Object
gov.usgs.earthquake.product.AbstractContent
All Implemented Interfaces:
Content
Direct Known Subclasses:
ByteContent, FileContent, InputStreamContent, URLContent

public abstract class AbstractContent extends Object implements Content
AbstractContent is a base class for other content classes and implements common functionality.
  • Constructor Details

    • AbstractContent

      public AbstractContent(String contentType, Date lastModified, Long length)
      Null values are replaced with defaults.
      Parameters:
      contentType - defaults to "text/plain".
      lastModified - defaults to new Date().
      length - defaults to -1L.
    • AbstractContent

      public AbstractContent(Content content)
      Copy constructor from another content.
      Parameters:
      content - the content to copy.
    • AbstractContent

      public AbstractContent()
      Default Constructor which requires no arguments. Default values are used for all fields.
  • Method Details

    • getContentType

      public String getContentType()
      Description copied from interface: Content
      The type of content.
      Specified by:
      getContentType in interface Content
      Returns:
      the content mime type.
    • setContentType

      public void setContentType(String contentType)
      Set the content mime type.
      Parameters:
      contentType - the content mime type.
    • getLastModified

      public Date getLastModified()
      Description copied from interface: Content
      When the content was modified.
      Specified by:
      getLastModified in interface Content
      Returns:
      the content creation date.
    • setLastModified

      public void setLastModified(Date lastModified)
      Set when this content was created.
      Parameters:
      lastModified - when this content was created.
    • getLength

      public Long getLength()
      Description copied from interface: Content
      How much content there is.
      Specified by:
      getLength in interface Content
      Returns:
      the content length, or -1 if unknown.
    • setLength

      public void setLength(Long length)
      Set the content length.
      Parameters:
      length - long to set
    • getSha256

      public String getSha256() throws Exception
      Get the Sha256 hash.
      Specified by:
      getSha256 in interface Content
      Returns:
      base64 encoded sha256 of content bytes.
      Throws:
      Exception - if error occurs
    • getSha256

      public String getSha256(boolean computeIfMissing) throws Exception
      Get or generate the MD5 hash of content.
      Parameters:
      computeIfMissing - Use getInputStream to generate hash if missing.
      Returns:
      sha256 string
      Throws:
      Exception - if error occurs
    • setSha256

      public void setSha256(String sha256)
      Set the sha256 hash of content.
      Parameters:
      sha256 - to set