Package org.jclouds.io.payloads

Examples of org.jclouds.io.payloads.FilePayload


   public static StringPayload newStringPayload(String data) {
      return new StringPayload(checkNotNull(data, "data"));
   }

   public static FilePayload newFilePayload(File data) {
      return new FilePayload(checkNotNull(data, "data"));
   }
View Full Code Here


        return new StringPayload(str);
    }

    @Converter
    public static Payload toPayload(File file) {
        return new FilePayload(file);
    }
View Full Code Here

         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");
         is = payloadOut.openStream();
         try {
            Files.asByteSink(tmpFileOut).writeFrom(is);
         } finally {
            Closeables.closeQuietly(is);
         }
         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

   }

   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

        return new StringPayload(str);
    }

    @Converter
    public static Payload toPayload(File file) {
        return new FilePayload(file);
    }
View Full Code Here

        return new StringPayload(str);
    }

    @Converter
    public static Payload toPayload(File file) {
        return new FilePayload(file);
    }
View Full Code Here

   /**
    * @deprecated see newPayload(ByteSource)
    */
   @Deprecated
   public static FilePayload newFilePayload(File data) {
      return new FilePayload(checkNotNull(data, "data"));
   }
View Full Code Here

         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

   }

   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

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.