Examples of InputStreamPayload


Examples of org.jclouds.io.payloads.InputStreamPayload

         // exercise create data object with none cdmi put with payload inputStream riginating from
         // string.
         value = "Hello CDMI World non-cdmi inputStream originating from string";
         is = new ByteArrayInputStream(value.getBytes());
         payloadIn = new InputStreamPayload(is);
         payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata()
                  .toBuilder().contentType(MediaType.PLAIN_TEXT_UTF_8.toString())
                  .contentLength(new Long(value.length())).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);
         assertNotNull(dataObject.getValueAsInputSupplier());
         assertEquals(CharStreams.toString(CharStreams.newReaderSupplier(
                  dataObject.getValueAsInputSupplier(Charsets.UTF_8), Charsets.UTF_8)), value);
         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);
         dataNonCDMIContentTypeApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with none cdmi put with payload inputStream originating from
         // jpeg file.
         inFile = new File(System.getProperty("user.dir") + "/src/test/resources/yellow-flowers.jpg");
         assertEquals(true, inFile.isFile());
         FileInputStream fileInputStream = new FileInputStream(inFile);
         payloadIn = new InputStreamPayload(fileInputStream);
         payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata()
                  .toBuilder().contentType(MediaType.JPEG.toString()).contentLength(new Long(inFile.length())).build()));
         dataNonCDMIContentTypeApi.create(inFile.getName(), payloadIn);
         System.out.println(containerApi.get(containerName));
         payloadOut = dataNonCDMIContentTypeApi.getValue(inFile.getName());
View Full Code Here

Examples of org.jclouds.io.payloads.InputStreamPayload

        return payload;
    }

    @Converter
    public static Payload toPayload(InputStream is, Exchange exchange) throws IOException {
        InputStreamPayload payload = new InputStreamPayload(is);
        // only set the contentlength if possible
        if (is.markSupported()) {
            long contentLength = ByteStreams.length(payload);
            is.reset();
            payload.getContentMetadata().setContentLength(contentLength);
        }
        return payload;
    }
View Full Code Here

Examples of org.jclouds.io.payloads.InputStreamPayload

            public InputStream getInput() throws IOException {
                return cache.getInputStream();
            }
        });
        cache.reset();
        InputStreamPayload payload = new InputStreamPayload(cache.getInputStream());
        payload.getContentMetadata().setContentLength(contentLength);
        setContentMetadata(payload, exchange);
        return payload;
    }
View Full Code Here

Examples of org.jclouds.io.payloads.InputStreamPayload

   }

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

      // write files
View Full Code Here

Examples of org.jclouds.io.payloads.InputStreamPayload

   }

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

      // write files
View Full Code Here

Examples of org.jclouds.io.payloads.InputStreamPayload

      try {
         ByteStreams.skipFully(content, offset);
      } catch (IOException ioe) {
         throw Throwables.propagate(ioe);
      }
      return new InputStreamPayload(ByteStreams.limit(content, length));
   }
View Full Code Here

Examples of org.jclouds.io.payloads.InputStreamPayload

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

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

Examples of org.jclouds.io.payloads.InputStreamPayload

         throw new UnsupportedOperationException("unsupported payload type: " + data.getClass());
      }
   }

   public static InputStreamPayload newInputStreamPayload(InputStream data) {
      return new InputStreamPayload(checkNotNull(data, "data"));
   }
View Full Code Here

Examples of org.jclouds.io.payloads.InputStreamPayload

    }

    @Converter
    public static Payload toPayload(InputStream is, Exchange exchange) throws IOException {
        if (is.markSupported()) {
            InputStreamPayload payload = new InputStreamPayload(is);
            long contentLength = ByteStreams.length(payload);
            is.reset();
            payload.getContentMetadata().setContentLength(contentLength);
            return payload;
        } else {
            CachedOutputStream cos = new CachedOutputStream(exchange);
            return toPayload(cos.getWrappedInputStream(), exchange);
        }
View Full Code Here

Examples of org.jclouds.io.payloads.InputStreamPayload

            public InputStream getInput() throws IOException {
                return cache.getInputStream();
            }
        });
        cache.reset();
        InputStreamPayload payload = new InputStreamPayload(cache.getInputStream());
        payload.getContentMetadata().setContentLength(contentLength);
        return payload;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.