package simplecloud.storage;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import simplecloud.storage.providers.amazon.S3Adapter;
import simplecloud.storage.providers.nirvanix.NirvanixAdapter;
import base.types.Item;

public class Example {
	
	public static void main(String[] args) {
		// Nirvanix
		try {
			NirvanixAdapter nirvanix = new NirvanixAdapter("your application name", "your application key", "your username", "your password");
			Map<Object, Object> options = new HashMap<Object, Object>();
			String localPath = "/Users/Eric/Desktop/frozen.jpg";
			String contentType = "image/jpeg";
			File file = new File(localPath);
			InputStream stream = new BufferedInputStream(new FileInputStream(file));
			Item item = new Item(stream, contentType, null, file.length());
			if (nirvanix.storeItem("/toby.jpg", item, new HashMap<String, String>(), options)) {
				System.out.println("Upload succeeded");
			} else {
				System.out.println("Upload failed");
			}
			System.out.println("Nirvanix root: ");
			options.put(NirvanixAdapter.Type.PAGE_NUMBER, "1");
			options.put(NirvanixAdapter.Type.PAGE_SIZE, "10");
			for (String name : nirvanix.listItems("/", options)) {
				System.out.println('\t' + name);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		
		// Amazon
		try {
			S3Adapter amazon = new S3Adapter("your access key id", "your access key", "s3.amazonaws.com");
			Map<Object, Object> options = new HashMap<Object, Object>();
			String localPath = "/Users/Eric/Desktop/frozen.jpg";
			String contentType = "image/jpeg";
			File file = new File(localPath);
			InputStream stream = new BufferedInputStream(new FileInputStream(file));
			Item item = new Item(stream, contentType, null, file.length());
			options.put(S3Adapter.Type.SRC_BUCKET, "ericlibcloud");
			if (amazon.storeItem("/toby.jpg", item, new HashMap<String, String>(), options)) {
				System.out.println("Upload succeeded");
			} else {
				System.out.println("Upload failed");
			}
			System.out.println("Amazon root:");
			for (String name : amazon.listItems("/", options)) {
				System.out.println('\t' + name);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}
}
