org.javaswift.joss.client.core
Class AbstractStoredObject

java.lang.Object
  extended by org.javaswift.joss.client.core.AbstractObjectStoreEntity<ObjectInformation>
      extended by org.javaswift.joss.client.core.AbstractStoredObject
All Implemented Interfaces:
Comparable<StoredObject>, ListSubject, ObjectStoreEntity, StoredObject
Direct Known Subclasses:
StoredObjectImpl, StoredObjectMock

public abstract class AbstractStoredObject
extends AbstractObjectStoreEntity<ObjectInformation>
implements StoredObject


Field Summary
protected  String name
           
 
Fields inherited from class org.javaswift.joss.client.core.AbstractObjectStoreEntity
ALLOW_CACHING, info, staleHeaders
 
Constructor Summary
AbstractStoredObject(Container container, String name, boolean allowCaching)
           
 
Method Summary
 int compareTo(StoredObject o)
           
 void copyObject(Container targetContainer, StoredObject targetObject)
          Copies the content of an object to another object.
protected  Metadata createMetadataEntry(String name, String value)
           
 void delete()
          Deletes an object in a container.
 void directlyUploadObject(UploadInstructions uploadInstructions)
           
 byte[] downloadObject()
          Fetches the object in a Container in a byte array.
 byte[] downloadObject(DownloadInstructions downloadInstructions)
          See documentation of StoredObject.downloadObject().
 void downloadObject(File targetFile)
          Reads the object and writes it to a file.
 void downloadObject(File targetFile, DownloadInstructions downloadInstructions)
          See documentation of StoredObject.downloadObject(java.io.File).
 InputStream downloadObjectAsInputStream()
          Fetches the object in a Container in an InputStream.
 InputStream downloadObjectAsInputStream(DownloadInstructions downloadInstructions)
          See documentation of StoredObject.downloadObjectAsInputStream().
 boolean equals(Object o)
           
protected  Account getAccount()
           
 Container getContainer()
           
 long getContentLength()
          The number of the bytes used by the StoredObject.
 String getContentType()
          The content type of the StoredObject.
 String getDeleteAt()
          The date when the object will be deleted.
 Date getDeleteAtAsDate()
          The date when the object will be deleted.
 String getEtag()
          The etag (or hash) of the StoredObject.
protected  void getInfo(boolean allowErrorLog)
           
 String getLastModified()
          The last modified date of the StoredObject.
 Date getLastModifiedAsDate()
          The last modified date of the StoredObject.
 String getName()
           
 String getPathForEntity()
           
 String getPrivateURL()
          Returns the private URL through which the resource can be viewed
 String getPublicURL()
          Returns the public URL through which the resource can be viewed
 String getTempGetUrl(long durationInSeconds)
          Returns a temporary GET URL to an Object.
 String getTempPutUrl(long durationInSeconds)
          Returns a temporary POST URL to an Object, allowing one to directly upload content to the ObjectStore.
protected  String getTempUrl(String method, long durationInSeconds)
           
 String getURL()
          This call checks the container privacy before deciding whether to use the configured public / private host or the default ObjectStore host.
 int hashCode()
           
 void metadataSetFromHeaders()
          Declares to the ListSubject that a number of fields have been read from the list operation and therefore do not have to be fetched individually, unless caching is turned off.
protected  void saveSpecificMetadata()
           
 void setContentLength(long contentLength)
           
 StoredObject setContentType(String contentType)
          Explicitly sets the content type of an object.
 void setContentTypeWithoutSaving(String contentType)
           
 StoredObject setDeleteAfter(long seconds)
          Schedules the object to be deleted after a fixed period of x seconds
 StoredObject setDeleteAt(Date date)
          Schedules the object to be deleted at a fixed date.
 void setEtag(String etag)
           
 void setLastModified(Date date)
           
 void setLastModified(String date)
           
 void uploadObject(byte[] fileToUpload)
          Uploads a byte array object to a location designated by the Container and the object.
 void uploadObject(File fileToUpload)
          Uploads a file from a designated location to a location designated by the Container and the object.
 void uploadObject(InputStream inputStream)
          Uploads a byte array object to a location designated by the Container and the object.
 void uploadObject(UploadInstructions uploadInstructions)
          Uploads a byte array object to a location designated by the Container and the object.
 void uploadObjectAsSegments(UploadInstructions uploadInstructions)
           
 boolean verifyTempUrl(String method, String signature, long expiry)
          Creates a hash using the server's hash password and compares it to the signature.
 
