org.javaswift.joss.model
Interface StoredObject

All Superinterfaces:
Comparable<StoredObject>, ListSubject, ObjectStoreEntity
All Known Implementing Classes:
AbstractStoredObject, StoredObjectImpl, StoredObjectMock

public interface StoredObject
extends ObjectStoreEntity, Comparable<StoredObject>, ListSubject

StoredObject is a handler for the actual content in the Object Store. The method used most on this handler are uploadObject(java.io.File), uploadObject(java.io.File) and uploadObject(byte[]) which all make sure you can upload your content to the Object Store. Downloading is done by calling downloadObject(), downloadObject(java.io.File) and downloadObjectAsInputStream(). To make sure the object really exists, you can call exists() which places a call to the Object Store. Deleting is done by calling delete(). Creation is done implicitly by uploading content. Two other methods deserve mention here. copyObject(Container, StoredObject) copies a StoredObject in a Container to another Container/ StoredObject combination. getPublicURL() gives you the public URL where the content can be viewed -- this does not work on a private Container.

Author:
Robert Bor

Method Summary
 void copyObject(Container targetContainer, StoredObject targetObject)
          Copies the content of an object to another object.
 void delete()
          Deletes an object in a container.
 byte[] downloadObject()
          Fetches the object in a Container in a byte array.
 byte[] downloadObject(DownloadInstructions downloadInstructions)
          See documentation of downloadObject().
 void downloadObject(File targetFile)
          Reads the object and writes it to a file.
 void downloadObject(File targetFile, DownloadInstructions downloadInstructions)
          See documentation of downloadObject(java.io.File).
 InputStream downloadObjectAsInputStream()
          Fetches the object in a Container in an InputStream.
 InputStream downloadObjectAsInputStream(DownloadInstructions downloadInstructions)
          See documentation of downloadObjectAsInputStream().
 boolean exists()
          Checks whether a container exists
 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.
 String getLastModified()
          The last modified date of the StoredObject.
 Date getLastModifiedAsDate()
          The last modified date of the StoredObject.
 String getPath()
          Returns the path to be appended to the host
 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 seconds)
          Returns a temporary GET URL to an Object.
 String getTempPutUrl(long seconds)
          Returns a temporary POST URL to an Object, allowing one to directly upload content to the ObjectStore.
 String getURL()
          This call checks the container privacy before deciding whether to use the configured public / private host or the default ObjectStore host.
 boolean isInfoRetrieved()
          Returns whether the metadata of the object has been retrieved
 void reload()
          Force the Account to reload its metadata
 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.
 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 interface org.javaswift.joss.model.ObjectStoreEntity
getMetadata, getMetadata, removeAndDoNotSaveMetadata, removeAndSaveMetadata, saveMetadata, setAndDoNotSaveMetadata, setAndSaveMetadata, setMetadata
 
Methods inherited from interface java.lang.Comparable
compareTo
 
Methods inherited from interface org.javaswift.joss.model.ListSubject
getName, metadataSetFromHeaders
 

Method Detail

downloadObjectAsInputStream

InputStream downloadObjectAsInputStream()
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).

Returns:
the object in an InputStreamWrapper (containing the input stream)

downloadObjectAsInputStream

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

Parameters:
downloadInstructions - the instructions for downloading the object
Returns:
the object in an InputStreamWrapper (containing the input stream)

downloadObject

byte[] downloadObject()
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.

Returns:
the object in a byte array

downloadObject

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

Parameters:
downloadInstructions - the instructions for downloading the object
Returns:
the object in a byte array

downloadObject

void downloadObject(File targetFile)
Reads the object and writes it to a file.

Parameters:
targetFile - the file to write the object to

downloadObject

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

Parameters:
targetFile - the file to write the object to
downloadInstructions - the instructions for downloading the object

uploadObject

void uploadObject(UploadInstructions uploadInstructions)
Uploads a byte array object to a location designated by the Container and the object.

Parameters:
uploadInstructions - not only the content to be uploaded, but also additional headers that need to be set

uploadObject

void uploadObject(InputStream inputStream)
Uploads a byte array object to a location designated by the Container and the object.

Parameters:
inputStream - the actual content that must be uploaded to the object, in InputStream format

uploadObject

void uploadObject(byte[] fileToUpload)
Uploads a byte array object to a location designated by the Container and the object.

Parameters:
fileToUpload - the actual content that must be uploaded to the object

uploadObject

void uploadObject(File fileToUpload)
Uploads a file from a designated location to a location designated by the Container and the object.

Parameters:
fileToUpload - the file containing the content that must be uploaded to the object

delete

void delete()
Deletes an object in a container. In combination with copyObject, this is effectively the "Best Practice' move method.


copyObject

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

Parameters:
targetContainer - the owning Container of the target location of the copy
targetObject - the object location where the copy must be placed

setContentType

StoredObject setContentType(String contentType)
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.

Parameters:
contentType - the content type of the object
Returns:
this

setDeleteAfter

StoredObject setDeleteAfter(long seconds)
Schedules the object to be deleted after a fixed period of x seconds

Parameters:
seconds - the number of seconds to wait before deleting the content
Returns:
this

setDeleteAt

StoredObject setDeleteAt(Date date)
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.

Parameters:
date - the date at which to delete the content
Returns:
this

getURL

String getURL()
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.

Returns:
the URL of the resource

getPublicURL

String getPublicURL()
Returns the public URL through which the resource can be viewed

Returns:
the public URL of the resource

getPrivateURL

String getPrivateURL()
Returns the private URL through which the resource can be viewed

Returns:
the private URL of the resource

exists

boolean exists()
Checks whether a container exists

Returns:
whether the container exists

isInfoRetrieved

boolean isInfoRetrieved()
Returns whether the metadata of the object has been retrieved

Returns:
true if the metadata has been retrieved

reload

void reload()
Force the Account to reload its metadata


getLastModifiedAsDate

Date getLastModifiedAsDate()
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.

Returns:
last modified date

getLastModified

String getLastModified()
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.

Returns:
last modified date

getEtag

String getEtag()
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.

Returns:
etag or hash of the StoredObject

getContentLength

long getContentLength()
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.

Returns:
number of bytes used

getContentType

String getContentType()
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.

Returns:
content type

getDeleteAtAsDate

Date getDeleteAtAsDate()
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.

Returns:
date when the StoredObject will be deleted (as a java.util.Date)

getDeleteAt

String getDeleteAt()
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.

Returns:
date when the StoredObject will be deleted (as a String)

getTempGetUrl

String getTempGetUrl(long seconds)
Returns a temporary GET URL to an Object. Note that for this method to work Account.saveHashPassword must have been set.

Parameters:
seconds - number of seconds for the temporary URL to be valid
Returns:
temporary GET URL to the object

getTempPutUrl

String getTempPutUrl(long seconds)
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.

Parameters:
seconds - number of seconds for the temporary URL to be valid
Returns:
temporary POST URL to the object

verifyTempUrl

boolean verifyTempUrl(String method,
                      String signature,
                      long expiry)
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.

Returns:
true if the TempURL is valid, false if not

getPath

String getPath()
Description copied from interface: ObjectStoreEntity
Returns the path to be appended to the host

Specified by:
getPath in interface ObjectStoreEntity
Returns:
the path to append to the host

setLastModified

void setLastModified(Date date)

setLastModified

void setLastModified(String date)

setEtag

void setEtag(String etag)

setContentLength

void setContentLength(long contentLength)

setContentTypeWithoutSaving

void setContentTypeWithoutSaving(String contentType)


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