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.String
getContentType()
The type of content.java.util.Date
getLastModified()
When the content was modified.java.lang.Long
getLength()
How much content there is.java.lang.String
getSha256()
Get the Sha256 hash.java.lang.String
getSha256(boolean computeIfMissing)
Get or generate the MD5 hash of content.void
setContentType(java.lang.String contentType)
Set the content mime type.void
setLastModified(java.util.Date lastModified)
Set when this content was created.void
setLength(java.lang.Long length)
Set the content length.void
setSha256(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:Content
The type of content.- Specified by:
getContentType
in 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:Content
When the content was modified.- Specified by:
getLastModified
in 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:Content
How 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.Exception
Get the Sha256 hash.
-
getSha256
public java.lang.String getSha256(boolean computeIfMissing) throws java.lang.Exception
Get 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
-
-