Package org.jclouds.io.payloads

Examples of org.jclouds.io.payloads.FilePayload


         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with none cdmi put with payload file.
         value = "Hello CDMI World non-cdmi File";
         Files.write(value, tmpFileIn, Charsets.UTF_8);
         payloadIn = new FilePayload(tmpFileIn);
         payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata()
                  .toBuilder().contentType(MediaType.PLAIN_TEXT_UTF_8.toString()).build()));

         dataNonCDMIContentTypeApi.create(dataObjectNameIn, payloadIn);
         System.out.println(containerApi.get(containerName));
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getValueAsString(), value);
         tmpFileOut = dataObject.getValueAsFile(Files.createTempDir());
         assertEquals(true, Files.equal(tmpFileOut, tmpFileIn));
         tmpFileOut.delete();
         assertEquals(dataObject.getUserMetadata().isEmpty(), true);
         System.out.println("My Metadata: " + dataObject.getUserMetadata());
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);

         payloadOut = dataNonCDMIContentTypeApi.getValue(dataObjectNameIn);
         assertNotNull(payloadOut);
         // assertEquals(Strings2.toString(payloadOut), value);
         // byte[] _bytes = ByteStreams.toByteArray(payloadOut);
         tmpFileOut = new File(Files.createTempDir(), "temp.txt");
         Files.copy(payloadOut, tmpFileOut);
         assertEquals(Files.equal(tmpFileOut, tmpFileIn), true);
         tmpFileOut.delete();

         dataNonCDMIContentTypeApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with none cdmi put with text file payload file.
         inFile = new File(System.getProperty("user.dir") + "/src/test/resources/container.json");
         assertEquals(true, inFile.isFile());
         payloadIn = new FilePayload(inFile);
         payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata()
                  .toBuilder().contentType(MediaType.JSON_UTF_8.toString()).build()));

         dataNonCDMIContentTypeApi.create(inFile.getName(), payloadIn);
         System.out.println(containerApi.get(containerName));
         dataObject = dataApi.get(inFile.getName());
         assertNotNull(dataObject);
         System.out.println(dataObject);
         // System.out.println("value: " + dataObject.getValueAsString());
         // assertEquals(dataObject.getValueAsString(), value);
         tmpFileOut = dataObject.getValueAsFile(Files.createTempDir());
         assertEquals(true, Files.equal(tmpFileOut, inFile));
         tmpFileOut.delete();
         assertEquals(dataObject.getUserMetadata().isEmpty(), true);
         // System.out.println("My Metadata: "+dataObject.getUserMetadata());
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), inFile.length());
         assertEquals(dataObject.getObjectName(), inFile.getName());
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(inFile.getName()), true);
         dataApi.delete(inFile.getName());
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with none cdmi put with text file payload file.
         // inFile = new File(System.getProperty("user.dir")
         // + "/src/test/resources/Jellyfish.jpg"); // takes too long when working from home
         inFile = new File(System.getProperty("user.dir") + "/src/test/resources/yellow-flowers.jpg");
         assertEquals(true, inFile.isFile());
         payloadIn = new FilePayload(inFile);
         payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata()
                  .toBuilder().contentType(MediaType.JPEG.toString()).build()));
         dataNonCDMIContentTypeApi.create(inFile.getName(), payloadIn);
         System.out.println(containerApi.get(containerName));
         // note dataApi.get when the data object is not a string