Methods inherited from class org.javaswift.joss.client.core.AbstractObjectStoreEntity
checkForInfo, checkForInfo, checkForInfoAndAllowHeaderSet, checkForInfoDisallowErrorLog, exists, getMetadata, getMetadata, getPath, invalidate, isAllowCaching, isInfoRetrieved, isStale, reload, removeAndDoNotSaveMetadata, removeAndSaveMetadata, saveMetadata, setAndDoNotSaveMetadata, setAndSaveMetadata, setInfoRetrieved, setMetadata
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.javaswift.joss.model.StoredObject
exists, getPath, isInfoRetrieved, reload
 
Methods inherited from interface org.javaswift.joss.model.ObjectStoreEntity
getMetadata, getMetadata, removeAndDoNotSaveMetadata, removeAndSaveMetadata, saveMetadata, setAndDoNotSaveMetadata, setAndSaveMetadata, setMetadata
 

Field Detail

name

protected String name
Constructor Detail

AbstractStoredObject

public AbstractStoredObject(Container container,
                            String name,
                            boolean allowCaching)
Method Detail

metadataSetFromHeaders

public void metadataSetFromHeaders()
Description copied from interface: ListSubject
Declares to the ListSubject that a number of fields have been read from the list operation and therefore do not have to be fetched individually, unless caching is turned off.

Specified by:
metadataSetFromHeaders in interface ListSubject

getLastModifiedAsDate

public Date getLastModifiedAsDate()
Description copied from interface: StoredObject
The last modified date of the StoredObject. If the Container was read by Container.list, this value will not be refetched from the server, unless caching is disabled.

Specified by:
getLastModifiedAsDate in interface StoredObject
Returns:
last modified date

getLastModified

public String getLastModified()
Description copied from interface: StoredObject
The last modified date of the StoredObject. If the Container was read by Container.list, this value will not be refetched from the server, unless caching is disabled.

Specified by:
getLastModified in interface StoredObject
Returns:
last modified date

getEtag

public String getEtag()
Description copied from interface: StoredObject
The etag (or hash) of the StoredObject. If the Container was read by Container.list, this value will not be refetched from the server, unless caching is disabled.

Specified by:
getEtag in interface StoredObject
Returns:
etag or hash of the StoredObject

getContentLength

public long getContentLength()
Description copied from interface: StoredObject
The number of the bytes used by the StoredObject. If the Container was read by Container.list, this value will not be refetched from the server, unless caching is disabled.

Specified by:
getContentLength in interface StoredObject
Returns:
number of bytes used

getContentType

public String getContentType()
Description copied from interface: StoredObject
The content type of the StoredObject. If the Container was read by Container.list, this value will not be refetched from the server, unless caching is disabled.

Specified by:
getContentType in interface StoredObject
Returns:
content type

getDeleteAtAsDate

public Date getDeleteAtAsDate()
Description copied from interface: StoredObject
The date when the object will be deleted. Note that this value is never passed in Container.list and therefore always costs an extra HTTP call to the server.

Specified by:
getDeleteAtAsDate in interface StoredObject
Returns:
date when the StoredObject will be deleted (as a java.util.Date)

getDeleteAt

public String getDeleteAt()
Description copied from interface: StoredObject
The date when the object will be deleted. Note that this value is never passed in Container.list and therefore always costs an extra HTTP call to the server.

Specified by:
getDeleteAt in interface StoredObject
Returns:
date when the StoredObject will be deleted (as a String)

getName

public String getName()
Specified by:
getName in interface ListSubject

getContainer

public Container getContainer()

getURL

public String getURL()
Description copied from interface: StoredObject
This call checks the container privacy before deciding whether to use the configured public / private host or the default ObjectStore host. NOTE: this call needs to know the container's privacy settings and therefore, if it did not do so already, will make a HEAD call to fetch the container's metadata.

Specified by:
getURL in interface StoredObject
Returns:
the URL of the resource

getPublicURL

public String getPublicURL()
Description copied from interface: StoredObject
Returns the public URL through which the resource can be viewed

