예제 #1
0
 @Test
 public void listObjectsPaged() {
   container.getObject("A").uploadObject(new byte[] {});
   container.getObject("B").uploadObject(new byte[] {});
   StoredObject object3 = container.getObject("C");
   object3.uploadObject(new byte[] {});
   StoredObject object4 = container.getObject("D");
   object4.uploadObject(new byte[] {});
   Collection<StoredObject> objects = container.list(null, "B", 2);
   assertEquals(2, objects.size());
   objects.contains(object3);
   objects.contains(object4);
 }
예제 #2
0
 @Test
 public void listContainersUsePaginationMap() {
   container.getObject("A").uploadObject(new byte[] {});
   container.getObject("B").uploadObject(new byte[] {});
   StoredObject object3 = container.getObject("C");
   object3.uploadObject(new byte[] {});
   StoredObject object4 = container.getObject("D");
   object4.uploadObject(new byte[] {});
   PaginationMap paginationMap = container.getPaginationMap(2);
   Collection<StoredObject> objects = container.list(paginationMap, 1);
   assertEquals(2, objects.size());
   objects.contains(object3);
   objects.contains(object4);
 }
예제 #3
0
 @Test
 public void uploadFromByteArray() throws IOException {
   expectStatusCode(201);
   this.bytes = new byte[] {0x01, 0x02, 0x03, 0x04, 0x05};
   object.uploadObject(this.bytes);
   verifyUploadContent(this.bytes);
 }
예제 #4
0
 @Test
 public void deleteObject() throws IOException {
   object.uploadObject(new byte[] {});
   assertEquals(1, container.list().size());
   object.delete();
   assertEquals(0, container.list().size());
 }
예제 #5
0
  // https://github.com/javaswift/joss/blob/master/src/main/java/org/javaswift/joss/model/StoredObject.java
  @Override
  public void storeFile(MultipartFile myFile, String fileId, int fileTTL) throws IOException {
    if (swiftUsername == null) {
      System.out.println("Swift username is not configured");
    }
    assert swiftUsername != null;
    if (config == null) {
      login();
    }
    StoredObject swiftObject = container.getObject(fileId);
    swiftObject.uploadObject(myFile.getInputStream());
    if (myFile.getContentType() != null) {
      swiftObject.setContentType(myFile.getContentType());
    }

    Map<String, Object> metadata = new HashMap<String, Object>();
    if (myFile.getOriginalFilename() != null) {
      metadata.put("filename", myFile.getOriginalFilename());
    }
    if (myFile.getContentType() != null) {
      metadata.put("content-type", myFile.getContentType());
    }
    swiftObject.setMetadata(metadata);
    swiftObject.saveMetadata();
    // swiftObject.setDeleteAt(Date date);
  }
예제 #6
0
 @Test
 public void uploadFromFile() throws IOException {
   OutputStream outputStream = new FileOutputStream(downloadedFile);
   IOUtils.write(this.bytes, outputStream);
   outputStream.close();
   expectStatusCode(201);
   object.uploadObject(downloadedFile);
   verifyUploadContent(this.bytes);
 }
예제 #7
0
 @Test
 public void getObject() throws IOException {
   StoredObject object1 = container.getObject("some-object");
   assertFalse(object1.exists());
   object1.uploadObject(new byte[] {0x01});
   StoredObject object2 = container.getObject("some-object");
   assertEquals(object1, object2);
   assertTrue(object1.exists());
 }
예제 #8
0
 protected void addObject(String name, byte[] bytes) throws IOException {
   StoredObject object = container.getObject(name);
   object.uploadObject(bytes);
 }