// Path: src/main/java/com/kolich/havalo/entities/StoreableEntity.java
// public abstract class StoreableEntity extends HavaloFileEntity {
// 	
// 	public StoreableEntity(String name) {
// 		super(name);
// 	}
// 		
// 	public abstract String getKey();
// 	
// }
// 
// Path: src/main/java/com/kolich/havalo/exceptions/objects/ObjectFlushException.java
// public class ObjectFlushException extends HavaloException {
// 
// 	private static final long serialVersionUID = 3980139747975745999L;
// 
// 	public ObjectFlushException(String message, Exception cause) {
// 		super(SC_PRECONDITION_FAILED, message, cause);
// 	}
// 	
// 	public ObjectFlushException(Exception cause) {
// 		super(SC_PRECONDITION_FAILED, cause);
// 	}
// 	
// 	public ObjectFlushException(String message) {
// 		super(SC_PRECONDITION_FAILED, message);
// 	}
// 	
// }
// 
// Path: src/main/java/com/kolich/havalo/exceptions/objects/ObjectLoadException.java
// public class ObjectLoadException extends HavaloException {
// 
// 	private static final long serialVersionUID = 4875646775404503031L;
// 
// 	public ObjectLoadException(String message, Exception cause) {
// 		super(SC_SERVICE_UNAVAILABLE, message, cause);
// 	}
// 	
// 	public ObjectLoadException(Exception cause) {
// 		super(SC_SERVICE_UNAVAILABLE, cause);
// 	}
// 	
// 	public ObjectLoadException(String message) {
// 		super(SC_SERVICE_UNAVAILABLE, message);
// 	}
// 	
// }
// 
// Path: src/main/java/com/kolich/havalo/io/MetaStore.java
// public interface MetaStore {
// 		
// 	public InputStream getInputStream(final String index);
// 	
// 	public void save(final StoreableEntity entity);
// 	
// 	public void delete(final String index);
// 
// }


import java.io.*;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import static com.kolich.common.DefaultCharacterEncoding.UTF_8;
import static java.util.zip.Deflater.BEST_COMPRESSION;
import static org.apache.commons.io.FileUtils.deleteQuietly;
import static org.apache.commons.io.IOUtils.closeQuietly;
import com.kolich.havalo.entities.StoreableEntity;
import com.kolich.havalo.exceptions.objects.ObjectFlushException;
import com.kolich.havalo.exceptions.objects.ObjectLoadException;
import com.kolich.havalo.io.MetaStore;

			fos = new FileOutputStream(getCanonicalFile(entity));
			gos = new GZIPOutputStream(fos) {
				// Ugly anonymous constructor hack to set the compression
				// level on the underlying Deflater to "max compression".
				{ def.setLevel(BEST_COMPRESSION); }
			};
			writer = new OutputStreamWriter(gos, UTF_8);
			// Call the entity to write itself to the output stream.
			entity.toWriter(writer);
			writer.flush(); // Muy importante
			gos.finish(); // Muy importante mucho!
		} catch (Exception e) {
			throw new ObjectFlushException("Failed to save entity: " +
				entity.getKey(), e);
		} finally {
			closeQuietly(writer);
			closeQuietly(gos);
			closeQuietly(fos);
		}
	}
	
	@Override
	public void delete(final String index) {
		try {
			// Actually attempt to delete it, or report failure.
			if(!deleteQuietly(getCanonicalFile(index, false))) {
				throw new IOException("Deletion of index " + index +
					" failed.");
			}
		} catch (Exception e) {

// Path: src/main/java/com/kolich/havalo/entities/StoreableEntity.java
// public abstract class StoreableEntity extends HavaloFileEntity {
// 	
// 	public StoreableEntity(String name) {
// 		super(name);
// 	}
// 		
// 	public abstract String getKey();
// 	
// }
// 
// Path: src/main/java/com/kolich/havalo/exceptions/objects/ObjectFlushException.java
// public class ObjectFlushException extends HavaloException {
// 
// 	private static final long serialVersionUID = 3980139747975745999L;
// 
// 	public ObjectFlushException(String message, Exception cause) {
// 		super(SC_PRECONDITION_FAILED, message, cause);
// 	}
// 	
// 	public ObjectFlushException(Exception cause) {
// 		super(SC_PRECONDITION_FAILED, cause);
// 	}
// 	
// 	public ObjectFlushException(String message) {
// 		super(SC_PRECONDITION_FAILED, message);
// 	}
// 	
// }
// 
// Path: src/main/java/com/kolich/havalo/exceptions/objects/ObjectLoadException.java
// public class ObjectLoadException extends HavaloException {
// 
// 	private static final long serialVersionUID = 4875646775404503031L;
// 
// 	public ObjectLoadException(String message, Exception cause) {
// 		super(SC_SERVICE_UNAVAILABLE, message, cause);
// 	}
// 	
// 	public ObjectLoadException(Exception cause) {
// 		super(SC_SERVICE_UNAVAILABLE, cause);
// 	}
// 	
// 	public ObjectLoadException(String message) {
// 		super(SC_SERVICE_UNAVAILABLE, message);
// 	}
// 	
// }
// 
// Path: src/main/java/com/kolich/havalo/io/MetaStore.java
// public interface MetaStore {
// 		
// 	public InputStream getInputStream(final String index);
// 	
// 	public void save(final StoreableEntity entity);
// 	
// 	public void delete(final String index);
// 
// }


// Path: src/main/java/com/kolich/havalo/io/stores/MetaObjectStore.java
import java.io.*;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import static com.kolich.common.DefaultCharacterEncoding.UTF_8;
import static java.util.zip.Deflater.BEST_COMPRESSION;
import static org.apache.commons.io.FileUtils.deleteQuietly;
import static org.apache.commons.io.IOUtils.closeQuietly;
import com.kolich.havalo.entities.StoreableEntity;
import com.kolich.havalo.exceptions.objects.ObjectFlushException;
import com.kolich.havalo.exceptions.objects.ObjectLoadException;
import com.kolich.havalo.io.MetaStore;

			fos = new FileOutputStream(getCanonicalFile(entity));
			gos = new GZIPOutputStream(fos) {
				// Ugly anonymous constructor hack to set the compression
				// level on the underlying Deflater to "max compression".
				{ def.setLevel(BEST_COMPRESSION); }
			};
			writer = new OutputStreamWriter(gos, UTF_8);
			// Call the entity to write itself to the output stream.
			entity.toWriter(writer);
			writer.flush(); // Muy importante
			gos.finish(); // Muy importante mucho!
		} catch (Exception e) {
			throw new ObjectFlushException("Failed to save entity: " +
				entity.getKey(), e);
		} finally {
			closeQuietly(writer);
			closeQuietly(gos);
			closeQuietly(fos);
		}
	}
	
	@Override
	public void delete(final String index) {
		try {
			// Actually attempt to delete it, or report failure.
			if(!deleteQuietly(getCanonicalFile(index, false))) {
				throw new IOException("Deletion of index " + index +
					" failed.");
			}
		} catch (Exception e) {

			throw new ObjectFlushException("Failed to delete entity: " +