Specified by:
getPublicURL in interface StoredObject
Returns:
the public URL of the resource

getPrivateURL

public String getPrivateURL()
Description copied from interface: StoredObject
Returns the private URL through which the resource can be viewed

Specified by:
getPrivateURL in interface StoredObject
Returns:
the private URL of the resource

getPathForEntity

public String getPathForEntity()
                        throws UnsupportedEncodingException
Specified by:
getPathForEntity in class AbstractObjectStoreEntity<ObjectInformation>
Throws:
UnsupportedEncodingException

setLastModified

public void setLastModified(Date date)
Specified by:
setLastModified in interface StoredObject

setLastModified

public void setLastModified(String date)
Specified by:
setLastModified in interface StoredObject

setEtag

public void setEtag(String etag)
Specified by:
setEtag in interface StoredObject

setContentLength

public void setContentLength(long contentLength)
Specified by:
setContentLength in interface StoredObject

setContentTypeWithoutSaving

public void setContentTypeWithoutSaving(String contentType)
Specified by:
setContentTypeWithoutSaving in interface StoredObject

hashCode

public int hashCode()
Overrides:
hashCode in class Object

uploadObject

public void uploadObject(UploadInstructions uploadInstructions)
Description copied from interface: StoredObject
Uploads a byte array object to a location designated by the Container and the object.

Specified by:
uploadObject in interface StoredObject
Parameters:
uploadInstructions - not only the content to be uploaded, but also additional headers that need to be set

uploadObjectAsSegments

public void uploadObjectAsSegments(UploadInstructions uploadInstructions)

equals

public boolean equals(Object o)
Overrides:
equals in class Object

compareTo

public int compareTo(StoredObject o)
Specified by:
compareTo in interface Comparable<StoredObject>

createMetadataEntry

protected Metadata createMetadataEntry(String name,
                                       String value)
Specified by:
createMetadataEntry in class AbstractObjectStoreEntity<ObjectInformation>

downloadObjectAsInputStream

public InputStream downloadObjectAsInputStream()
Description copied from interface: StoredObject
Fetches the object in a Container in an InputStream. Note that for passing the information on, the content-type is useful. This information can be found by fetching the object information. BE AWARE that the original InputStream must be closed after usage, which can be accomplished by calling close on the InputStream (which consumes the entire original response).

Specified by:
downloadObjectAsInputStream in interface StoredObject
Returns:
the object in an InputStreamWrapper (containing the input stream)

downloadObjectAsInputStream

public InputStream downloadObjectAsInputStream(DownloadInstructions downloadInstructions)
Description copied from interface: StoredObject
See documentation of StoredObject.downloadObjectAsInputStream(). This method also accepts the download instructions, which can be used among others to set the "Range" and "If-*" headers.

Specified by:
downloadObjectAsInputStream in interface StoredObject
Parameters:
downloadInstructions - the instructions for downloading the object
Returns:
the object in an InputStreamWrapper (containing the input stream)

downloadObject

public byte[] downloadObject()
Description copied from interface: StoredObject
Fetches the object in a Container in a byte array. Note that for passing the information on, the content-type is useful. This information can be found by fetching the object information.

Specified by:
downloadObject in interface StoredObject
Returns:
the object in a byte array

downloadObject

public byte[] downloadObject(DownloadInstructions downloadInstructions)
Description copied from interface: StoredObject
See documentation of StoredObject.downloadObject(). This method also accepts the download instructions, which can be used among others to set the "Range" and "If-*" headers.

Specified by:
downloadObject in interface StoredObject
Parameters:
downloadInstructions - the instructions for downloading the object
Returns:
the object in a byte array

downloadObject

public void downloadObject(File targetFile)
Description copied from interface: StoredObject
Reads the object and writes it to a file.

Specified by:
downloadObject in interface StoredObject
Parameters:
targetFile - the file to write the object to

downloadObject

public void downloadObject(File targetFile,
                           DownloadInstructions downloadInstructions)
Description copied from interface: StoredObject
See documentation of StoredObject.downloadObject(java.io.File). This method also accepts the download instructions, which can be used among others to set the "Range" and "If-*" headers.

Specified by:
downloadObject in interface StoredObject
Parameters:
targetFile - the file to write the object to
downloadInstructions - the instructions for downloading the object

directlyUploadObject

