/** * Create an object (=file) * * @param containerName Name of the container * @param objectName Name of the file * @param contents Binary content of the file */ public void createObject(String containerName, String objectName, byte[] contents) { HttpURLConnection conn = new ConnBuilder(credentials, containerName, objectName) .method("PUT") .addHeader(CONTENT_LENGTH_HEADER, String.valueOf(contents.length)) .getConnection(); Response response = doSendOperation(conn, contents); if (!response.isSuccessCode()) { if (response.isAuthDenied()) { log.warn("Refreshing credentials and retrying"); authenticate(); createObject(containerName, objectName, contents); } else { log.error(Util.getMessage("ErrorCreatingObject") + objectName + " in container " + containerName + ",code = " + response.code); } } }
/** * Create an object (=file) * * @param containerName Name of the container * @param objectName Name of the file * @param contents Binary content of the file */ public void createObject(String containerName, String objectName, byte[] contents) { HttpURLConnection conn = new ConnBuilder(credentials, containerName, objectName) .method("PUT") .addHeader(CONTENT_LENGTH_HEADER, String.valueOf(contents.length)) .getConnection(); Response response = doSendOperation(conn, contents); if (!response.isSuccessCode()) { if (response.isAuthDenied()) { log.warn("Refreshing credentials and retrying"); authenticate(); createObject(containerName, objectName, contents); } else { log.error(Util.getMessage("ErrorCreatingObject") + objectName + " in container " + containerName + ",code = " + response.code); } } }
/** * Read the content of a file * * @param containerName Name of the folder * @param objectName name of the file * @return Content of the files */ public byte[] readObject(String containerName, String objectName) { HttpURLConnection urlConnection = new ConnBuilder(credentials, containerName, objectName).getConnection(); Response response = doReadOperation(urlConnection); if (!response.isSuccessCode()) { if (response.isAuthDenied()) { log.warn("Refreshing credentials and retrying"); authenticate(); return readObject(containerName, objectName); } else { log.error(Util.getMessage("ErrorReadingObject") + objectName + " from container " + containerName + ", code = " + response.code); } } return response.payload; }
/** * Delete a object (=file) from the storage * * @param containerName Folder name * @param objectName File name */ public void deleteObject(String containerName, String objectName) { HttpURLConnection urlConnection = new ConnBuilder(credentials, containerName, objectName) .method("DELETE") .getConnection(); Response response = doVoidOperation(urlConnection); if (!response.isSuccessCode()) { if (response.isAuthDenied()) { log.warn("Refreshing credentials and retrying"); authenticate(); deleteObject(containerName, objectName); } else { log.error(Util.getMessage("ErrorDeletingObject") + objectName + " from container " + containerName + ",code = " + response.code); } } }
/** * List files in a folder * * @param containerName Folder name * @return List of file names */ public List<String> listObjects(String containerName) { HttpURLConnection urlConnection = new ConnBuilder(credentials, containerName, null).getConnection(); Response response = doReadOperation(urlConnection); if (!response.isSuccessCode()) { if (response.isAuthDenied()) { log.warn("Refreshing credentials and retrying"); authenticate(); return listObjects(containerName); } else { log.error(Util.getMessage("ErrorListingContainer") + containerName + ", code = " + response.code); } } return response.payloadAsLines(); }
/** * Create a container, which is equivalent to a bucket * * @param containerName Name of the container */ public void createContainer(String containerName) { HttpURLConnection urlConnection = new ConnBuilder(credentials, containerName, null) .method("PUT") .getConnection(); Response response = doVoidOperation(urlConnection); if (!response.isSuccessCode()) { if (response.isAuthDenied()) { log.warn("Refreshing credentials and retrying"); authenticate(); createContainer(containerName); } else { log.error(Util.getMessage("ErrorCreatingContainer") + containerName + " ,code = " + response.code); } } }
@Override protected void createRootDir() { rackspaceClient.authenticate(); rackspaceClient.createContainer(container); }
/** * Read the content of a file * * @param containerName Name of the folder * @param objectName name of the file * @return Content of the files */ public byte[] readObject(String containerName, String objectName) { HttpURLConnection urlConnection = new ConnBuilder(credentials, containerName, objectName).getConnection(); Response response = doReadOperation(urlConnection); if (!response.isSuccessCode()) { if (response.isAuthDenied()) { log.warn("Refreshing credentials and retrying"); authenticate(); return readObject(containerName, objectName); } else { log.error(Util.getMessage("ErrorReadingObject") + objectName + " from container " + containerName + ", code = " + response.code); } } return response.payload; }
/** * Delete a object (=file) from the storage * * @param containerName Folder name * @param objectName File name */ public void deleteObject(String containerName, String objectName) { HttpURLConnection urlConnection = new ConnBuilder(credentials, containerName, objectName) .method("DELETE") .getConnection(); Response response = doVoidOperation(urlConnection); if (!response.isSuccessCode()) { if (response.isAuthDenied()) { log.warn("Refreshing credentials and retrying"); authenticate(); deleteObject(containerName, objectName); } else { log.error(Util.getMessage("ErrorDeletingObject") + objectName + " from container " + containerName + ",code = " + response.code); } } }
/** * Create a container, which is equivalent to a bucket * * @param containerName Name of the container */ public void createContainer(String containerName) { HttpURLConnection urlConnection = new ConnBuilder(credentials, containerName, null) .method("PUT") .getConnection(); Response response = doVoidOperation(urlConnection); if (!response.isSuccessCode()) { if (response.isAuthDenied()) { log.warn("Refreshing credentials and retrying"); authenticate(); createContainer(containerName); } else { log.error(Util.getMessage("ErrorCreatingContainer") + containerName + " ,code = " + response.code); } } }
/** * List files in a folder * * @param containerName Folder name * @return List of file names */ public List<String> listObjects(String containerName) { HttpURLConnection urlConnection = new ConnBuilder(credentials, containerName, null).getConnection(); Response response = doReadOperation(urlConnection); if (!response.isSuccessCode()) { if (response.isAuthDenied()) { log.warn("Refreshing credentials and retrying"); authenticate(); return listObjects(containerName); } else { log.error(Util.getMessage("ErrorListingContainer") + containerName + ", code = " + response.code); } } return response.payloadAsLines(); }
@Override protected void createRootDir() { rackspaceClient.authenticate(); rackspaceClient.createContainer(container); }