public class Client extends Object
// Create the openstack object for username "jdoe", password "johnsdogsname".
FilesClient myClient = FilesClient("jdoe", "johnsdogsname");
// Log in (login() will return false if the login was unsuccessful.
assert(myClient.login());
// Make sure there are no containers in the account
assert(myClient.listContainers.length() == 0);
// Create the container
assert(myClient.createContainer("myContainer"));
// Now we should have one
assert(myClient.listContainers.length() == 1);
// Upload the file "alpaca.jpg"
assert(myClient.storeObject("myContainer", new File("alapca.jpg"), "image/jpeg"));
// Download "alpaca.jpg"
FilesObject obj = myClient.getObject("myContainer", "alpaca.jpg");
byte data[] = obj.getObject();
// Clean up after ourselves.
// Note: Order here is important, you can't delete non-empty containers.
assert(myClient.deleteObject("myContainer", "alpaca.jpg"));
assert(myClient.deleteContainer("myContainer");
| Modifier and Type | Class and Description |
|---|---|
static class |
Client.AuthVersion |
| Constructor and Description |
|---|
Client(org.apache.http.impl.client.CloseableHttpClient client) |
Client(int connectionTimeOut) |
| Modifier and Type | Method and Description |
|---|---|
AuthenticationResponse |
authenticate(AuthenticationRequest request) |
AuthenticationResponse |
authenticate(AuthenticationRequest request,
org.apache.http.client.ResponseHandler<AuthenticationResponse> handler) |
AuthenticationResponse |
authenticate(Client.AuthVersion authVersion,
URI authenticationURL,
String username,
String password,
String tenantId) |
protected void |
authorize(org.apache.http.client.methods.HttpRequestBase method) |
String |
cdnEnableContainer(Region region,
String name)
Enables access of files in this container via the Content Delivery Network.
|
String |
cdnUpdateContainer(Region region,
String name,
int ttl,
boolean enabled,
boolean retainLogs) |
boolean |
containerExists(Region region,
String container)
Convenience method to test for the existence of a container in Cloud Files.
|
String |
copyObject(Region region,
String sourceContainer,
String sourceObjName,
String destContainer,
String destObjName)
This method copies the object found in the source container with the
source object name to the destination container with the destination
object name.
|
void |
createContainer(Region region,
String name)
Creates a container
|
String |
createDLOManifestObject(Region region,
String container,
String contentType,
String name,
String commonPrefix)
Create a Dynamic Large Object manifest on the server, including metadata
|
String |
createDLOManifestObject(Region region,
String container,
String contentType,
String name,
String commonPrefix,
Map<String,String> metadata)
Create a Dynamic Large Object manifest on the server, including metadata
|
void |
createPath(Region region,
String container,
String path)
Creates a path (but not any of the sub portions of the path)
|
String |
createSLOManifestObject(Region region,
String container,
String contentType,
String name,
String manifest,
Map<String,String> metadata)
Create a Static Large Object manifest on the server, including metadata
|
void |
deleteContainer(Region region,
String name)
Deletes a container
|
void |
deleteObject(Region region,
String container,
String object)
Delete the given object from it's container.
|
void |
deleteObjects(Region region,
String container,
List<String> objects) |
void |
disconnect()
Release all connections
|
AccountInfo |
getAccountInfo(Region region)
Gets information for the given account.
|
AuthenticationResponse |
getAuthentication() |
CDNContainer |
getCDNContainerInfo(Region region,
String container)
Gets current CDN sharing status of the container
|
org.apache.http.impl.client.CloseableHttpClient |
getClient() |
ContainerInfo |
getContainerInfo(Region region,
String container)
Get basic information on a container (number of items and the total size).
|
ContainerMetadata |
getContainerMetaData(Region region,
String container)
Get an container's metadata
|
Response |
getObject(Region region,
String container,
String object)
Get's the given object's content as a stream
|
Response |
getObject(Region region,
String container,
String object,
long offset) |
Response |
getObject(Region region,
String container,
String object,
long offset,
long length) |
ObjectMetadata |
getObjectMetaData(Region region,
String container,
String object)
Get an object's metadata
|
Set<Region> |
getRegions() |
boolean |
isCDNEnabled(Region region,
String container)
Gets current CDN sharing status of the container
|
List<CDNContainer> |
listCdnContainerInfo(Region region)
Gets list of all of the containers associated with this account.
|
List<CDNContainer> |
listCdnContainerInfo(Region region,
int limit)
Gets list of all of the containers associated with this account.
|
List<CDNContainer> |
listCdnContainerInfo(Region region,
int limit,
String marker)
Gets list of all of the containers associated with this account.
|
List<Container> |
listContainers(Region region)
List the containers available in an account.
|
List<Container> |
listContainers(Region region,
int limit)
List the containers available in an account.
|
List<Container> |
listContainers(Region region,
int limit,
String marker)
List the containers available in an account.
|
List<ContainerInfo> |
listContainersInfo(Region region)
List all of the containers available in an account, ordered by container name.
|
List<ContainerInfo> |
listContainersInfo(Region region,
int limit)
List the containers available in an account, ordered by container name.
|
List<ContainerInfo> |
listContainersInfo(Region region,
int limit,
String marker)
List the containers available in an account, ordered by container name.
|
List<StorageObject> |
listObjects(Region region,
String container)
List the objects in a container in lexicographic order.
|
List<StorageObject> |
listObjects(Region region,
String container,
Character delimiter)
List the objects in a container in lexicographic order.
|
List<StorageObject> |
listObjects(Region region,
String container,
int limit)
List the objects in a container in lexicographic order.
|
List<StorageObject> |
listObjects(Region region,
String container,
int limit,
String marker)
List the objects in a container in lexicographic order.
|
List<StorageObject> |
listObjects(Region region,
String container,
String path)
List the objects in a container in lexicographic order.
|
List<StorageObject> |
listObjects(Region region,
String container,
String path,
Character delimiter)
List the objects in a container in lexicographic order.
|
List<StorageObject> |
listObjects(Region region,
String container,
String path,
int limit)
List the objects in a container in lexicographic order.
|
List<StorageObject> |
listObjects(Region region,
String container,
String path,
int limit,
String marker)
List the objects in a container in lexicographic order.
|
Map<String,List<StorageObject>> |
listObjectSegments(Region region,
String container,
String name)
Lists the segments associated with an existing object.
|
List<StorageObject> |
listObjectsStartingWith(Region region,
String container,
String startsWith,
String path,
int limit,
String marker)
List all of the objects in a container with the given starting string.
|
List<StorageObject> |
listObjectsStartingWith(Region region,
String container,
String startsWith,
String path,
int limit,
String marker,
Character delimiter)
List all of the objects in a container with the given starting string.
|
void |
purgeCDNContainer(Region region,
String container,
String emailAddresses)
Purges all items from a given container from the CDN
|
void |
purgeCDNObject(Region region,
String container,
String object,
String emailAddresses)
Purges all items from a given container from the CDN
|
String |
storeObject(Region region,
String container,
InputStream data,
String contentType,
String name,
Map<String,String> metadata)
Store a file on the server, including metadata, with the contents coming from an input stream.
|
String |
storeObject(Region region,
String container,
String name,
org.apache.http.HttpEntity entity,
Map<String,String> metadata,
String md5sum) |
String |
storeObject(Region region,
String container,
String name,
org.apache.http.HttpEntity entity,
Map<String,String> metadata,
String md5sum,
Long objectSize) |
String |
storeObject(Region region,
String container,
String name,
org.apache.http.HttpEntity entity,
Map<String,String> metadata,
String md5sum,
Long objectSize,
Long segmentSize,
Boolean dynamicLargeObject,
String segmentContainer,
String segmentFolder,
Boolean leaveSegments) |
void |
updateAccountMetadata(Region region,
Map<String,String> metadata) |
void |
updateContainerMetadata(Region region,
String container,
Map<String,String> metadata) |
void |
updateObjectManifest(Region region,
String container,
String object,
String manifest) |
void |
updateObjectMetadata(Region region,
String container,
String object,
Map<String,String> metadata) |
void |
updateObjectMetadataAndManifest(Region region,
String container,
String object,
Map<String,String> metadata,
String manifest) |
public Client(int connectionTimeOut)
connectionTimeOut - The connection timeout, in ms.public Client(org.apache.http.impl.client.CloseableHttpClient client)
client - The HttpClient to talk to Swiftpublic org.apache.http.impl.client.CloseableHttpClient getClient()
public void disconnect()
throws IOException
IOExceptionpublic AuthenticationResponse authenticate(Client.AuthVersion authVersion, URI authenticationURL, String username, String password, String tenantId) throws IOException
authVersion - VersionauthenticationURL - Authentication endpoint of identity serviceusername - User or access keypassword - Password or secret keytenantId - Tenant or nullIOExceptionpublic AuthenticationResponse authenticate(AuthenticationRequest request) throws IOException
IOExceptionpublic AuthenticationResponse authenticate(AuthenticationRequest request, org.apache.http.client.ResponseHandler<AuthenticationResponse> handler) throws IOException
IOExceptionpublic AuthenticationResponse getAuthentication()
public List<ContainerInfo> listContainersInfo(Region region) throws IOException
GenericException - Unexpected responseAuthorizationException - The openstack's login was invalid.IOExceptionpublic List<ContainerInfo> listContainersInfo(Region region, int limit) throws IOException
limit - The maximum number of containers to return. -1 returns an unlimited number.GenericException - Unexpected responseAuthorizationException - The openstack's login was invalid.IOExceptionpublic List<ContainerInfo> listContainersInfo(Region region, int limit, String marker) throws IOException
limit - The maximum number of containers to return. -1 returns an unlimited number.marker - Return containers that occur after this lexicographically.GenericException - Unexpected responseAuthorizationException - The openstack's login was invalid.IOExceptionpublic List<Container> listContainers(Region region) throws IOException
GenericException - Unexpected responseAuthorizationException - The openstack's login was invalid.IOExceptionpublic List<Container> listContainers(Region region, int limit) throws IOException
limit - The maximum number of containers to return. -1 denotes no limit.IOException - There was an IO error doing network communicationGenericException - Unexpected responseAuthorizationException - The openstack's login was invalid.public List<Container> listContainers(Region region, int limit, String marker) throws IOException
limit - The maximum number of containers to return. -1 denotes no limit.marker - Only return containers after this container. Null denotes starting at the beginning (lexicographically).GenericException - Unexpected responseAuthorizationException - The openstack's login was invalid.IOExceptionprotected void authorize(org.apache.http.client.methods.HttpRequestBase method)
public List<StorageObject> listObjectsStartingWith(Region region, String container, String startsWith, String path, int limit, String marker) throws IOException
container - The container namestartsWith - The string to start withpath - Only look for objects in this pathlimit - Return at most limit objectsmarker - Returns objects lexicographically greater than marker. Used in conjunction with limit to paginate the list.IOException - There was an IO error doing network communicationGenericException - Unexpected responseAuthorizationException - The openstack's login was invalid.public List<StorageObject> listObjectsStartingWith(Region region, String container, String startsWith, String path, int limit, String marker, Character delimiter) throws IOException
container - The container namestartsWith - The string to start withpath - Only look for objects in this pathlimit - Return at most limit objectsmarker - Returns objects lexicographically greater than marker. Used in conjunction with limit to paginate the list.delimiter - Use this argument as the delimiter that separates "directories"GenericException - Unexpected responseAuthorizationException - The openstack's login was invalid.IOExceptionpublic List<StorageObject> listObjects(Region region, String container) throws IOException
container - The container nameGenericException - Unexpected responseAuthorizationException - The openstack's login was invalid.IOExceptionpublic List<StorageObject> listObjects(Region region, String container, Character delimiter) throws IOException
container - The container namedelimiter - Use this argument as the delimiter that separates "directories"GenericException - Unexpected responseAuthorizationException - The openstack's login was invalid.IOExceptionpublic List<StorageObject> listObjects(Region region, String container, int limit) throws IOException
container - The container namelimit - Return at most limit objectsGenericException - Unexpected responseAuthorizationException - The openstack's login was invalid.IOExceptionpublic List<StorageObject> listObjects(Region region, String container, String path) throws IOException
container - The container namepath - Only look for objects in this pathGenericException - Unexpected responseAuthorizationExceptionIOExceptionpublic List<StorageObject> listObjects(Region region, String container, String path, Character delimiter) throws IOException
container - The container namepath - Only look for objects in this pathdelimiter - Use this argument as the delimiter that separates "directories"IOException - There was an IO error doing network communicationGenericException - Unexpected responseAuthorizationExceptionpublic List<StorageObject> listObjects(Region region, String container, String path, int limit) throws IOException
container - The container namepath - Only look for objects in this pathlimit - Return at most limit objectsGenericException - Unexpected responseAuthorizationException - The openstack's login was invalid.IOExceptionpublic List<StorageObject> listObjects(Region region, String container, String path, int limit, String marker) throws IOException
container - The container namepath - Only look for objects in this pathlimit - Return at most limit objectsmarker - Returns objects lexicographically greater than marker. Used in conjunction with limit to paginate the list.GenericException - Unexpected responseAuthorizationExceptionIOExceptionpublic List<StorageObject> listObjects(Region region, String container, int limit, String marker) throws IOException
container - The container namelimit - Return at most limit objectsmarker - Returns objects lexicographically greater than marker. Used in conjunction with limit to paginate the list.GenericException - Unexpected responseAuthorizationException - The openstack's login was invalid.IOExceptionpublic boolean containerExists(Region region, String container) throws IOException
container - Container nameGenericException - Unexpected responseIOExceptionpublic AccountInfo getAccountInfo(Region region) throws IOException
GenericException - Unexpected responseAuthorizationException - The openstack's login was invalid.IOExceptionpublic ContainerInfo getContainerInfo(Region region, String container) throws IOException
container - The container to get information forGenericException - There was an protocol level exception while talking to CloudfilesNotFoundException - The container was not foundAuthorizationException - The openstack was not logged in or the log in expired.IOExceptionpublic void createContainer(Region region, String name) throws IOException
name - The name of the container to be createdGenericException - Unexpected responseAuthorizationException - The openstack was not property logged inIOExceptionpublic void deleteContainer(Region region, String name) throws IOException
name - The name of the containerGenericException - Unexpected responseAuthorizationException - The user is not Logged inNotFoundException - The container doesn't existContainerNotEmptyException - The container was not emptyIOExceptionpublic String cdnEnableContainer(Region region, String name) throws IOException
name - The name of the container to enableIOException - There was an IO error doing network communicationGenericException - Unexpected responsepublic String cdnUpdateContainer(Region region, String name, int ttl, boolean enabled, boolean retainLogs) throws IOException
IOExceptionpublic CDNContainer getCDNContainerInfo(Region region, String container) throws IOException
container - ContainerGenericException - Unexpected responseNotFoundException - The Container has never been CDN enabledIOExceptionpublic boolean isCDNEnabled(Region region, String container) throws IOException
container - Container nameGenericException - Unexpected responseNotFoundException - The Container has never been CDN enabledIOExceptionpublic void createPath(Region region, String container, String path) throws IOException
container - The name of the container.path - The name of the PathGenericException - Unexpected responseIOExceptionpublic void purgeCDNContainer(Region region, String container, String emailAddresses) throws IOException
container - The name of the containeremailAddresses - An optional comma separated list of email addresses to be notified when the purge is complete.
null if desired.AuthorizationException - Log in was not successful, or account is suspendedGenericException - Unexpected responseIOExceptionpublic void purgeCDNObject(Region region, String container, String object, String emailAddresses) throws IOException
container - The name of the containerobject - The name of the objectemailAddresses - An optional comma separated list of email addresses to be notified when the purge is complete.
null if desired.GenericException - Unexpected responseAuthorizationException - Log in was not successful, or account is suspendedIOExceptionpublic List<CDNContainer> listCdnContainerInfo(Region region) throws IOException
region - The name of the storage regionGenericException - Unexpected responseIOExceptionpublic List<CDNContainer> listCdnContainerInfo(Region region, int limit) throws IOException
region - The name of the storage regionlimit - The maximum number of container names to returnGenericException - Unexpected responseIOExceptionpublic List<CDNContainer> listCdnContainerInfo(Region region, int limit, String marker) throws IOException
region - The name of the storage regionlimit - The maximum number of container names to returnmarker - All of the names will come after marker lexicographically.GenericException - Unexpected responseIOExceptionpublic String createDLOManifestObject(Region region, String container, String contentType, String name, String commonPrefix) throws IOException
region - The name of the storage regioncontainer - The name of the containercontentType - The MIME type of the filename - The name of the file on the servercommonPrefix - Set manifest header content here (the shared prefix of objects that make up the dynamic large object)GenericException - Unexpected responseIOExceptionpublic String createDLOManifestObject(Region region, String container, String contentType, String name, String commonPrefix, Map<String,String> metadata) throws IOException
region - The name of the storage regioncontainer - The name of the containercontentType - The MIME type of the filename - The name of the file on the servercommonPrefix - Set manifest header content here (the shared prefix of objects that make up the dynamic large object)metadata - A map with the metadata as key names and values as the metadata valuesGenericException - Unexpected responseIOExceptionpublic String createSLOManifestObject(Region region, String container, String contentType, String name, String manifest, Map<String,String> metadata) throws IOException
region - The name of the storage regioncontainer - The name of the containercontentType - The MIME type of the filename - The name of the file on the servermanifest - Set manifest content here (A JSON string describing the large object contents)
Should be an ordered list of maps with the following keys for each object segment:
- "path" the path (including container) to the object segment
- "size_bytes" the size in byes of the segment
- "etag" the etag of the segmentmetadata - A map with the metadata as key names and values as the metadata valuesGenericException - Unexpected responseIOExceptionpublic Map<String,List<StorageObject>> listObjectSegments(Region region, String container, String name) throws IOException
region - The name of the storage regioncontainer - The name of the containername - The name of the objectIOExceptionpublic String storeObject(Region region, String container, InputStream data, String contentType, String name, Map<String,String> metadata) throws IOException
region - The name of the storage regioncontainer - The name of the containerdata - Any object that implements InputStreamcontentType - The MIME type of the filename - The name of the file on the servermetadata - A map with the metadata as key names and values as the metadata valuesGenericException - Unexpected responseIOExceptionpublic String storeObject(Region region, String container, String name, org.apache.http.HttpEntity entity, Map<String,String> metadata, String md5sum) throws IOException
region - The name of the storage regioncontainer - The name of the containername - The name of the objectentity - The name of the request entity (make sure to set the Content-Typemetadata - The metadata for the objectmd5sum - The 32 character hex encoded MD5 sum of the dataGenericException - There was a protocol level error talking to CloudFilesIOExceptionpublic String storeObject(Region region, String container, String name, org.apache.http.HttpEntity entity, Map<String,String> metadata, String md5sum, Long objectSize, Long segmentSize, Boolean dynamicLargeObject, String segmentContainer, String segmentFolder, Boolean leaveSegments) throws IOException, InterruptedException
container - The name of the containername - The name of the objectentity - The name of the request entity (make sure to set the Content-Typemetadata - The metadata for the objectmd5sum - The 32 character hex encoded MD5 sum of the dataobjectSize - The total size in bytes of the object to be storedsegmentSize - Optional size in bytes of the object segments to be stored (forces large object support) default 4GdynamicLargeObject - Optional setting to use dynamic large objects, False/null will use static large objects if requiredsegmentContainer - Optional name of container to store file segments, defaults to storing chunks in the same container as the file sill appearsegmentFolder - Optional name of folder for storing file segments, defaults to ".chunks/"leaveSegments - Optional setting to leave segments of large objects in place when the manifest is overwrtten/changedGenericException - There was a protocol level error talking to CloudFilesIOExceptionInterruptedExceptionpublic String storeObject(Region region, String container, String name, org.apache.http.HttpEntity entity, Map<String,String> metadata, String md5sum, Long objectSize) throws IOException, InterruptedException
container - The name of the containername - The name of the objectentity - The name of the request entity (make sure to set the Content-Typemetadata - The metadata for the objectmd5sum - The 32 character hex encoded MD5 sum of the dataobjectSize - The total size in bytes of the object to be storedGenericException - There was a protocol level error talking to CloudFilesIOExceptionInterruptedExceptionpublic String copyObject(Region region, String sourceContainer, String sourceObjName, String destContainer, String destObjName) throws IOException
sourceContainer - of object to copysourceObjName - of object to copydestContainer - where object copy will be copieddestObjName - of object copyGenericException - Unexpected responseIOExceptionpublic void deleteObject(Region region, String container, String object) throws IOException
container - The container nameobject - The object nameIOException - There was an IO error doing network communicationGenericException - Unexpected responseNotFoundException - The file was not foundpublic void deleteObjects(Region region, String container, List<String> objects) throws IOException
IOExceptionpublic ObjectMetadata getObjectMetaData(Region region, String container, String object) throws IOException
container - The name of the containerobject - The name of the objectGenericException - Unexpected responseAuthorizationException - The Client's Login was invalid.NotFoundException - The file was not foundIOExceptionpublic ContainerMetadata getContainerMetaData(Region region, String container) throws IOException
container - The name of the containerGenericException - Unexpected responseAuthorizationException - The Client's Login was invalid.IOExceptionpublic Response getObject(Region region, String container, String object) throws IOException
container - The name of the containerobject - The name of the objectGenericException - Unexpected responseIOExceptionpublic Response getObject(Region region, String container, String object, long offset) throws IOException
IOExceptionpublic Response getObject(Region region, String container, String object, long offset, long length) throws IOException
IOExceptionpublic void updateObjectManifest(Region region, String container, String object, String manifest) throws IOException
IOExceptionpublic void updateObjectMetadata(Region region, String container, String object, Map<String,String> metadata) throws IOException
IOExceptionpublic void updateObjectMetadataAndManifest(Region region, String container, String object, Map<String,String> metadata, String manifest) throws IOException
IOExceptionpublic void updateContainerMetadata(Region region, String container, Map<String,String> metadata) throws IOException
IOExceptionpublic void updateAccountMetadata(Region region, Map<String,String> metadata) throws IOException
IOExceptionCopyright © 2020. All rights reserved.