public void directlyUploadObject(UploadInstructions uploadInstructions)

uploadObject

public void uploadObject(InputStream inputStream)
Description copied from interface: StoredObject
Uploads a byte array object to a location designated by the Container and the object.

Specified by:
uploadObject in interface StoredObject
Parameters:
inputStream - the actual content that must be uploaded to the object, in InputStream format

uploadObject

public void uploadObject(byte[] fileToUpload)
Description copied from interface: StoredObject
Uploads a byte array object to a location designated by the Container and the object.

Specified by:
uploadObject in interface StoredObject
Parameters:
fileToUpload - the actual content that must be uploaded to the object

uploadObject

public void uploadObject(File fileToUpload)
Description copied from interface: StoredObject
Uploads a file from a designated location to a location designated by the Container and the object.

Specified by:
uploadObject in interface StoredObject
Parameters:
fileToUpload - the file containing the content that must be uploaded to the object

delete

public void delete()
Description copied from interface: StoredObject
Deletes an object in a container. In combination with copyObject, this is effectively the "Best Practice' move method.

Specified by:
delete in interface StoredObject

copyObject

public void copyObject(Container targetContainer,
                       StoredObject targetObject)
Description copied from interface: StoredObject
Copies the content of an object to another object. In combination with deleteObject, this is effectively the "Best Practice" move method.

Specified by:
copyObject in interface StoredObject
Parameters:
targetContainer - the owning Container of the target location of the copy
targetObject - the object location where the copy must be placed

setContentType

public StoredObject setContentType(String contentType)
Description copied from interface: StoredObject
Explicitly sets the content type of an object. This can be useful, for example when you have content-sniffers in the application that need to advise the object store (which uses a simple file extension matching instead of content-sniffing) as to the real nature of the uploaded file.

Specified by:
setContentType in interface StoredObject
Parameters:
contentType - the content type of the object
Returns:
this

setDeleteAfter

public StoredObject setDeleteAfter(long seconds)
Description copied from interface: StoredObject
Schedules the object to be deleted after a fixed period of x seconds

Specified by:
setDeleteAfter in interface StoredObject
Parameters:
seconds - the number of seconds to wait before deleting the content
Returns:
this

setDeleteAt

public StoredObject setDeleteAt(Date date)
Description copied from interface: StoredObject
Schedules the object to be deleted at a fixed date. Be careful using this method, since the server's date may be different from yours.

Specified by:
setDeleteAt in interface StoredObject
Parameters:
date - the date at which to delete the content
Returns:
this

getAccount

protected Account getAccount()

saveSpecificMetadata

protected void saveSpecificMetadata()
Specified by:
saveSpecificMetadata in class AbstractObjectStoreEntity<ObjectInformation>

getInfo

protected void getInfo(boolean allowErrorLog)
Specified by:
getInfo in class AbstractObjectStoreEntity<ObjectInformation>

getTempGetUrl

public String getTempGetUrl(long durationInSeconds)
Description copied from interface: StoredObject
Returns a temporary GET URL to an Object. Note that for this method to work Account.saveHashPassword must have been set.

Specified by:
getTempGetUrl in interface StoredObject
Parameters:
durationInSeconds - number of seconds for the temporary URL to be valid
Returns:
temporary GET URL to the object

getTempPutUrl

public String getTempPutUrl(long durationInSeconds)
Description copied from interface: StoredObject
Returns a temporary POST URL to an Object, allowing one to directly upload content to the ObjectStore. The object does not yet have to exist for this method to be invoked. Note that for this method to work Account.saveHashPassword must have been set.

Specified by:
getTempPutUrl in interface StoredObject
Parameters:
durationInSeconds - number of seconds for the temporary URL to be valid
Returns:
temporary POST URL to the object

getTempUrl

protected String getTempUrl(String method,
                            long durationInSeconds)

verifyTempUrl

public boolean verifyTempUrl(String method,
                             String signature,
                             long expiry)
Description copied from interface: StoredObject
Creates a hash using the server's hash password and compares it to the signature. If right, expiry will be checked against the server time. If all matches, a go is given. This method is useful for supporting TempURLs in a mock context.

Specified by:
verifyTempUrl in interface StoredObject
Returns:
true if the TempURL is valid, false if not


Copyright © 2012-2014 42 BV. All Rights Reserved.