Package com.amazon.s3

Examples of com.amazon.s3.GetObjectResult


      request.setCredential("TODO");
      request.setSignature("TODO");
      request.setTimestamp(Calendar.getInstance());
     
      ListBucketResponse response = serviceStub.listBucket(request);
      ListBucketResult result = response.getListBucketResponse();
      System.out.println("\tContent of Bucket " + result.getName());
      System.out.println("\tListing with prefix: " + result.getPrefix() + ", delimiter: "
        + result.getDelimiter() + ", marker: " + result.getMarker() + ", max: " + result.getMaxKeys());
     
      ListEntry[] entries = result.getContents();
      if(entries != null) {
        for(int i = 0; i < entries.length; i++) {
          ListEntry entry = entries[i];
          System.out.print("\t");
          System.out.print(entry.getSize());
          System.out.print("\t");
          System.out.print(entry.getKey());
          System.out.print("\t");
          System.out.print(entry.getETag());
          System.out.print("\n");
        }
      }
     
      PrefixEntry[] prefixEntries = result.getCommonPrefixes();
      if(prefixEntries != null) {
        System.out.print("\n\n");
       
        for(int i = 0; i < prefixEntries.length; i++) {
          System.out.print("\t<Prefix>\t");
View Full Code Here


        + result.getDelimiter() + ", marker: " + result.getMarker() + ", max: " + result.getMaxKeys());
     
      ListEntry[] entries = result.getContents();
      if(entries != null) {
        for(int i = 0; i < entries.length; i++) {
          ListEntry entry = entries[i];
          System.out.print("\t");
          System.out.print(entry.getSize());
          System.out.print("\t");
          System.out.print(entry.getKey());
          System.out.print("\t");
          System.out.print(entry.getETag());
          System.out.print("\n");
        }
      }
     
      PrefixEntry[] prefixEntries = result.getCommonPrefixes();
View Full Code Here

      System.out.println("Unable to find file " + args[args.length -1]);
      System.exit(0);
    }
   
    try {
      PutObjectInline request = new PutObjectInline();
      request.setBucket(params.get("bucket"));
      request.setKey(params.get("name"));
      request.setContentLength(file.length());
      request.setAWSAccessKeyId("TODO");
      request.setCredential("TODO");
      request.setSignature("TODO");
      request.setTimestamp(Calendar.getInstance());
      request.setData(new DataHandler(file.toURL()));
     
      PutObjectInlineResponse response = serviceStub.putObjectInline(request);
        System.out.println("Object has been posted successfully. ETag: " + response.getPutObjectInlineResponse().getETag());
    } catch(Exception e) {
        System.out.println("Failed to execute object-put-inline due to " + e.getMessage());
View Full Code Here

      request.setCredential("TODO");
      request.setSignature("TODO");
      request.setTimestamp(Calendar.getInstance());
      request.setData(new DataHandler(file.toURL()));
     
      PutObjectInlineResponse response = serviceStub.putObjectInline(request);
        System.out.println("Object has been posted successfully. ETag: " + response.getPutObjectInlineResponse().getETag());
    } catch(Exception e) {
        System.out.println("Failed to execute object-put-inline due to " + e.getMessage());
    }
  }
View Full Code Here

        request.setBucket(args[1]);
        request.setSignature("TODO");
        request.setTimestamp(Calendar.getInstance());
       
        DeleteBucketResponse response = serviceStub.deleteBucket(request);
        Status status = response.getDeleteBucketResponse();
        if(status.getCode() == 200) {
          System.out.println("Bucket " + args[1] + " has been deleted successfully");
        } else {
          System.out.println("Unable to delete bucket " + args[1] + " - " + status.getDescription());
        }
      } catch(Exception e) {
        System.out.println("Failed to execute bucket-delete due to " + e.getMessage());
      }
  }