View Full Code Here


      assertTrue(size(strategy.execute("_default", "all")) > 0, "Expected one or more elements");
   }

   private FilePayload uploadContent(String fileName) throws Exception {
      // Define the file you want in the cookbook
      FilePayload content = Payloads.newFilePayload(new File(System.getProperty("user.dir"), fileName));
      content.getContentMetadata().setContentType("application/x-binary");

      // Get an md5 so that you can see if the server already has it or not
      Payloads.calculateMD5(content);

      // Note that java collections cannot effectively do equals or hashcodes on
      // byte arrays, so let's convert to a list of bytes.
      List<Byte> md5 = Bytes.asList(content.getContentMetadata().getContentMD5());

      // Request an upload site for this file
      UploadSandbox site = api.createUploadSandboxForChecksums(ImmutableSet.of(md5));
      assertTrue(site.getChecksums().containsKey(md5), md5 + " not in " + site.getChecksums());
View Full Code Here

      return content;
   }

   private void createCookbooksWithMultipleVersions(String cookbookName) throws Exception {
      FilePayload v0content = uploadContent("pom.xml");
      FilePayload v1content = uploadContent("../README.md");

      // Create the metadata of the cookbook
      Metadata metadata = Metadata.builder() //
            .name(cookbookName) //
            .version("0.0.0") //
View Full Code Here

   // The id of the data bag item used in search tests
   private String databagitemId;

   public void testCreateNewCookbook() throws Exception {
      // Define the file you want in the cookbook
      FilePayload content = Payloads.newFilePayload(new File(System.getProperty("user.dir"), "pom.xml"));
      content.getContentMetadata().setContentType("application/x-binary");

      // Get an md5 so that you can see if the server already has it or not
      Payloads.calculateMD5(content);

      // Note that java collections cannot effectively do equals or hashcodes on
      // byte arrays, so let's convert to a list of bytes.
      List<Byte> md5 = Bytes.asList(content.getContentMetadata().getContentMD5());

      // Request an upload site for this file
      UploadSandbox site = api.createUploadSandboxForChecksums(ImmutableSet.of(md5));
      assertTrue(site.getChecksums().containsKey(md5), md5 + " not in " + site.getChecksums());
View Full Code Here

   }

   public void testWritePayloadOnFile() throws IOException {
      String blobKey = TestUtils.createRandomBlobKey("writePayload-", ".img");
      File sourceFile = TestUtils.getImageForBlobPayload();
      FilePayload filePayload = new FilePayload(sourceFile);
      Blob blob = storageStrategy.newBlob(blobKey);
      blob.setPayload(filePayload);

      // write files
      storageStrategy.putBlob(CONTAINER_NAME, blob);
View Full Code Here

            "Files are not equal");
   }

   public void testWritePayloadOnFile_SourceFileDoesntExist() {
      File sourceFile = new File("asdfkjsadkfjasdlfasdflk.asdfasdfas");
      FilePayload payload = new FilePayload(sourceFile);
      try {
         payload.getInput();
         fail("Exception not thrown");
      } catch (Exception ex) {
         assertNotNull(Throwables2.getFirstThrowableOfType(ex, IOException.class));
      }
   }
View Full Code Here

   private String databagitemId;

   public void testCreateNewCookbook() throws Exception {
      // Define the file you want in the cookbook
      File file = new File(System.getProperty("user.dir"), "pom.xml");
      FilePayload content = Payloads.newFilePayload(file);
      content.getContentMetadata().setContentType("application/x-binary");

      // Get an md5 so that you can see if the server already has it or not
      content.getContentMetadata().setContentMD5(Files.asByteSource(file).hash(Hashing.md5()).asBytes());

      // Note that java collections cannot effectively do equals or hashcodes on
      // byte arrays, so let's convert to a list of bytes.
      List<Byte> md5 = Bytes.asList(content.getContentMetadata().getContentMD5());

      // Request an upload site for this file
      UploadSandbox site = api.createUploadSandboxForChecksums(ImmutableSet.of(md5));
      assertTrue(site.getChecksums().containsKey(md5), md5 + " not in " + site.getChecksums());
View Full Code Here

   }

   public void testWritePayloadOnFile() throws IOException {
      String blobKey = TestUtils.createRandomBlobKey("writePayload-", ".img");
      File sourceFile = TestUtils.getImageForBlobPayload();
      FilePayload filePayload = new FilePayload(sourceFile);
      Blob blob = storageStrategy.newBlob(blobKey);
      blob.setPayload(filePayload);

      // write files
      storageStrategy.putBlob(CONTAINER_NAME, blob);
View Full Code Here

   }

   public void testWritePayloadOnFile_SourceFileDoesntExist() {
      File sourceFile = new File("asdfkjsadkfjasdlfasdflk.asdfasdfas");
      try {
         new FilePayload(sourceFile);
         fail("Exception not throwed");
      } catch (Exception ex) {
      }
   }
View Full Code Here

      return putInternal(key, new StringPayload(value));
   }

   @Override
   public InputStream putFile(String key, File value) {
      return putInternal(key, new FilePayload(value));
   }
View Full Code Here

TOP

Related Classes of org.jclouds.io.payloads.FilePayload

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.