Package gov.usgs.earthquake.product
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 java.lang.Object implements Content
AbstractContent is a base class for other content classes and implements common functionality.
-
-
Constructor Summary
Constructors Constructor Description AbstractContent()Default Constructor which requires no arguments.AbstractContent(Content content)Copy constructor from another content.AbstractContent(java.lang.String contentType, java.util.Date lastModified, java.lang.Long length)Null values are replaced with defaults.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetContentType()The type of content.java.util.DategetLastModified()When the content was modified.java.lang.LonggetLength()How much content there is.java.lang.StringgetSha256()Get the Sha256 hash.java.lang.StringgetSha256(boolean computeIfMissing)Get or generate the MD5 hash of content.voidsetContentType(java.lang.String contentType)Set the content mime type.voidsetLastModified(java.util.Date lastModified)Set when this content was created.voidsetLength(java.lang.Long length)Set the content length.voidsetSha256(java.lang.String sha256)Set the sha256 hash of content.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface gov.usgs.earthquake.product.Content
close, getInputStream
-
-
-
-
Constructor Detail
-
AbstractContent
public AbstractContent(java.lang.String contentType, java.util.Date lastModified, java.lang.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 Detail
-
getContentType
public java.lang.String getContentType()
Description copied from interface:ContentThe type of content.- Specified by:
getContentTypein interfaceContent- Returns:
- the content mime type.
-
setContentType
public void setContentType(java.lang.String contentType)
Set the content mime type.- Parameters:
contentType- the content mime type.
-
getLastModified
public java.util.Date getLastModified()
Description copied from interface:ContentWhen the content was modified.- Specified by:
getLastModifiedin interfaceContent- Returns:
- the content creation date.
-
setLastModified
public void setLastModified(java.util.Date lastModified)
Set when this content was created.- Parameters:
lastModified- when this content was created.
-
getLength
public java.lang.Long getLength()
Description copied from interface:ContentHow much content there is.
-
setLength
public void setLength(java.lang.Long length)
Set the content length.- Parameters:
length- long to set
-
getSha256
public java.lang.String getSha256() throws java.lang.ExceptionGet the Sha256 hash.
-
getSha256
public java.lang.String getSha256(boolean computeIfMissing) throws java.lang.ExceptionGet or generate the MD5 hash of content.- Parameters:
computeIfMissing- Use getInputStream to generate hash if missing.- Returns:
- sha256 string
- Throws:
java.lang.Exception- if error occurs
-
setSha256
public void setSha256(java.lang.String sha256)
Set the sha256 hash of content.- Parameters:
sha256- to set
-
-