Package com.amazonaws.s3.doc._2006_03_01

Examples of com.amazonaws.s3.doc._2006_03_01.PutObjectResult


    }
   
    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

      /* Create the bucket if it doesn't yet exist */
      boolean bucketFound = false;

      /* First, create the bucket if it doesn't yet exist */
      ListOperation listOperation = new ListOperation(null, null);
      ListAllMyBucketsResult list = listOperation.getBucketList();

      for (ListAllMyBucketsEntry bucket : list.getBuckets())
      {
        if (getBucketName().equals(bucket.getName()))
        {
          bucketFound = true;
          break;
View Full Code Here

    {
   
      Log.info("Bucket List\n");
     
      /* Get the list of files from S3 */
      ListAllMyBucketsResult listResult = null;
 
      /* Get a page of results */
      listResult = getBucketList();
     
      long bucketCount = 0;
     
      /* Process this list of keys */
      for (ListAllMyBucketsEntry listEntry : listResult.getBuckets())
      {
        String bucket = listEntry.getName();
        Log.info(this.df_.format(listEntry.getCreationDate().getTime()) + " - " + bucket + "\n");       
        bucketCount++;
      }
     
     
      Log.info(String.format("total: %d\n", bucketCount));
     
    }
    else
    {
     
      /* If a bucket is specified, then list the files in the bucket */
      String marker = null;
     
      /* Get the list of files from S3 */
      ListBucketResult listResult = null;
     
      /* This do while loop deals with the paging of s3 lists */
      do
      {
        /* Get a page of results */
        listResult = getBucketObjectList(marker, getBucketName(), getPrefixName(), MAX_KEYS_PER_LIST);
       
        if (listResult.getContents() != null)
        {
          /* Process this list of keys */
          for (ListEntry listEntry : listResult.getContents())
          {
            marker = listEntry.getKey();
            processListEntry(listEntry);
           
          }
         
        }
           
      }
      while(listResult.isIsTruncated());
     
     
      /* Now that each object has been processed, dump the results to the screen */
      Iterator keyIterator = this.archives_.keySet().iterator();
      while (keyIterator.hasNext())
View Full Code Here

  public ListAllMyBucketsResult getBucketList() throws Exception
  {
    Access access = new Access();
   
    /* Get the list of files from S3 */
    ListAllMyBucketsResult listResult = null;
   
    /* Get a page of results */
    listResult = getS3Port().listAllMyBuckets(
                      access.getAccessKey(),
                      access.getAccessCalendar(),
View Full Code Here

  {
      throw new ProviderRequestException( e );
  }
  SortedSet<Metadata> contents = bucket.getContents( );
 
  ListBucketResult output = new ListBucketResult( );
  output.setIsTruncated( bucket.isTruncated( ) );
  output.setDelimiter( bucket.getDelimiter( ) );
  output.setMarker( bucket.getMarker( ) );
  output.setMaxKeys( (int) bucket.getMaxKeys( ) );
  output.setName( bucket.getName( ) );
  output.setPrefix( bucket.getPrefix( ) );
 
  List<ListEntry> outputContents = output.getContents( );
  for ( Metadata meta : contents )
  {
      ListEntry entry = new ListEntry( );
      entry.setETag( String.valueOf( meta.getMd5( ) ) );
      entry.setKey( meta.getKey( ) );
View Full Code Here

      // the delimiter out for now and will possibly add it later
      // if people complain.
      String dirPath = directory.getPath( ).getAbsolutePath( );
      String prefix = directory.isRoot( ) ? "" : dirPath.substring( 1 );
     
      ListBucketResult resp = executeListDirectoryRequest( prefix, marker );
     
      resultsWereTruncated = resp.isIsTruncated( );
      int numResults = resp.getContents( ).size( );
      marker = marker + numResults + 1;
     
      if ( output == null )
      {
    if ( resultsWereTruncated )
    {
        output = new ArrayList<CloudStoreObject>( 5 * numResults );
    }
    else
    {
        output = new ArrayList<CloudStoreObject>( numResults );
    }
      }
     
      for ( ListEntry entry : resp.getContents( ) )
      {
    CloudStoreObject obj;
    String path = entry.getKey( );
    if ( !filter.shouldInclude( path ) )
        continue;
View Full Code Here

  request.addQueryArg( "marker", String.valueOf( marker ) );
  request.addQueryArg( "prefix", prefix );
 
  request.setBucket( _bucket );
 
  ListBucketResult resp = null;
  InputStream is = request.execute( );
  try
  {
      StreamSource stream = new StreamSource( is );
      JAXBElement<ListBucketResult> root = LIST_BUCKET_RESPONSE_UNMARSHALLER
View Full Code Here

    ListOperation listOp = new ListOperation(getBucketName(), getPrefixName());
   
    String marker = null;
   
    /* Get the list of files from S3 */
    ListBucketResult listResult = null;
   
    /* This do while loop deals with the paging of s3 lists */
    do
    {
      /* Get a page of results */
      listResult = listOp.getBucketObjectList(marker, getBucketName(), getPrefixName(), MAX_KEYS_PER_LIST);
     
      if (listResult.getContents() != null)
      {
        /* Process this list of keys */
        for (ListEntry listEntry : listResult.getContents())
        {
          marker = listEntry.getKey();
          restoreS3Object(listEntry.getKey());
         
        }
       
      }
         
    }
    while(listResult.isIsTruncated());
   
   
    if (this.kBytesProcessed_ > 10000)
    {
      Log.info(String.format("%.2fM transfered\n", (this.kBytesProcessed_ / 1000.0)));
View Full Code Here

          return;
        }
        else
        {
          /* Look for our prefix.  If it exists, then throw an error */
          ListBucketResult bucketList = listOperation.getBucketObjectList(null, getBucketName(), getPrefixName(), 1);
         
          if ((bucketList.getContents() != null) && (bucketList.getContents().length > 0))
          {
            Log.error("Bucket: " + getBucketName() + " Prefix: " + getPrefixName() + " already exists.\nWe cannot send data to an existing bucket:prefix, please specify a new bucket:prefix name\n");
            return;
          }
         
View Full Code Here

TOP

Related Classes of com.amazonaws.s3.doc._2006_03_01.PutObjectResult

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.