Package org.jclouds.openstack.swift.domain

Examples of org.jclouds.openstack.swift.domain.SwiftObject


   public SwiftObject apply(HttpResponse from) {
      MutableObjectInfoWithMetadata metadata = infoParser.apply(from);
      if (metadata.getHash() != null)
         from.getPayload().getContentMetadata().setContentMD5(metadata.getHash());
      SwiftObject object = objectProvider.create(metadata);
      object.getAllHeaders().putAll(from.getHeaders());
      object.setPayload(from.getPayload());
      return object;
   }
View Full Code Here


   }

   public SwiftObject apply(Blob from) {
      if (from == null)
         return null;
      SwiftObject object = objectProvider.create(blob2ObjectMd.apply(from.getMetadata()));
      object.setPayload(checkNotNull(from.getPayload(), "payload: " + from));
      object.setAllHeaders(from.getAllHeaders());
      return object;
   }
View Full Code Here

      BufferedWriter out = new BufferedWriter(new FileWriter(tempFile));
      out.write("Hello Cloud Files");
      out.close();

      SwiftObject object = swift.getApi().newSwiftObject();
      object.getInfo().setName(Constants.FILENAME + Constants.SUFFIX);
      object.setPayload(tempFile);

      swift.getApi().putObject(Constants.CONTAINER_PUBLISH, object);

      System.out.println("  " + Constants.FILENAME + Constants.SUFFIX);
   }
View Full Code Here

      BufferedWriter out = new BufferedWriter(new FileWriter(tempFile));
      out.write("uploadObjectFromFile");
      out.close();

      SwiftObject object = swift.getApi().newSwiftObject();
      object.getInfo().setName(filename + suffix);
      object.setPayload(tempFile);

      swift.getApi().putObject(Constants.CONTAINER, object);

      System.out.println("  " + filename + suffix);
   }
View Full Code Here

   private void uploadObjectFromString() {
      System.out.println("Upload Object From String");

      String filename = "uploadObjectFromString.txt";

      SwiftObject object = swift.getApi().newSwiftObject();
      object.getInfo().setName(filename);
      object.setPayload("uploadObjectFromString");

      swift.getApi().putObject(Constants.CONTAINER, object);

      System.out.println("  " + filename);
   }
View Full Code Here

         getApi().updateCDN(containerNameWithCDN, 3599L, false);
         cdnMetadata = getApi().getCDNMetadata(containerNameWithCDN);
         assertEquals(cdnMetadata.getTTL(), 3599L);
        
         // Test purging an object from a CDN container
         SwiftObject swiftObject = newSwiftObject("hello", "hello.txt");
         getApi().putObject(containerNameWithCDN, swiftObject);
        
         assertTrue(getApi().purgeCDNObject(containerNameWithCDN, swiftObject.getInfo().getName()));

         // Disable CDN with POST
         assertTrue(getApi().disableCDN(containerNameWithCDN));

         cdnMetadata = getApi().getCDNMetadata(containerNameWithCDN);
View Full Code Here

      String destinationContainer = getContainerName();
      String destinationObject = "copy.txt";
      String destinationPath = "/" + destinationContainer + "/" + destinationObject;
      String badDestination = "baddestination";
      String data = "Hello World";
      SwiftObject sourceSwiftObject = newSwiftObject(data, sourceObject);
     
      getApi().putObject(sourceContainer, sourceSwiftObject);

      // test that not giving a destination name *doesn't* copy source name to the destination container with
      // the source name but copy still returns success :(
      assertTrue(getApi().copyObject(sourceContainer, sourceObject, destinationContainer, ""));
      assertFalse(getApi().objectExists(destinationContainer, sourceObject));
     
      // test copy works
      assertTrue(getApi().copyObject(sourceContainer, sourceObject, destinationContainer, destinationObject));     
      assertTrue(getApi().objectExists(destinationContainer, destinationObject));
     
      SwiftObject destinationSwiftObject = getApi().getObject(destinationContainer, destinationObject);
      assertEquals(Strings2.toString(destinationSwiftObject.getPayload()), data);
     
      // test exception thrown on bad destination container
      try {
         assertFalse(getApi().copyObject(sourceContainer, sourceObject, badDestination, destinationObject));
         fail("Expected CopyObjectException");
View Full Code Here

       String contentType = getBlob.getPayload().getContentMetadata().getContentType();
       assert contentType.startsWith("text/plain") || "application/x-www-form-urlencoded".equals(contentType): contentType;
   }

   protected SwiftObject newSwiftObject(String data, String key) throws IOException {
      SwiftObject object = getApi().newSwiftObject();
      object.getInfo().setName(key);
      object.setPayload(data);
      Payloads.calculateMD5(object);
      object.getInfo().setContentType("text/plain");
      object.getInfo().getMetadata().put("Metadata", "metadata-value");
      return object;
   }
View Full Code Here

   @Override
   public <R extends HttpRequest> R bindToRequest(R request, Object input) {
      checkArgument(checkNotNull(input, "input") instanceof SwiftObject, "this binder is only valid for SwiftObject!");
      checkNotNull(request, "request");

      SwiftObject object = (SwiftObject) input;
      if (object.getPayload().getContentMetadata().getContentType() == null)
         object.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_OCTET_STREAM);

      if (object.getPayload().getContentMetadata().getContentLength() != null
            && object.getPayload().getContentMetadata().getContentLength() >= 0) {
         checkArgument(object.getPayload().getContentMetadata().getContentLength() <= 5l * 1024 * 1024 * 1024,
               "maximum size for put object is 5GB");
      } else {
         // Enable "chunked"/"streamed" data, where the size needn't be known in advance.
         request = (R) request.toBuilder().replaceHeader("Transfer-Encoding", "chunked").build();
      }
View Full Code Here

   public SwiftObject apply(HttpResponse from) {
      MutableObjectInfoWithMetadata metadata = infoParser.apply(from);
      if (metadata.getHash() != null)
         from.getPayload().getContentMetadata().setContentMD5(metadata.getHash());
      SwiftObject object = objectProvider.create(metadata);
      object.getAllHeaders().putAll(from.getHeaders());
      object.setPayload(from.getPayload());
      return object;
   }
View Full Code Here

TOP

Related Classes of org.jclouds.openstack.swift.domain.SwiftObject

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.