import java.io.FileInputStream;
import java.io.IOException;
import java.util.UUID;
import com.cloudvane.ossc.CloudStorageClient;
import com.cloudvane.ossc.infrastructure.CloudDirectory;
import com.cloudvane.ossc.infrastructure.CloudObject;
public class Main {
/**
* @param args
* @throws IOException
* @throws ClassNotFoundException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws ConfigurationException
*/
public static void main(String[] args) throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
FileInputStream stream = new FileInputStream("ossc.config");
CloudStorageClient c = new CloudStorageClient(stream);
c.getClient().addConfigSetting("Path", "store");
System.out.println("Tests");
System.out.println("");
CloudDirectory ncd = new CloudDirectory();
ncd.setDirectoryName("New Directory");
c.getClient().createDirectory(ncd);
listDirectories(c, "List directories");
CloudObject obj = new CloudObject();
obj.setFileName(UUID.randomUUID().toString() + ".txt");
obj.setCloudObject(new FileInputStream("ossc.config"));
obj.setDirectoryName(c.getClient().getFullPath(ncd));
c.getClient().createObject(ncd, obj);
listDirectories(c, "Now with a file");
c.getClient().deleteObject(obj);
listDirectories(c, "Now cleaned again");
c.getClient().deleteDirectory(ncd);
listDirectories(c, "Now deleted the directory");
}
private static void listDirectories(CloudStorageClient c, String header) {
if(!header.isEmpty()) {
System.out.println("\n");
System.out.println(header);
System.out.println("##############################");
}
for(CloudDirectory dir : c.getClient().listDirectories()) {
System.out.println(dir.getDirectoryName());
for(CloudObject obj : c.getClient().listObjectsInDirectory(dir)) {
System.out.println(" - " + obj.getFileName());
}
}
}
}