List of usage examples for com.amazonaws.util StringUtils fromDate
public static String fromDate(Date value)
From source file:com.mycompany.mytubeaws.ListServlet.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w ww . j a v a 2 s .c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ArrayList<String> nameList = new ArrayList<>(); ArrayList<String> sizeList = new ArrayList<>(); ArrayList<String> dateList = new ArrayList<>(); ObjectListing objects = s3.listObjects(bucketName); do { for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) { nameList.add(objectSummary.getKey()); sizeList.add(Long.toString(objectSummary.getSize())); dateList.add(StringUtils.fromDate(objectSummary.getLastModified())); } objects = s3.listNextBatchOfObjects(objects); } while (objects.isTruncated()); request.setAttribute("nameList", nameList); request.setAttribute("sizeList", sizeList); request.setAttribute("dateList", dateList); request.getRequestDispatcher("/UploadResult.jsp").forward(request, response); }
From source file:imperial.modaclouds.monitoring.datacollectors.monitors.DetailedCostMonitor.java
License:BSD License
@Override public void run() { String accessKeyId = null;//ww w. jav a 2s .c o m String secretKey = null; ObjectListing objects = null; AmazonS3Client s3Client = null; String key = null; long startTime = 0; while (!dcmt.isInterrupted()) { if (System.currentTimeMillis() - startTime > 10000) { cost_nonspot = new HashMap<String, Double>(); cost_spot = new HashMap<String, Double>(); for (String metric : getProvidedMetrics()) { try { VM resource = new VM(Config.getInstance().getVmType(), Config.getInstance().getVmId()); if (dcAgent.shouldMonitor(resource, metric)) { Map<String, String> parameters = dcAgent.getParameters(resource, metric); accessKeyId = parameters.get("accessKey"); secretKey = parameters.get("secretKey"); bucketName = parameters.get("bucketName"); filePath = parameters.get("filePath"); period = Integer.valueOf(parameters.get("samplingTime")) * 1000; } } catch (NumberFormatException e) { e.printStackTrace(); } catch (ConfigurationException e) { e.printStackTrace(); } } startTime = System.currentTimeMillis(); AWSCredentials credentials = new BasicAWSCredentials(accessKeyId, secretKey); s3Client = new AmazonS3Client(credentials); objects = s3Client.listObjects(bucketName); key = "aws-billing-detailed-line-items-with-resources-and-tags-"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); String date = sdf.format(new Date()); key = key + date + ".csv.zip"; } String fileName = null; do { for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) { System.out.println(objectSummary.getKey() + "\t" + objectSummary.getSize() + "\t" + StringUtils.fromDate(objectSummary.getLastModified())); if (objectSummary.getKey().contains(key)) { fileName = objectSummary.getKey(); s3Client.getObject(new GetObjectRequest(bucketName, fileName), new File(filePath + fileName)); break; } } objects = s3Client.listNextBatchOfObjects(objects); } while (objects.isTruncated()); try { ZipFile zipFile = new ZipFile(filePath + fileName); zipFile.extractAll(filePath); } catch (ZipException e) { e.printStackTrace(); } String csvFileName = fileName.replace(".zip", ""); AnalyseFile(filePath + csvFileName); try { Thread.sleep(period); } catch (InterruptedException e) { Thread.currentThread().interrupt(); break; } } }
From source file:md.djembe.aws.AmazonS3WebClient.java
License:Apache License
public static void listBucket() { AmazonS3 s3Client = getS3Client();/*w ww.j a v a2 s . c om*/ List<Bucket> buckets = s3Client.listBuckets(); for (Bucket bucket : buckets) { LOGGER.info("bucket : " + bucket.getName() + "\t" + StringUtils.fromDate(bucket.getCreationDate())); } }