View Full Code Here

    }
   
    Access access = new Access();
   
    /* Get the metadata for the given file */
    GetObjectResult result = null;
   
   
    /* Try a few times to get the object */
    /* Put the file, We'll try a few times */
    int attemptCount = 0;
    while (attemptCount < MAX_S3_READWRITE_ATTEMPTS)
    {
      attemptCount++;
     
      try
      {
       
        long startTime = System.currentTimeMillis();
       
       
        AmazonS3_ServiceLocator locator = new AmazonS3_ServiceLocator();
        AmazonS3SoapBindingStub binding = new AmazonS3SoapBindingStub(new URL(locator.getAmazonS3Address()), locator);
       
        result = binding.getObject(getBucketName(),
                      key,
                      false,
                      true,
                      false,
                      access.getAccessKey(),
                      access.getAccessCalendar(),
                      access.generateSignature("GetObject"),
                      null);
       
       
        long endTime = System.currentTimeMillis();
       
               
        /* Get the attachments. Note, the getAttachments() method will ONLY return the object[] on the first call.  Subsiquent calls will return null */
        Object[] attachments = binding.getAttachments();
        if (attachments.length != 1)
        {
          throw new Exception("The S3 Object returned [" + attachments.length + "] when we expected exactly 1");
        }
       
        /* Setup the MD5 digest */
        MessageDigest messageDigest = MessageDigest.getInstance("MD5");
       
        /* Get the attachment, and pipe it's data to the buffer */
        OutputStream os = createBufferOutputStream();
        AttachmentPart part = (AttachmentPart) attachments[0];
        InputStream attachmentStream = part.getDataHandler().getInputStream();
        long byteCount = 0;
        int b = 0;
        while ((b = attachmentStream.read()) != -1)
        {
          byteCount++;
          messageDigest.update((byte)b);
          os.write(b);
         
          if (byteCount % 1000 == 0)
          {
            Log.info("\r" + byteCount + " bytes read...");
          }
        }
       
        Log.info("\r" + byteCount + " bytes read...");
       
        os.flush();
        os.close();
       
        this.kBytesProcessed_ += ((double)byteCount / 1000.0);
       
        Log.info(String.format("%6.02f Kb/s\n", (((double)((double)byteCount * (double)Byte.SIZE)) / 1000D) / ((endTime - startTime) / 1000)));
        Log.debug(byteCount + " bytes written to buffer\n");

       
        /* Calculate the MD5 value */
        String md5 =  Common.toHex(messageDigest.digest());
       
        /* compare md5 hashes */
        if (md5.equals(result.getETag().replaceAll("\"", "")) == false)
        {
          throw new Exception("After getting the S3 object [" + key + "], we compared the md5 hash codes. They did not match\n" + "original: [" + md5 + "]\nS3: [" + result.getETag() + "]");
        }
       
        /* Now, stream the file to stdout */
        byteCount = 0;
        InputStream is = createBufferInputStream();
View Full Code Here

      arch.lastModifiedDate = timestamp;
     
      /* Given this is the first object found with this prefix, we'll use this
       * key to get it's metadata for the TAG value */
      Access access = new Access();
      GetObjectResult result = new AmazonS3_ServiceLocator().getAmazonS3().getObject(getBucketName(),
                                              key,
                                              true,
                                              false,
                                              false,
                                              access.getAccessKey(),
                                              access.getAccessCalendar(),
                                              access.generateSignature("GetObject"),
                                              null);
     
      /* get the meta data TAG value */
      for (int index = 0; index < result.getMetadata().length; index++)
      {
        if (META_DATA_TAG.equals(result.getMetadata()[index].getName()))
        {
          arch.tag = result.getMetadata()[index].getValue();
          break;
        }
      }
     
      /* Add this archive object to our map */
 
View Full Code Here

            || byteRangeStart != null || byteRangeEnd != null;
       
        try {
            AmazonS3SoapBindingStub s3SoapBinding = getSoapBinding();
            Calendar timestamp = getTimeStamp( System.currentTimeMillis() );
            GetObjectResult result = null;
           
            if (useExtendedGet) {
                log.debug("Using Extended GET to apply constraints: "
                    + "ifModifiedSince=" + (ifModifiedSince != null? ifModifiedSince.getTime().toString() : "null")
                    + ", ifUnmodifiedSince=" + (ifUnmodifiedSince != null? ifUnmodifiedSince.getTime().toString() : "null")
                    + ", ifMatchTags=" + (ifMatchTags != null? Arrays.asList(ifMatchTags).toString() : "null")
                    + ", ifNoneMatchTags=" + (ifNoneMatchTags != null? Arrays.asList(ifNoneMatchTags).toString() : "null")
                    + ", byteRangeStart=" + byteRangeStart + ", byteRangeEnd=" + byteRangeEnd);
               
                String signature = ServiceUtils.signWithHmacSha1(getAWSSecretKey(),
                    Constants.SOAP_SERVICE_NAME + "GetObjectExtended" + convertDateToString(timestamp));
                result = s3SoapBinding.getObjectExtended(
                    bucketName, objectKey, true, withData, false, byteRangeStart, byteRangeEnd,
                    ifModifiedSince, ifUnmodifiedSince, ifMatchTags, ifNoneMatchTags,
                    Boolean.FALSE, getAWSAccessKey(), timestamp, signature, null);
               
                // Throw an exception if the preconditions failed.
                int expectedStatusCode = 200;
                if (byteRangeStart != null || byteRangeEnd != null) {
                    // Partial data responses have a status code of 206.
                    expectedStatusCode = 206;
                }
                if (result.getStatus().getCode() != expectedStatusCode) {
                    throw new S3ServiceException("Precondition failed when getting object "
                        + objectKey + ": " + result.getStatus().getDescription());
                }
            } else {
                log.debug("Using standard GET (no constraints to apply)");
                String signature = ServiceUtils.signWithHmacSha1(getAWSSecretKey(),
                    Constants.SOAP_SERVICE_NAME + "GetObject" + convertDateToString(timestamp));
                result = s3SoapBinding.getObject(
                    bucketName, objectKey, true, withData, false,               
                    getAWSAccessKey(), timestamp, signature, null);               
            }
           
            S3Object object = new S3Object(objectKey);
            object.setETag(result.getETag());
            object.setLastModifiedDate(result.getLastModified().getTime());
            object.setBucketName(bucketName);
           
            // Get data details from the SOAP attachment.
            if (withData) {
                Object[] attachments = s3SoapBinding.getAttachments();
                log.debug("SOAP attachment count for " + object.getKey() + ": " + attachments.length);
                for (int i = 0; i < attachments.length; i++) {
                    if (i > 0) {
                        throw new S3ServiceException(
                            "Received multiple SOAP attachment parts, this shouldn't happen");
                    }
                    AttachmentPart part = (AttachmentPart) attachments[i];
                    object.setContentType(part.getContentType());
                    object.setContentLength(part.getSize());
                    object.setDataInputStream(part.getDataHandler().getInputStream());
                }
            }
           
            // Populate object's metadata details.
            MetadataEntry[] metadata = result.getMetadata();
            for (int i = 0; i < metadata.length; i++) {
                MetadataEntry entry = metadata[i];
                object.addMetadata(entry.getName(), entry.getValue());
            }
            object.setMetadataComplete(true);
View Full Code Here

            || byteRangeStart != null || byteRangeEnd != null;
       
        try {
            AmazonS3SoapBindingStub s3SoapBinding = getSoapBinding();
            Calendar timestamp = getTimeStamp( System.currentTimeMillis() );
            GetObjectResult result = null;
           
            if (useExtendedGet) {
              if (log.isDebugEnabled()) {
                  log.debug("Using Extended GET to apply constraints: "
                      + "ifModifiedSince=" + (ifModifiedSince != null? ifModifiedSince.getTime().toString() : "null")
                      + ", ifUnmodifiedSince=" + (ifUnmodifiedSince != null? ifUnmodifiedSince.getTime().toString() : "null")
                      + ", ifMatchTags=" + (ifMatchTags != null? Arrays.asList(ifMatchTags).toString() : "null")
                      + ", ifNoneMatchTags=" + (ifNoneMatchTags != null? Arrays.asList(ifNoneMatchTags).toString() : "null")
                      + ", byteRangeStart=" + byteRangeStart + ", byteRangeEnd=" + byteRangeEnd);
              }
             
                String signature = ServiceUtils.signWithHmacSha1(getAWSSecretKey(),
                    Constants.SOAP_SERVICE_NAME + "GetObjectExtended" + convertDateToString(timestamp));
                result = s3SoapBinding.getObjectExtended(
                    bucketName, objectKey, true, withData, false, byteRangeStart, byteRangeEnd,
                    ifModifiedSince, ifUnmodifiedSince, ifMatchTags, ifNoneMatchTags,
                    Boolean.FALSE, getAWSAccessKey(), timestamp, signature, null);
               
                // Throw an exception if the preconditions failed.
                int expectedStatusCode = 200;
                if (byteRangeStart != null || byteRangeEnd != null) {
                    // Partial data responses have a status code of 206.
                    expectedStatusCode = 206;
                }
                if (result.getStatus().getCode() != expectedStatusCode) {
                    throw new S3ServiceException("Precondition failed when getting object "
                        + objectKey + ": " + result.getStatus().getDescription());
                }
            } else {
              if (log.isDebugEnabled()) {
                log.debug("Using standard GET (no constraints to apply)");
              }
                String signature = ServiceUtils.signWithHmacSha1(getAWSSecretKey(),
                    Constants.SOAP_SERVICE_NAME + "GetObject" + convertDateToString(timestamp));
                result = s3SoapBinding.getObject(
                    bucketName, objectKey, true, withData, false,               
                    getAWSAccessKey(), timestamp, signature, null);               
            }
           
            S3Object object = new S3Object(objectKey);
            object.setETag(result.getETag());
            object.setLastModifiedDate(result.getLastModified().getTime());
            object.setBucketName(bucketName);
           
            // Get data details from the SOAP attachment.
            if (withData) {
                Object[] attachments = s3SoapBinding.getAttachments();
                if (log.isDebugEnabled()) {
                  log.debug("SOAP attachment count for " + object.getKey() + ": " + attachments.length);
                }
                for (int i = 0; i < attachments.length; i++) {
                    if (i > 0) {
                        throw new S3ServiceException(
                            "Received multiple SOAP attachment parts, this shouldn't happen");
                    }
                    AttachmentPart part = (AttachmentPart) attachments[i];
                    object.setContentType(part.getContentType());
                    object.setContentLength(part.getSize());
                    object.setDataInputStream(part.getDataHandler().getInputStream());
                }
            }
           
            // Populate object's metadata details.
            MetadataEntry[] metadata = result.getMetadata();
            for (int i = 0; i < metadata.length; i++) {
                MetadataEntry entry = metadata[i];
                object.addMetadata(entry.getName(), entry.getValue());
            }
            object.setMetadataComplete(true);
View Full Code Here

            || byteRangeStart != null || byteRangeEnd != null;
       
        try {
            AmazonS3SoapBindingStub s3SoapBinding = getSoapBinding();
            Calendar timestamp = getTimeStamp( System.currentTimeMillis() );
            GetObjectResult result = null;
           
            if (useExtendedGet) {
              if (log.isDebugEnabled()) {
                  log.debug("Using Extended GET to apply constraints: "
                      + "ifModifiedSince=" + (ifModifiedSince != null? ifModifiedSince.getTime().toString() : "null")
                      + ", ifUnmodifiedSince=" + (ifUnmodifiedSince != null? ifUnmodifiedSince.getTime().toString() : "null")
                      + ", ifMatchTags=" + (ifMatchTags != null? Arrays.asList(ifMatchTags).toString() : "null")
                      + ", ifNoneMatchTags=" + (ifNoneMatchTags != null? Arrays.asList(ifNoneMatchTags).toString() : "null")
                      + ", byteRangeStart=" + byteRangeStart + ", byteRangeEnd=" + byteRangeEnd);
              }
             
                String signature = ServiceUtils.signWithHmacSha1(getAWSSecretKey(),
                    Constants.SOAP_SERVICE_NAME + "GetObjectExtended" + convertDateToString(timestamp));
                result = s3SoapBinding.getObjectExtended(
                    bucketName, objectKey, true, withData, false, byteRangeStart, byteRangeEnd,
                    ifModifiedSince, ifUnmodifiedSince, ifMatchTags, ifNoneMatchTags,
                    Boolean.FALSE, getAWSAccessKey(), timestamp, signature, null);
               
                // Throw an exception if the preconditions failed.
                int expectedStatusCode = 200;
                if (byteRangeStart != null || byteRangeEnd != null) {
                    // Partial data responses have a status code of 206.
                    expectedStatusCode = 206;
                }
                if (result.getStatus().getCode() != expectedStatusCode) {
                    throw new S3ServiceException("Precondition failed when getting object "
                        + objectKey + ": " + result.getStatus().getDescription());
                }
            } else {
              if (log.isDebugEnabled()) {
                log.debug("Using standard GET (no constraints to apply)");
              }
                String signature = ServiceUtils.signWithHmacSha1(getAWSSecretKey(),
                    Constants.SOAP_SERVICE_NAME + "GetObject" + convertDateToString(timestamp));
                result = s3SoapBinding.getObject(
                    bucketName, objectKey, true, withData, false,               
                    getAWSAccessKey(), timestamp, signature, null);               
            }
           
            S3Object object = new S3Object(objectKey);
            object.setETag(result.getETag());
            object.setLastModifiedDate(result.getLastModified().getTime());
            object.setBucketName(bucketName);
           
            // Get data details from the SOAP attachment.
            if (withData) {
                Object[] attachments = s3SoapBinding.getAttachments();
                if (log.isDebugEnabled()) {
                  log.debug("SOAP attachment count for " + object.getKey() + ": " + attachments.length);
                }
                for (int i = 0; i < attachments.length; i++) {
                    if (i > 0) {
                        throw new S3ServiceException(
                            "Received multiple SOAP attachment parts, this shouldn't happen");
                    }
                    AttachmentPart part = (AttachmentPart) attachments[i];
                    object.setContentType(part.getContentType());
                    object.setContentLength(part.getSize());
                    object.setDataInputStream(part.getDataHandler().getInputStream());
                }
            }
           
            // Populate object's metadata details.
            MetadataEntry[] metadata = result.getMetadata();
            for (int i = 0; i < metadata.length; i++) {
                MetadataEntry entry = metadata[i];
                object.addMetadata(entry.getName(), entry.getValue());
            }
            object.setMetadataComplete(true);
View Full Code Here

TOP

Related Classes of com.amazon.s3.GetObjectResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.