// Path: osgi.enroute.examples.backend.application/src/osgi/enroute/examples/backend/api/Backend.java
// public interface Backend {
// 	String TYPE = "type";
// 
// 	/**
// 	 * Save a blob
// 	 * 
// 	 * @param name
// 	 *            The name of the blob
// 	 * @param data
// 	 *            The actual data
// 	 * @return the meta data describing the details of the store
// 	 */
// 	MetaData save(String name, byte[] data) throws Exception;
// 
// 	/**
// 	 * Read the blob with the given name.
// 	 * 
// 	 * @param name
// 	 *            The name of the resource
// 	 * @return the data
// 	 */
// 	byte[] read(String name) throws Exception;
// 
// 	/**
// 	 * Return a list of the meta data of what the store has.
// 	 * 
// 	 * @return The list
// 	 */
// 	Collection<? extends MetaData> list() throws Exception;
// 
// 	/**
// 	 * Delete a blob
// 	 * 
// 	 * @param name
// 	 *            The name of the blob
// 	 * @return true if deleted, false if could not be deleted (might not exist)
// 	 */
// 	boolean delete(String name) throws Exception;
// }
// 
// Path: osgi.enroute.examples.backend.application/src/osgi/enroute/examples/backend/api/MetaData.java
// public class MetaData extends DTO {
// 	/**
// 	 * The name of the blob
// 	 */
// 	public String name;
// 
// 	/**
// 	 * The size of the blob
// 	 */
// 	public long size;
// 
// 	/**
// 	 * The epoch time when it was last modified.
// 	 */
// 	public long modified;
// }


import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import osgi.enroute.examples.backend.api.Backend;
import osgi.enroute.examples.backend.api.MetaData;
		if (!f.isFile())
			return null;

		try (FileInputStream fout = new FileInputStream(getFile(name));
				DataInputStream din = new DataInputStream(fout)) {
			byte[] data = new byte[(int) f.length()];
			din.readFully(data);
			return data;
		}
	}

	/*
	 * List the metadata
	 */
	@Override
	public Collection<? extends MetaData> list() throws Exception {
		return Arrays.stream(root.listFiles()).map((file) -> {
			return toMetaData(file);
		}).collect(Collectors.toList());
	}

	/*
	 * Delete a blob
	 */
	@Override
	public boolean delete(String name) throws Exception {
		File f = getFile(name);
		if (!f.isFile())
			return false;

// Path: osgi.enroute.examples.backend.application/src/osgi/enroute/examples/backend/api/Backend.java
// public interface Backend {
// 	String TYPE = "type";
// 
// 	/**
// 	 * Save a blob
// 	 * 
// 	 * @param name
// 	 *            The name of the blob
// 	 * @param data
// 	 *            The actual data
// 	 * @return the meta data describing the details of the store
// 	 */
// 	MetaData save(String name, byte[] data) throws Exception;
// 
// 	/**
// 	 * Read the blob with the given name.
// 	 * 
// 	 * @param name
// 	 *            The name of the resource
// 	 * @return the data
// 	 */
// 	byte[] read(String name) throws Exception;
// 
// 	/**
// 	 * Return a list of the meta data of what the store has.
// 	 * 
// 	 * @return The list
// 	 */
// 	Collection<? extends MetaData> list() throws Exception;
// 
// 	/**
// 	 * Delete a blob
// 	 * 
// 	 * @param name
// 	 *            The name of the blob
// 	 * @return true if deleted, false if could not be deleted (might not exist)
// 	 */
// 	boolean delete(String name) throws Exception;
// }
// 
// Path: osgi.enroute.examples.backend.application/src/osgi/enroute/examples/backend/api/MetaData.java
// public class MetaData extends DTO {
// 	/**
// 	 * The name of the blob
// 	 */
// 	public String name;
// 
// 	/**
// 	 * The size of the blob
// 	 */
// 	public long size;
// 
// 	/**
// 	 * The epoch time when it was last modified.
// 	 */
// 	public long modified;
// }


// Path: osgi.enroute.examples.backend.application/src/osgi/enroute/examples/backend/file/provider/FileBackend.java
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import osgi.enroute.examples.backend.api.Backend;
import osgi.enroute.examples.backend.api.MetaData;

		if (!f.isFile())
			return null;

		try (FileInputStream fout = new FileInputStream(getFile(name));
				DataInputStream din = new DataInputStream(fout)) {
			byte[] data = new byte[(int) f.length()];
			din.readFully(data);
			return data;
		}
	}

	/*
	 * List the metadata
	 */
	@Override
	public Collection<? extends MetaData> list() throws Exception {
		return Arrays.stream(root.listFiles()).map((file) -> {
			return toMetaData(file);
		}).collect(Collectors.toList());
	}

	/*
	 * Delete a blob
	 */
	@Override
	public boolean delete(String name) throws Exception {
		File f = getFile(name);
		if (!f.isFile())
			return false;

		return f.delete();