/** * Creates all directories that are part of the blobName. */ public static void mkDirs(BlobStore blobStore, String container, String blobName) { if (blobStore != null && !Strings.isNullOrEmpty(blobName) && blobName.contains("/")) { String directory = BlobStoreUtils.parseDirectoryFromPath(blobName); blobStore.createDirectory(container, directory); } }
@Override public void createDirectory(String container, String directory) { delegate().createDirectory(container, directory); }
@Override public void createDirectory(String container, String directory) { delegate().createDirectory(container, directory); }
@Override public void createDirectory(String container, String directory) { delegate().createDirectory(container, directory); }
@Override public void createDirectory(String container, String directory) { delegate().createDirectory(container, directory); }
/** * Writes to the {@link org.jclouds.blobstore.domain.Blob} using an InputStream. * * @param blobStore * @param bucket * @param blobName * @param blob * @param options */ public void write(BlobStore blobStore, String bucket, String blobName, Blob blob, PutOptions options, boolean signedRequest) throws Exception { if (blobName.contains("/")) { String directory = BlobStoreUtils.parseDirectoryFromPath(blobName); if (!Strings.isNullOrEmpty(directory)) { blobStore.createDirectory(bucket, directory); } } if (signedRequest) { BlobStoreContext context = blobStore.getContext(); HttpRequest request = context.getSigner().signPutBlob(bucket, blob); HttpClient httpClient = context.utils().http(); HttpResponse response = httpClient.invoke(request); int statusCode = response.getStatusCode(); if (statusCode != 200 && statusCode != 201) { throw new IOException(response.getStatusLine()); } } else { blobStore.putBlob(bucket, blob, options); } }
public void testDirectoryListing() { String containerName = "testDirectoryListing"; blobStore.createContainerInLocation(null, containerName); blobStore.createDirectory(containerName, "dir"); blobStore.createDirectory(containerName, "dir/dir"); PageSet<? extends StorageMetadata> results = blobStore.list(containerName); assertThat(results.size()).isEqualTo(2); assertThat(Iterables.get(results, 0).getName()).isEqualTo("dir"); assertThat(Iterables.get(results, 1).getName()).isEqualTo("dir/"); results = blobStore.list(containerName, ListContainerOptions.Builder.inDirectory("dir")); assertThat(results.size()).isEqualTo(1); assertThat(Iterables.get(results, 0).getName()).isEqualTo("dir/dir"); assertThat(Iterables.get(results, 0).getType()).isEqualTo(StorageType.FOLDER); blobStore.putBlob(containerName, blobStore.blobBuilder("dir/dir/blob").payload("").build()); results = blobStore.list(containerName, ListContainerOptions.Builder.inDirectory("dir")); assertThat(results.size()).isEqualTo(2); assertThat(Iterables.get(results, 0).getName()).isEqualTo("dir/dir"); assertThat(Iterables.get(results, 0).getType()).isEqualTo(StorageType.FOLDER); assertThat(Iterables.get(results, 1).getName()).isEqualTo("dir/dir/"); assertThat(Iterables.get(results, 1).getType()).isEqualTo(StorageType.RELATIVE_PATH); } }
try { view.getBlobStore().createDirectory(containerName, directory); addTenObjectsUnderRoot(containerName); assertEquals(rootMap.size(), 10); ImmutableSortedSet.of("0", "1", "2", "3", "4", "5", "6", "7", "8", "9")); view.getBlobStore().createDirectory(containerName, directory + "/" + directory); assertEquals(rootMap.size(), 10); assertEquals(rootRecursiveMap.size(), 20);
public void testListDirectory() { String containerName = "testListDir"; String directory = "dir"; blobStore.createContainerInLocation(null, containerName); blobStore.createDirectory(containerName, directory); blobStore.putBlob(containerName, blobStore.blobBuilder(directory + "/foo").payload("").build()); blobStore.putBlob(containerName, blobStore.blobBuilder(directory + "/bar").payload("").build()); Iterable<? extends StorageMetadata> results = concatter.execute(containerName, ListContainerOptions.NONE); assertThat(results).hasSize(2); assertThat(Iterables.get(results, 0).getName()).isEqualTo(directory); assertThat(Iterables.get(results, 0).getType()).isEqualTo(StorageType.FOLDER); assertThat(Iterables.get(results, 1).getName()).isEqualTo(directory + '/'); assertThat(Iterables.get(results, 1).getType()).isEqualTo(StorageType.RELATIVE_PATH); }
public void testDirectoryEndingWithSlash() throws InterruptedException { String containerName = getContainerName(); try { BlobStore blobStore = view.getBlobStore(); blobStore.createDirectory(containerName, "someDir"); // According to the S3 documentation, a directory is nothing but a blob // whose name ends with a '/'. So let's try to remove the blob we just // created. blobStore.removeBlob(containerName, "someDir/"); // The directory "someDir" shouldn't exist since we removed it. If this // test succeeds, it confirms that a directory (or folder) is nothing // but a blob with a name ending in '/'. assertEquals(blobStore.directoryExists(containerName, "someDir"), false); } finally { returnContainer(containerName); } } }
public void testDirectoryEndingWithSlash() throws InterruptedException { String containerName = getContainerName(); try { BlobStore blobStore = view.getBlobStore(); blobStore.createDirectory(containerName, "someDir"); // According to the S3 documentation, a directory is nothing but a blob // whose name ends with a '/'. So let's try to remove the blob we just // created. blobStore.removeBlob(containerName, "someDir/"); // The directory "someDir" shouldn't exist since we removed it. If this // test succeeds, it confirms that a directory (or folder) is nothing // but a blob with a name ending in '/'. assertEquals(blobStore.directoryExists(containerName, "someDir"), false); } finally { returnContainer(containerName); } }
/** * Create a new object in storage. An object identifier may be provided, or * a null value will try to have Fedora auto-generate the new OID. * * @param oid * the Object ID to use during creation, null is allowed * @return DigitalObject the instantiated DigitalObject created * @throws StorageException * if any errors occur */ @Override public synchronized DigitalObject createObject(String oid) throws StorageException { // log.debug("createObject({})", oid); if (oid == null) { throw new StorageException("Error; Null OID recieved"); } // Can we see object? if (BlobStoreClient.getClient().directoryExists(BlobStoreClient.getContainerName(), oid)) { throw new StorageException("Error; object '" + oid + "' already exists in Blobstore"); } BlobStoreClient.getClient().createDirectory(BlobStoreClient.getContainerName(), oid); // Instantiate and return return new BlobStoreDigitalObject(oid); }
public void testCreateListDestroySimpleDirInContainer() throws IOException { context.getBlobStore().createContainerInLocation(null, testContainerName); context.getBlobStore().createDirectory(testContainerName, "my-dir-1"); PageSet<? extends StorageMetadata> ps = context.getBlobStore().list(testContainerName); assertHasItemNamed(ps, "my-dir-1"); Blob b = context.getBlobStore().blobBuilder("my-blob-1").payload(Streams.newInputStreamWithContents("hello world")).build(); context.getBlobStore().putBlob(testContainerName+"/"+"my-dir-1", b); ps = context.getBlobStore().list(testContainerName, ListContainerOptions.Builder.inDirectory("my-dir-1")); assertHasItemNamed(ps, "my-dir-1/my-blob-1"); // both these syntaxes work: Blob b2 = context.getBlobStore().getBlob(testContainerName+"/"+"my-dir-1", "my-blob-1"); Assert.assertEquals(Streams.readFullyStringAndClose(b2.getPayload().openStream()), "hello world"); Blob b3 = context.getBlobStore().getBlob(testContainerName, "my-dir-1"+"/"+"my-blob-1"); Assert.assertEquals(Streams.readFullyStringAndClose(b3.getPayload().openStream()), "hello world"); context.getBlobStore().deleteContainer(testContainerName); }
view.getBlobStore().createDirectory(containerName, directory); view.getBlobStore().createDirectory(containerName, directory + "/" + directory); assertThat(container).hasSize(0); view.getBlobStore().createDirectory(containerName, directory + "/" + directory);
view.getBlobStore().createDirectory(containerName, directory); view.getBlobStore().createDirectory(containerName, directory + "/" + directory); assert view.getBlobStore().directoryExists(containerName, directory + "/" + directory); assert container.size() == 1 : container; view.getBlobStore().createDirectory(containerName, directory + "/" + directory);