Get the dependency org.apache.jclouds.api/filesystem using jclouds Installation.
Start coding
// setup where the provider must store the filesPropertiesproperties=newProperties();properties.setProperty(FilesystemConstants.PROPERTY_BASEDIR,"./local/filesystemstorage");// setup the container name used by the provider (like bucket in S3)StringcontainerName="test-container";// get a context with filesystem that offers the portable BlobStore apiBlobStoreContextcontext=ContextBuilder.newBuilder("filesystem").overrides(properties).buildView(BlobStoreContext.class);// create a container in the default locationBlobStoreblobStore=context.getBlobStore();blobStore.createContainerInLocation(null,containerName);// add blobBlobblob=blobStore.newBlob("test");blob.setPayload("test data");blobStore.putBlob(containerName,blob);// retrieve blobBlobblobRetrieved=blobStore.getBlob(containerName,"test");// delete blobblobStore.removeBlob(containerName,"test");//close contextcontext.close();
Tips & tricks
Container is an additional subfolder appended to FilesystemConstants.PROPERTY_BASEDIR.
All blobs are stored inside this folder. So its value follows common rules for allowed directory names.
Blob key represent the name of the file stored in the filesystem. It can contains path separator.
In this case, the entire directory structure is generated, starting from the container path.
Also in this case, common rules for allowed file names must be followed.