Examples of PCSFile


Examples of org.jclouds.mezeo.pcs.domain.PCSFile

      String data = "Here is my data";

      URI container = connection.createContainer(containerName);

      // Test PUT with string data, ETag hash, and a piece of metadata
      PCSFile object = connection.newFile();
      object.getMetadata().setName("object");
      object.getMetadata().setMimeType("text/plain");
      object.setPayload(data);
      URI objectURI = connection.uploadFile(container, object);
      connection.putMetadataItem(objectURI, "name", "object");

      try {
         connection.downloadFile(uriBuilderProvider.get().uri(objectURI).path("sad").build());
         fail("Expected KeyNotFoundException");
      } catch (KeyNotFoundException e) {
      }
      // Test GET of object (including updated metadata)
      InputStream file = connection.downloadFile(objectURI);
      assertEquals(Strings2.toStringAndClose(file), data);
      validateFileInfoAndNameIsInMetadata(container, objectURI, "object", Long.valueOf(data.length()));

      try {
         connection.uploadFile(container, object);
      } catch (Throwable e) {
         assertEquals(e.getCause().getClass(), HttpResponseException.class);
         assertEquals(((HttpResponseException) e.getCause()).getResponse().getStatusCode(), 422);
      }

      connection.deleteFile(objectURI);
      try {
         connection.getFileInfo(objectURI);
      } catch (Throwable e) {
         assertEquals(e.getClass(), KeyNotFoundException.class);
      }

      String name = "sad";
      // try sending it in 2 parts
      object.getMetadata().setName(name);
      objectURI = connection.createFile(container, object);
      validateFileInfoAndNameIsInMetadata(container, objectURI, name, Long.valueOf(0));

      object.setPayload(data.substring(0, 2));
      connection.uploadBlock(objectURI, object, range(0, 2));
      validateFileInfoAndNameIsInMetadata(container, objectURI, name, Long.valueOf(2));

      object.setPayload(data.substring(2));
      connection.uploadBlock(objectURI, object, range(2, data.getBytes().length));
      validateFileInfoAndNameIsInMetadata(container, objectURI, name, Long.valueOf(data.length()));

      file = connection.downloadFile(objectURI);
      assertEquals(Strings2.toStringAndClose(file), data);

      // change data in an existing file
      data = "Here is my datum";
      object.setPayload(data.substring(2));
      connection.uploadBlock(objectURI, object, range(2, data.getBytes().length));
      validateFileInfoAndNameIsInMetadata(container, objectURI, name, Long.valueOf(data.length()));

      file = connection.downloadFile(objectURI);
      assertEquals(Strings2.toStringAndClose(file), data);
View Full Code Here

Examples of org.jclouds.mezeo.pcs.domain.PCSFile

      this.file2Blob = file2Blob;
   }

   @Override
   public <R extends HttpRequest> R bindToRequest(R request, Object input) {
      PCSFile file = (PCSFile) input;
      checkNotNull(file.getPayload().getContentMetadata().getContentLength(), "contentLength");
      checkArgument(file.getPayload().getContentMetadata().getContentLength() <= 2l * 1024 * 1024 * 1024,
            "maximum size for POST request is 2GB");
      return blobBinder.bindToRequest(request, file2Blob.apply(file));
   }
View Full Code Here

Examples of org.jclouds.mezeo.pcs.domain.PCSFile

@Singleton
public class BindFileInfoToXmlPayload implements Binder {

   @Override
   public <R extends HttpRequest> R bindToRequest(R request, Object input) {
      PCSFile blob = (PCSFile) input;
      String file = String.format("<file><name>%s</name><mime_type>%s</mime_type><public>false</public></file>",
            new File(blob.getMetadata().getName()).getName(), blob.getMetadata().getMimeType());
      request.setPayload(file);
      return ModifyRequest.replaceHeaders(request, ImmutableMultimap.<String, String> of(HttpHeaders.CONTENT_LENGTH,
            file.getBytes().length + "", HttpHeaders.CONTENT_TYPE, "application/vnd.csp.file-info+xml"));
   }
View Full Code Here

Examples of org.jclouds.mezeo.pcs.domain.PCSFile

      this.blob2ObjectMd = blob2ObjectMd;
      this.objectProvider = objectProvider;
   }

   public PCSFile apply(Blob from) {
      PCSFile object = objectProvider.create(blob2ObjectMd.apply(from.getMetadata()));
      object.setPayload(from.getPayload());
      object.setAllHeaders(from.getAllHeaders());
      return object;
   }
View Full Code Here

Examples of org.jclouds.mezeo.pcs.domain.PCSFile

   PCSFile.Factory factory = Guice.createInjector(new PCSObjectModule()).getInstance(PCSFile.Factory.class);

   public void test() {
      BindFileInfoToXmlPayload binder = new BindFileInfoToXmlPayload();
      HttpRequest request = new HttpRequest("GET", URI.create("http://localhost"));
      PCSFile file = factory.create(null);
      file.getMetadata().setName("foo");
      request = binder.bindToRequest(request, file);
      assertEquals(request.getPayload().getRawContent(),
            "<file><name>foo</name><mime_type>application/octet-stream</mime_type><public>false</public></file>");
      assertEquals(
            request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH),
View Full Code Here

Examples of org.jclouds.mezeo.pcs.domain.PCSFile

   public void testCompound() {
      BindFileInfoToXmlPayload binder = new BindFileInfoToXmlPayload();
      HttpRequest request = new HttpRequest("GET", URI.create("http://localhost"));

      PCSFile file = factory.create(null);
      file.getMetadata().setName("subdir/foo");
      request = binder.bindToRequest(request, file);
      assertEquals(request.getPayload().getRawContent(),
            "<file><name>foo</name><mime_type>application/octet-stream</mime_type><public>false</public></file>");
      assertEquals(
            request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH),
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.