Package com.rackspacecloud.client.cloudfiles

Examples of com.rackspacecloud.client.cloudfiles.FilesClient


        String fullPath = FilenameUtils.concat(SYSTEM_TMP.getAbsolutePath(),
                                               filename);
        logger.info("Test Copy File Location: " + fullPath);
        try {
            byte randomData[] = makeRandomFile(fullPath);
            FilesClient client = new FilesClient();
            assertTrue(client.login());

            // Set up
            client.createContainer(containerSrc);
            if (null != containerDest && !containerSrc.equals(containerDest)) {
                client.createContainer(containerDest);
            }

            // Store it
            logger.info("About to save: " + filename);
            String mime = "application/octet-stream";
            assertNotNull(client.storeObjectAs(containerSrc,
                                               new File(fullPath),
                                               mime,
                                               filename));

            verifyStoredObject(containerSrc,
                               filename,
                               mime,
                               randomData,
                               client);

            // Do the copy
            logger.info("About to copy: " + filename);
            String dest = null == containerDest ? "not-exist" : containerDest;
            String etag = client.copyObject(containerSrc,
                                            filename,
                                            dest,
                                            filename);

            String md5 = FilesClient.md5Sum(randomData);
            assertEquals(md5, etag);

            verifyStoredObject(containerDest,
                               filename,
                               mime,
                               randomData,
                               client);

            // Clean up
            client.deleteObject(containerSrc, filename);
            assertTrue(client.deleteContainer(containerSrc));
            if (null != containerDest && !containerSrc.equals(containerDest)) {
                client.deleteObject(containerDest, filename);
                assertTrue(client.deleteContainer(containerDest));
            }

        } catch (FilesException fe) {
            System.err.println(fe.getHttpHeadersAsString());
            System.err.println(fe.getHttpStatusMessage());
View Full Code Here


    String filename = makeFileName("<object>");
    String fullPath = FilenameUtils.concat(SYSTEM_TMP.getAbsolutePath(), filename);
    logger.info("Test File Location: " + fullPath);
    try {
      byte randomData[] = makeRandomFile(fullPath);
      FilesClient client = new FilesClient();
      assertTrue(client.login());
     
      // Set up
      client.createContainer(containerName);
     
      // Store it
      logger.info("About to save: " + filename);
      assertNotNull(client.storeObjectAs(containerName, new File(fullPath), "application/octet-stream", filename));
     
      // Make sure it's there
      List<FilesObject> objects = client.listObjects(containerName);
      assertEquals(1, objects.size());
      FilesObject obj = objects.get(0);
      assertEquals(filename, obj.getName());
      assertEquals("application/octet-stream", obj.getMimeType());
      assertEquals(NUMBER_RANDOM_BYTES, obj.getSize());
      assertEquals(md5Sum(randomData), obj.getMd5sum());
     
      // Make sure the data is correct
      assertArrayEquals(randomData, client.getObject(containerName, filename));
     
      // Make sure the data is correct as a stream
      InputStream is = client.getObjectAsStream(containerName, filename);
      byte otherData[] = new byte[NUMBER_RANDOM_BYTES];
      is.read(otherData);
      assertArrayEquals(randomData, otherData);
      assertEquals(-1, is.read()); // Could hang if there's a bug on the other end
     
      // Clean up
      client.deleteObject(containerName, filename);
      assertTrue(client.deleteContainer(containerName));
     
    }
    catch (Exception e) {
      fail(e.getMessage());
    }
View Full Code Here

  public void testContainerListingWithXML() {
    String containerName = createTempContainerName("<container>");
    String filename = makeFileName("</name></object>");
    try {
      byte randomData[] = makeRandomBytes();
      FilesClient client = new FilesClient();
      assertTrue(client.login());
     
      // Set up
      client.createContainer(containerName);
     
      // Store it
      logger.info("About to save: " + filename);
      assertTrue(client.storeObject(containerName, randomData, "application/octet-stream", filename, new HashMap<String,String>()));
       
      // Make sure it's there
      List<FilesObject> objects = client.listObjects(containerName);
      assertEquals(1, objects.size());
      FilesObject obj = objects.get(0);
      assertEquals(filename, obj.getName());
      assertEquals("application/octet-stream", obj.getMimeType());
      assertEquals(NUMBER_RANDOM_BYTES, obj.getSize());
      assertEquals(md5Sum(randomData), obj.getMd5sum());
     
      // Make sure the data is correct
      assertArrayEquals(randomData, client.getObject(containerName, filename));
     
      // Make sure the data is correct as a stream
      InputStream is = client.getObjectAsStream(containerName, filename);
      byte otherData[] = new byte[NUMBER_RANDOM_BYTES];
      is.read(otherData);
      assertArrayEquals(randomData, otherData);
      assertEquals(-1, is.read()); // Could hang if there's a bug on the other end
     
      // Clean up
      client.deleteObject(containerName, filename);
      assertTrue(client.deleteContainer(containerName));
     
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
View Full Code Here

  public void testByteArraySaving() {
    String containerName = createTempContainerName("byte-array");
    String filename = makeFileName("bytearray");
    try {
      byte randomData[] = makeRandomBytes();
      FilesClient client = new FilesClient();
      // client.setUseETag(false);
      assertTrue(client.login());
     
      // Set up
      client.createContainer(containerName);
     
      // Store it
      assertTrue(client.storeObject(containerName, randomData, "application/octet-stream", filename, new HashMap<String,String>()));
     
      // Make sure it's there
      List<FilesObject> objects = client.listObjects(containerName);
      assertEquals(1, objects.size());
      FilesObject obj = objects.get(0);
      assertEquals(filename, obj.getName());
      assertEquals("application/octet-stream", obj.getMimeType());
     
      // Make sure the data is correct
      assertArrayEquals(randomData, client.getObject(containerName, filename));
     
      // Make sure the data is correct as a stream
      InputStream is = client.getObjectAsStream(containerName, filename);
      byte otherData[] = new byte[NUMBER_RANDOM_BYTES];
      is.read(otherData);
      assertArrayEquals(randomData, otherData);
      assertEquals(-1, is.read()); // Could hang if there's a bug on the other end
     
      // Clean up
      client.deleteObject(containerName, filename);
      assertTrue(client.deleteContainer(containerName));
     
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
View Full Code Here

  public void testLineNoiseSaving() {
    String containerName = createTempContainerName("[]<>{}!@#$%^&*()_-+=|,.?");
    String filename = makeFileName("/[]<>{}!@#$%^&*()_-+=|,.?/");
    try {
      byte randomData[] = makeRandomBytes();
      FilesClient client = new FilesClient();
      // client.setUseETag(false);
      assertTrue(client.login());

      // Set up
      client.createContainer(containerName);
     
      // Store it
      assertTrue(client.storeObject(containerName, randomData, "application/octet-stream", filename, new HashMap<String,String>()));
     
      // Make sure it's there
      List<FilesObject> objects = client.listObjects(containerName);
      assertEquals(1, objects.size());
      FilesObject obj = objects.get(0);
      assertEquals(filename, obj.getName());
      assertEquals("application/octet-stream", obj.getMimeType());
     
      // Make sure the data is correct
      assertArrayEquals(randomData, client.getObject(containerName, filename));
     
      // Make sure the data is correct as a stream
      InputStream is = client.getObjectAsStream(containerName, filename);
      byte otherData[] = new byte[NUMBER_RANDOM_BYTES];
      is.read(otherData);
      assertArrayEquals(randomData, otherData);
      assertEquals(-1, is.read()); // Could hang if there's a bug on the other end
     
      // Clean up
      client.deleteObject(containerName, filename);
      assertTrue(client.deleteContainer(containerName));
     
    }
    catch (Exception e) {
      logger.error("LGV: LINE NOISE", e);
      e.printStackTrace();
View Full Code Here

      byte randomData[] = makeRandomBytes();
     
      while(zeroStripMd5Sum(randomData).length() ==32) {
        randomData = makeRandomBytes();
      }
      FilesClient client = new FilesClient();
      // client.setUseETag(false);
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
     
      // Set up
      client.createContainer(containerName);
     
      // Store it
      assertTrue(client.storeObject(containerName, randomData, "application/octet-stream", filename, new HashMap<String,String>()));
     
      // Make sure it's there
      List<FilesObject> objects = client.listObjects(containerName);
      assertEquals(1, objects.size());
      FilesObject obj = objects.get(0);
      assertEquals(filename, obj.getName());
      assertEquals("application/octet-stream", obj.getMimeType());
     
      // Make sure the data is correct
      assertArrayEquals(randomData, client.getObject(containerName, filename));
     
      // Make sure the data is correct as a stream
      InputStream is = client.getObjectAsStream(containerName, filename);
      byte otherData[] = new byte[NUMBER_RANDOM_BYTES];
      is.read(otherData);
      assertArrayEquals(randomData, otherData);
      assertEquals(-1, is.read()); // Could hang if there's a bug on the other end
     
      // Clean up
      client.deleteObject(containerName, filename);
      assertTrue(client.deleteContainer(containerName));
     
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
View Full Code Here

    }
     
  public void testUnicodeContainer() {
    String containerName = createTempContainerName("\u0169\u00f1\u00efcode-test-\u03de");
    try {
      FilesClient client = new FilesClient(FilesUtil.getProperty("username"), FilesUtil.getProperty("password"), FilesUtil.getProperty("account"));
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
     
      // Set up
      client.createContainer(containerName);
     
     
      // Make sure it's there
      assertTrue(client.containerExists(containerName));

      // Make sure we can get the container info
      assertNotNull(client.getContainerInfo(containerName));
     
      // Clean up
      assertTrue(client.deleteContainer(containerName));
     
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
View Full Code Here

    filename = makeFileName("\u00f1\u00efcode-test-\u03de");
    String fullPath = FilenameUtils.concat(SYSTEM_TMP.getAbsolutePath(), filename);
    logger.info("Test File Location: " + fullPath);
    try {
      byte randomData[] = makeRandomFile(fullPath);
      FilesClient client = new FilesClient(FilesUtil.getProperty("username"), FilesUtil.getProperty("password"), FilesUtil.getProperty("account"));
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
     
      // Set up
      client.createContainer(containerName);
     
      // Store it
      assertNotNull(client.storeObjectAs(containerName, new File(fullPath), "application/octet-stream", filename));
     
      // Make sure it's there
      List<FilesObject> objects = client.listObjects(containerName);
      assertEquals(1, objects.size());
      FilesObject obj = objects.get(0);
      assertEquals(filename, obj.getName());
      assertEquals("application/octet-stream", obj.getMimeType());
     
      assertNotNull(obj.getMetaData());
     
      // Make sure the data is correct
      assertArrayEquals(randomData, client.getObject(containerName, filename));
     
      // Make sure the data is correct as a stream
      InputStream is = client.getObjectAsStream(containerName, filename);
      byte otherData[] = new byte[NUMBER_RANDOM_BYTES];
      is.read(otherData);
      assertArrayEquals(randomData, otherData);
      assertEquals(-1, is.read()); // Could hang if there's a bug on the other end
     
      // Make sure we can get the container info
      assertNotNull(client.getContainerInfo(containerName));
     
      // Clean up
      client.deleteObject(containerName, filename);
      assertTrue(client.deleteContainer(containerName));
     
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
View Full Code Here

    }
   
  }
 
  public void testCDNContainerList() {
    FilesClient client = new FilesClient();
    try {
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
     
      List<String> containers = client.listCdnContainers();
      assertTrue(containers.size() > 0);
    } catch (Exception e) {
      fail(e.getMessage());
    }
  }
View Full Code Here

      fail(e.getMessage());
    }
  }
 
  public void testCDNContainerListLimitMarker() {
    FilesClient client = new FilesClient();
    try {
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
           
      List<String> originalContainers = client.listCdnContainers();
      assertTrue(originalContainers.size() > 0);
     
      // Now do a limit
      List<String> containers = client.listCdnContainers(5);
      assertEquals(5, containers.size());
      for (int i=0; i < 5; i++) {
        assertEquals(originalContainers.get(i), containers.get(i));
      }
     
      // Now check out a marker
      containers = client.listCdnContainers(10, originalContainers.get(originalContainers.size() - 5));
      assertEquals(4, containers.size());
      for (int i=0; i < 2; i++) {
        assertEquals(originalContainers.get(originalContainers.size() - 4 + i), containers.get(i));
      }
    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of com.rackspacecloud.client.cloudfiles.FilesClient

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.