/** * List files in a folder * * @param containerName Folder name * @return List of file names * @throws IOException */ public List<String> listObjects(String containerName) throws Exception { HttpURLConnection urlConnection = getConnBuilder(containerName, null).getConnection(); HttpResponse response = Utils.doReadOperation(urlConnection); if (!response.isSuccessCode()) { if (response.isAuthDenied()) { log.warn("Refreshing credentials and retrying"); authenticate(); return listObjects(containerName); } else { log.error("Error listing container " + containerName + ", code = " + response.code); } } return response.payloadAsLines(); }
/** * Read the content of a file * * @param containerName Name of the folder * @param objectName name of the file * @return Content of the files * @throws IOException */ public byte[] readObject(String containerName, String objectName) throws Exception { HttpURLConnection urlConnection = getConnBuilder(containerName, objectName).getConnection(); HttpResponse response = Utils.doReadOperation(urlConnection); if (!response.isSuccessCode()) { if (response.isAuthDenied()) { log.warn("Refreshing credentials and retrying"); authenticate(); return readObject(containerName, objectName); } else { log.error( "Error reading object " + objectName + " from container " + containerName + ", code = " + response.code); } } return response.payload; }