Esempio n. 1
0
    /**
     * Create a container, which is equivalent to a bucket
     *
     * @param containerName Name of the container
     * @throws IOException
     */
    public void createContainer(String containerName) throws Exception {
      HttpURLConnection urlConnection =
          getConnBuilder(containerName, null).method("PUT").getConnection();

      HttpResponse response = Utils.doVoidOperation(urlConnection);

      if (!response.isSuccessCode()) {
        if (response.isAuthDenied()) {
          log.warn("Refreshing credentials and retrying");
          authenticate();
          createContainer(containerName);
        } else {
          log.error("Error creating container " + containerName + " ,code = " + response.code);
        }
      }
    }
Esempio n. 2
0
    /**
     * Delete a object (=file) from the storage
     *
     * @param containerName Folder name
     * @param objectName File name
     * @throws IOException
     */
    public void deleteObject(String containerName, String objectName) throws Exception {
      HttpURLConnection urlConnection =
          getConnBuilder(containerName, objectName).method("DELETE").getConnection();

      HttpResponse response = Utils.doVoidOperation(urlConnection);

      if (!response.isSuccessCode()) {
        if (response.isAuthDenied()) {
          log.warn("Refreshing credentials and retrying");
          authenticate();
          deleteObject(containerName, objectName);
        } else {
          log.error(
              "Error deleting object "
                  + objectName
                  + " from container "
                  + containerName
                  + ",code = "
                  + response.code);
        }
      }
    }