You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by im...@apache.org on 2006/02/22 20:55:50 UTC

svn commit: r379864 - in /jakarta/commons/proper/vfs/trunk/src: java/org/apache/commons/vfs/provider/ram/ test/org/apache/commons/vfs/provider/ram/ test/org/apache/commons/vfs/provider/ram/test/

Author: imario
Date: Wed Feb 22 11:55:47 2006
New Revision: 379864

URL: http://svn.apache.org/viewcvs?rev=379864&view=rev
Log:
PR: 33795
Added ram filesystem

Many thanks to Edgar Poce!

Added:
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileData.java   (with props)
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileObject.java   (with props)
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileOutputStream.java   (with props)
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileProvider.java   (with props)
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileRandomAccessContent.java   (with props)
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystem.java   (with props)
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystemConfigBuilder.java   (with props)
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/package.html   (with props)
    jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/
    jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/
    jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/CustomRamProviderTest.java   (with props)
    jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/RamProviderTestCase.java   (with props)

Added: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileData.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileData.java?rev=379864&view=auto
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileData.java (added)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileData.java Wed Feb 22 11:55:47 2006
@@ -0,0 +1,258 @@
+/*
+ * Copyright 2002, 2003,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.commons.vfs.provider.ram;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileType;
+
+/**
+ * RAM File Object Data
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+class RamFileData implements Serializable
+{
+	/**
+	 * File Name
+	 */
+	private FileName name;
+
+	/**
+	 * File Type
+	 */
+	private FileType type;
+
+	/**
+	 * Bytes
+	 */
+	private byte[] buffer;
+
+	/**
+	 * Last modified time
+	 */
+	private long lastModified;
+
+	/**
+	 * Children
+	 */
+	private Collection children;
+
+	/**
+	 * Constructor
+	 */
+	public RamFileData(FileName name)
+	{
+		super();
+		this.clear();
+		if (name == null)
+		{
+			throw new IllegalArgumentException("name can not be null");
+		}
+		this.name = name;
+	}
+
+	/**
+	 * @return Returns the buffer.
+	 */
+	public byte[] getBuffer()
+	{
+		return buffer;
+	}
+
+	/**
+	 * @param buffer
+	 */
+	public void setBuffer(byte[] buffer)
+	{
+		this.buffer = buffer;
+	}
+
+	/**
+	 * @return Returns the lastModified.
+	 */
+	public long getLastModified()
+	{
+		return lastModified;
+	}
+
+	/**
+	 * @param lastModified
+	 *            The lastModified to set.
+	 */
+	public void setLastModified(long lastModified)
+	{
+		this.lastModified = lastModified;
+	}
+
+	/**
+	 * @return Returns the type.
+	 */
+	public FileType getType()
+	{
+		return type;
+	}
+
+	/**
+	 * @param type
+	 *            The type to set.
+	 */
+	public void setType(FileType type)
+	{
+		this.type = type;
+	}
+
+	/**
+	 * 
+	 */
+	public void clear()
+	{
+		this.buffer = new byte[0];
+		this.lastModified = System.currentTimeMillis();
+		this.type = FileType.IMAGINARY;
+		this.children = Collections.synchronizedCollection(new ArrayList());
+		this.name = null;
+	}
+
+	/**
+	 * @return Returns the name.
+	 */
+	public FileName getName()
+	{
+		return name;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.lang.Object#toString()
+	 */
+	public String toString()
+	{
+		return this.name.toString();
+	}
+
+	/**
+	 * Add a child
+	 * 
+	 * @param data
+	 */
+	public void addChild(RamFileData data) throws FileSystemException
+	{
+		if (!this.getType().equals(FileType.FOLDER))
+		{
+			throw new FileSystemException(
+					"A child can only be added in a folder");
+		}
+
+		if (data == null)
+		{
+			throw new FileSystemException("No child can be null");
+		}
+
+		if (this.children.contains(data))
+		{
+			throw new FileSystemException("Child already exists. " + data);
+		}
+
+		this.children.add(data);
+	}
+
+	/**
+	 * Remove a child
+	 * 
+	 * @param data
+	 * @throws FileSystemException
+	 */
+	public void removeChild(RamFileData data) throws FileSystemException
+	{
+		if (!this.getType().equals(FileType.FOLDER))
+		{
+			throw new FileSystemException(
+					"A child can only be removed from a folder");
+		}
+		if (!this.children.contains(data))
+		{
+			throw new FileSystemException("Child not found. " + data);
+		}
+		this.children.remove(data);
+	}
+
+	/**
+	 * @return Returns the children.
+	 */
+	public Collection getChildren()
+	{
+		if (name == null)
+		{
+			throw new IllegalStateException("Data is clear");
+		}
+		return children;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.lang.Object#equals(java.lang.Object)
+	 */
+	public boolean equals(Object o)
+	{
+		RamFileData data = (RamFileData) o;
+		return this.getName().equals(data.getName());
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.lang.Object#hashCode()
+	 */
+	public int hashCode()
+	{
+		return this.getName().hashCode();
+	}
+
+	public boolean hasChildren(RamFileData data)
+	{
+		return this.children.contains(data);
+	}
+
+	/**
+	 * @return Returns the size of the buffer
+	 */
+	public int size()
+	{
+		return buffer.length;
+	}
+
+	/**
+	 * Resize the buffer
+	 * 
+	 * @param newSize
+	 */
+	public void resize(int newSize)
+	{
+		int size = this.size();
+		byte[] newBuf = new byte[newSize];
+		System.arraycopy(this.buffer, 0, newBuf, 0, size);
+		this.buffer = newBuf;
+	}
+
+}

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileData.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileData.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileObject.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileObject.java?rev=379864&view=auto
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileObject.java (added)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileObject.java Wed Feb 22 11:55:47 2006
@@ -0,0 +1,262 @@
+/*
+ * Copyright 2002, 2003,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.commons.vfs.provider.ram;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileType;
+import org.apache.commons.vfs.RandomAccessContent;
+import org.apache.commons.vfs.provider.AbstractFileObject;
+import org.apache.commons.vfs.util.RandomAccessMode;
+
+/**
+ * A RAM File contains a single RAM FileData instance, it provides methods to
+ * access the data by implementing FileObject interface.
+ * 
+ * @author Edgar Poce
+ */
+public class RamFileObject extends AbstractFileObject implements FileObject
+{
+	/**
+	 * File System
+	 */
+	RamFileSystem fs;
+
+	/**
+	 * RAM File Object Data
+	 */
+	private RamFileData data;
+
+	private void save() throws FileSystemException
+	{
+		this.fs.save(this);
+	}
+
+	/**
+	 * @param name
+	 * @param fs
+	 */
+	protected RamFileObject(FileName name, RamFileSystem fs)
+	{
+		super(name, fs);
+		this.fs = fs;
+		this.fs.attach(this);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doGetType()
+	 */
+	protected FileType doGetType() throws Exception
+	{
+		return data.getType();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doListChildren()
+	 */
+	protected String[] doListChildren() throws Exception
+	{
+		return this.fs.listChildren(this.getName());
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doGetContentSize()
+	 */
+	protected long doGetContentSize() throws Exception
+	{
+		return this.data.getBuffer().length;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doGetInputStream()
+	 */
+	protected InputStream doGetInputStream() throws Exception
+	{
+		return new ByteArrayInputStream(this.data.getBuffer());
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doGetOutputStream(boolean)
+	 */
+	protected OutputStream doGetOutputStream(boolean bAppend) throws Exception
+	{
+		if (!bAppend)
+		{
+			this.data.setBuffer(new byte[0]);
+		}
+		return new RamFileOutputStream(this);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doDelete()
+	 */
+	protected void doDelete() throws Exception
+	{
+		fs.delete(this);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doGetLastModifiedTime()
+	 */
+	protected long doGetLastModifiedTime() throws Exception
+	{
+		return data.getLastModified();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doSetLastModifiedTime(long)
+	 */
+	protected void doSetLastModifiedTime(long modtime) throws Exception
+	{
+		data.setLastModified(modtime);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doCreateFolder()
+	 */
+	protected void doCreateFolder() throws Exception
+	{
+		this.injectType(FileType.FOLDER);
+		this.save();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doRename(org.apache.commons.vfs.FileObject)
+	 */
+	protected void doRename(FileObject newfile) throws Exception
+	{
+		fs.rename(this, (RamFileObject) newfile);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doGetRandomAccessContent(org.apache.commons.vfs.util.RandomAccessMode)
+	 */
+	protected RandomAccessContent doGetRandomAccessContent(RandomAccessMode mode)
+			throws Exception
+	{
+		return new RamFileRandomAccessContent(this, mode);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.provider.AbstractFileObject#doAttach()
+	 */
+	protected void doAttach() throws Exception
+	{
+		this.fs.attach(this);
+	}
+
+	/**
+	 * @return Returns the data.
+	 */
+	public RamFileData getData()
+	{
+		return data;
+	}
+
+	/**
+	 * @param data
+	 *            The data to set.
+	 */
+	public void setData(RamFileData data)
+	{
+		this.data = data;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.provider.AbstractFileObject#injectType(org.apache.commons.vfs.FileType)
+	 */
+	protected void injectType(FileType fileType)
+	{
+		this.data.setType(fileType);
+		super.injectType(fileType);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.provider.AbstractFileObject#endOutput()
+	 */
+	protected void endOutput() throws Exception
+	{
+		super.endOutput();
+		this.save();
+	}
+
+	/**
+	 * @return Returns the size of the RAMFileData
+	 */
+	public int size()
+	{
+		if (data == null)
+		{
+			return 0;
+		}
+		return data.size();
+	}
+
+	/**
+	 * @param newSize
+	 * @throws IOException
+	 *             if the new size exceeds the limit
+	 */
+	public synchronized void resize(int newSize) throws IOException
+	{
+		if (fs.getFileSystemOptions() != null)
+		{
+			int maxSize = RamFileSystemConfigBuilder.getInstance().getMaxSize(
+					fs.getFileSystemOptions());
+			if (fs.size() + newSize - this.size() > maxSize)
+			{
+				throw new IOException("FileSystem capacity (" + maxSize
+						+ ") exceeded.");
+			}
+		}
+		this.data.resize(newSize);
+	}
+
+}

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileObject.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileObject.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileObject.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileOutputStream.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileOutputStream.java?rev=379864&view=auto
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileOutputStream.java (added)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileOutputStream.java Wed Feb 22 11:55:47 2006
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2002, 2003,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.commons.vfs.provider.ram;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.commons.vfs.FileSystemException;
+
+/**
+ * OutputStream to a RamFile
+ * 
+ * @author edgar poce
+ */
+public class RamFileOutputStream extends OutputStream
+{
+
+	/**
+	 * File
+	 */
+	protected RamFileObject file;
+
+	/**
+	 * buffer
+	 */
+	protected byte buffer1[] = new byte[1];
+
+	protected boolean closed = false;
+
+	private IOException exc;
+
+	/**
+	 * @param mode
+	 */
+	public RamFileOutputStream(RamFileObject file)
+	{
+		super();
+		this.file = file;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataOutput#write(byte[], int, int)
+	 */
+	public void write(byte[] b, int off, int len) throws IOException
+	{
+		int size = this.file.getData().size();
+		int newSize = this.file.getData().size() + len;
+		// Store the Exception in order to notify the client again on close()
+		try
+		{
+			this.file.resize(newSize);
+		}
+		catch (IOException e)
+		{
+			this.exc = e;
+			throw e;
+		}
+		System.arraycopy(b, off, this.file.getData().getBuffer(), size, len);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataOutput#write(int)
+	 */
+	public void write(int b) throws IOException
+	{
+		buffer1[0] = (byte) b;
+		this.write(buffer1);
+	}
+
+	public void flush() throws IOException
+	{
+	}
+
+	public void close() throws IOException
+	{
+		if (closed)
+		{
+			return;
+		}
+		// Notify on close that there was an IOException while writing
+		if (exc != null)
+		{
+			throw exc;
+		}
+		try
+		{
+			this.closed = true;
+			// Close the
+			this.file.endOutput();
+		}
+		catch (Exception e)
+		{
+			throw new FileSystemException(e);
+		}
+	}
+
+}

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileOutputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileOutputStream.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileOutputStream.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileProvider.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileProvider.java?rev=379864&view=auto
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileProvider.java (added)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileProvider.java Wed Feb 22 11:55:47 2006
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2002, 2003,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.commons.vfs.provider.ram;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.commons.vfs.Capability;
+import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileSystem;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileSystemOptions;
+import org.apache.commons.vfs.provider.AbstractOriginatingFileProvider;
+import org.apache.commons.vfs.provider.FileProvider;
+
+/**
+ * RAM File Provider
+ * 
+ * @author Edgar Poce
+ */
+public class RamFileProvider extends AbstractOriginatingFileProvider implements
+		FileProvider
+{
+
+	public final static Collection capabilities = Collections
+			.unmodifiableCollection(Arrays.asList(new Capability[]
+			{ Capability.CREATE, Capability.DELETE, Capability.RENAME,
+					Capability.GET_TYPE, Capability.GET_LAST_MODIFIED,
+					Capability.SET_LAST_MODIFIED_FILE,
+					Capability.SET_LAST_MODIFIED_FOLDER,
+					Capability.LIST_CHILDREN, Capability.READ_CONTENT,
+					Capability.URI, Capability.WRITE_CONTENT,
+					Capability.APPEND_CONTENT, Capability.RANDOM_ACCESS_READ,
+					Capability.RANDOM_ACCESS_WRITE }));
+
+	/**
+	 * Constructor
+	 */
+	public RamFileProvider()
+	{
+		super();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.provider.AbstractOriginatingFileProvider#doCreateFileSystem(org.apache.commons.vfs.FileName,
+	 *      org.apache.commons.vfs.FileSystemOptions)
+	 */
+	protected FileSystem doCreateFileSystem(FileName name,
+			FileSystemOptions fileSystemOptions) throws FileSystemException
+	{
+		return new RamFileSystem(name, fileSystemOptions);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.provider.FileProvider#getCapabilities()
+	 */
+	public Collection getCapabilities()
+	{
+		return capabilities;
+	}
+}

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileProvider.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileRandomAccessContent.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileRandomAccessContent.java?rev=379864&view=auto
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileRandomAccessContent.java (added)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileRandomAccessContent.java Wed Feb 22 11:55:47 2006
@@ -0,0 +1,608 @@
+/*
+ * Copyright 2002, 2003,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.commons.vfs.provider.ram;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.vfs.RandomAccessContent;
+import org.apache.commons.vfs.util.RandomAccessMode;
+
+/**
+ * 
+ * RAM File Random Access Content
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public class RamFileRandomAccessContent implements RandomAccessContent
+{
+	/**
+	 * Buffer
+	 */
+	byte[] buf;
+
+	/**
+	 * File Pointer
+	 */
+	protected int filePointer = 0;
+
+	/**
+	 * buffer
+	 */
+	private byte buffer8[] = new byte[8];
+
+	/**
+	 * buffer
+	 */
+	private byte buffer4[] = new byte[4];
+
+	/**
+	 * buffer
+	 */
+	private byte buffer2[] = new byte[2];
+
+	/**
+	 * buffer
+	 */
+	private byte buffer1[] = new byte[1];
+
+	/**
+	 * Mode
+	 */
+	private RandomAccessMode mode;
+
+	/**
+	 * File
+	 */
+	private RamFileObject file;
+
+	private InputStream rafis;
+
+	/**
+	 * @param mode
+	 */
+	public RamFileRandomAccessContent(RamFileObject file, RandomAccessMode mode)
+	{
+		super();
+		this.buf = file.getData().getBuffer();
+		this.file = file;
+		this.mode = mode;
+
+		rafis = new InputStream()
+		{
+			public int read() throws IOException
+			{
+				try
+				{
+					return readByte();
+				}
+				catch (EOFException e)
+				{
+					return -1;
+				}
+			}
+
+			public long skip(long n) throws IOException
+			{
+				seek(getFilePointer() + n);
+				return n;
+			}
+
+			public void close() throws IOException
+			{
+				close();
+			}
+
+			public int read(byte b[]) throws IOException
+			{
+				return read(b);
+			}
+
+			public int read(byte b[], int off, int len) throws IOException
+			{
+				return read(b, off, len);
+			}
+		};
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.RandomAccessContent#getFilePointer()
+	 */
+	public long getFilePointer() throws IOException
+	{
+		return this.filePointer;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.RandomAccessContent#seek(long)
+	 */
+	public void seek(long pos) throws IOException
+	{
+		this.filePointer = (int) pos;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.RandomAccessContent#length()
+	 */
+	public long length() throws IOException
+	{
+		return buf.length;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.RandomAccessContent#close()
+	 */
+	public void close() throws IOException
+	{
+
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataInput#readByte()
+	 */
+	public byte readByte() throws IOException
+	{
+		return (byte) this.readUnsignedByte();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataInput#readChar()
+	 */
+	public char readChar() throws IOException
+	{
+		int ch1 = this.readUnsignedByte();
+		int ch2 = this.readUnsignedByte();
+		return (char) ((ch1 << 8) + (ch2 << 0));
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataInput#readDouble()
+	 */
+	public double readDouble() throws IOException
+	{
+		return Double.longBitsToDouble(this.readLong());
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataInput#readFloat()
+	 */
+	public float readFloat() throws IOException
+	{
+		return Float.intBitsToFloat(this.readInt());
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataInput#readInt()
+	 */
+	public int readInt() throws IOException
+	{
+		return (readUnsignedByte() << 24) | (readUnsignedByte() << 16)
+				| (readUnsignedByte() << 8) | readUnsignedByte();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataInput#readUnsignedByte()
+	 */
+	public int readUnsignedByte() throws IOException
+	{
+		if (filePointer < buf.length)
+		{
+			return buf[filePointer++] & 0xFF;
+		}
+		else
+		{
+			throw new EOFException();
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataInput#readUnsignedShort()
+	 */
+	public int readUnsignedShort() throws IOException
+	{
+		this.readFully(buffer2);
+		return toUnsignedShort(buffer2);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataInput#readLong()
+	 */
+	public long readLong() throws IOException
+	{
+		this.readFully(buffer8);
+		return toLong(buffer8);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataInput#readShort()
+	 */
+	public short readShort() throws IOException
+	{
+		this.readFully(buffer2);
+		return toShort(buffer2);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataInput#readBoolean()
+	 */
+	public boolean readBoolean() throws IOException
+	{
+		return (this.readUnsignedByte() != 0);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataInput#skipBytes(int)
+	 */
+	public int skipBytes(int n) throws IOException
+	{
+		if (n < 0)
+		{
+			throw new IndexOutOfBoundsException(
+					"The skip number can't be negative");
+		}
+
+		long newPos = filePointer + n;
+
+		if (newPos > buf.length)
+		{
+			throw new IndexOutOfBoundsException("Tyring to skip too much bytes");
+		}
+
+		seek(newPos);
+
+		return n;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataInput#readFully(byte[])
+	 */
+	public void readFully(byte[] b) throws IOException
+	{
+		this.readFully(b, 0, b.length);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataInput#readFully(byte[], int, int)
+	 */
+	public void readFully(byte[] b, int off, int len) throws IOException
+	{
+		if (len < 0)
+		{
+			throw new IndexOutOfBoundsException("Length is lower than 0");
+		}
+
+		if (len > this.getLeftBytes())
+		{
+			throw new IndexOutOfBoundsException("Read length (" + len
+					+ ") is higher than buffer left bytes ("
+					+ this.getLeftBytes() + ") ");
+		}
+
+		System.arraycopy(buf, filePointer, b, off, len);
+
+		filePointer += len;
+	}
+
+	private int getLeftBytes()
+	{
+		return buf.length - filePointer;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataInput#readUTF()
+	 */
+	public String readUTF() throws IOException
+	{
+		return DataInputStream.readUTF(this);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataOutput#write(byte[], int, int)
+	 */
+	public void write(byte[] b, int off, int len) throws IOException
+	{
+		if (this.getLeftBytes() < len)
+		{
+			int newSize = this.buf.length + len - this.getLeftBytes();
+			this.file.resize(newSize);
+			this.buf = this.file.getData().getBuffer();
+		}
+		System.arraycopy(b, off, this.buf, filePointer, len);
+		this.filePointer += len;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataOutput#write(byte[])
+	 */
+	public void write(byte[] b) throws IOException
+	{
+		this.write(b, 0, b.length);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataOutput#writeByte(int)
+	 */
+	public void writeByte(int i) throws IOException
+	{
+		this.write(i);
+	}
+
+	/**
+	 * Build a long from first 8 bytes of the array.
+	 * 
+	 * @author Apache-Commons-Id Team
+	 * @param b
+	 *            The byte[] to convert.
+	 * @return A long.
+	 */
+	public static long toLong(byte[] b)
+	{
+		return ((((long) b[7]) & 0xFF) + ((((long) b[6]) & 0xFF) << 8)
+				+ ((((long) b[5]) & 0xFF) << 16)
+				+ ((((long) b[4]) & 0xFF) << 24)
+				+ ((((long) b[3]) & 0xFF) << 32)
+				+ ((((long) b[2]) & 0xFF) << 40)
+				+ ((((long) b[1]) & 0xFF) << 48) + ((((long) b[0]) & 0xFF) << 56));
+	}
+
+	/**
+	 * Build a 8-byte array from a long. No check is performed on the array
+	 * length.
+	 * 
+	 * @author Commons-Id Team
+	 * 
+	 * @param n
+	 *            The number to convert.
+	 * @param b
+	 *            The array to fill.
+	 * @return A byte[].
+	 */
+	public static byte[] toBytes(long n, byte[] b)
+	{
+		b[7] = (byte) (n);
+		n >>>= 8;
+		b[6] = (byte) (n);
+		n >>>= 8;
+		b[5] = (byte) (n);
+		n >>>= 8;
+		b[4] = (byte) (n);
+		n >>>= 8;
+		b[3] = (byte) (n);
+		n >>>= 8;
+		b[2] = (byte) (n);
+		n >>>= 8;
+		b[1] = (byte) (n);
+		n >>>= 8;
+		b[0] = (byte) (n);
+		return b;
+	}
+
+	/**
+	 * Build a short from first 2 bytes of the array.
+	 * 
+	 * @author Apache-Commons-Id Team
+	 * @param b
+	 *            The byte[] to convert.
+	 * @return A short.
+	 */
+	public static short toShort(byte[] b)
+	{
+		return (short) toUnsignedShort(b);
+	}
+
+	/**
+	 * Build a short from first 2 bytes of the array.
+	 * 
+	 * @author Apache-Commons-Id Team
+	 * @param b
+	 *            The byte[] to convert.
+	 * @return A short.
+	 */
+	public static int toUnsignedShort(byte[] b)
+	{
+		return ((b[1] & 0xFF) + ((b[0] & 0xFF) << 8));
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataOutput#write(int)
+	 */
+	public void write(int b) throws IOException
+	{
+		buffer1[0] = (byte) b;
+		this.write(buffer1);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataOutput#writeBoolean(boolean)
+	 */
+	public void writeBoolean(boolean v) throws IOException
+	{
+		this.write(v ? 1 : 0);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataOutput#writeBytes(java.lang.String)
+	 */
+	public void writeBytes(String s) throws IOException
+	{
+		write(s.getBytes());
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataOutput#writeChar(int)
+	 */
+	public void writeChar(int v) throws IOException
+	{
+		buffer2[0] = (byte) ((v >>> 8) & 0xFF);
+		buffer2[1] = (byte) ((v >>> 0) & 0xFF);
+		write(buffer2);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataOutput#writeChars(java.lang.String)
+	 */
+	public void writeChars(String s) throws IOException
+	{
+		int len = s.length();
+		for (int i = 0; i < len; i++)
+		{
+			writeChar(s.charAt(i));
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataOutput#writeDouble(double)
+	 */
+	public void writeDouble(double v) throws IOException
+	{
+		writeLong(Double.doubleToLongBits(v));
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataOutput#writeFloat(float)
+	 */
+	public void writeFloat(float v) throws IOException
+	{
+		writeInt(Float.floatToIntBits(v));
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataOutput#writeInt(int)
+	 */
+	public void writeInt(int v) throws IOException
+	{
+		buffer4[0] = (byte) ((v >>> 24) & 0xFF);
+		buffer4[1] = (byte) ((v >>> 16) & 0xFF);
+		buffer4[2] = (byte) ((v >>> 8) & 0xFF);
+		buffer4[3] = (byte) (v & 0xFF);
+		write(buffer4);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataOutput#writeLong(long)
+	 */
+	public void writeLong(long v) throws IOException
+	{
+		write(toBytes(v, buffer8));
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataOutput#writeShort(int)
+	 */
+	public void writeShort(int v) throws IOException
+	{
+		buffer2[0] = (byte) ((v >>> 8) & 0xFF);
+		buffer2[1] = (byte) (v & 0xFF);
+		write(buffer2);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataOutput#writeUTF(java.lang.String)
+	 */
+	public void writeUTF(String str) throws IOException
+	{
+		ByteArrayOutputStream out = new ByteArrayOutputStream(str.length());
+		DataOutputStream dataOut = new DataOutputStream(out);
+		dataOut.writeUTF(str);
+		dataOut.flush();
+		dataOut.close();
+		byte[] b = out.toByteArray();
+		write(b);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.io.DataInput#readLine()
+	 */
+	public String readLine() throws IOException
+	{
+		throw new UnsupportedOperationException("deprecated");
+	}
+
+	public InputStream getInputStream() throws IOException
+	{
+		return rafis;
+	}
+}

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileRandomAccessContent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileRandomAccessContent.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileRandomAccessContent.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystem.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystem.java?rev=379864&view=auto
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystem.java (added)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystem.java Wed Feb 22 11:55:47 2006
@@ -0,0 +1,356 @@
+/*
+ * Copyright 2003,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.commons.vfs.provider.ram;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.Transformer;
+import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSelectInfo;
+import org.apache.commons.vfs.FileSelector;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileSystemOptions;
+import org.apache.commons.vfs.FileType;
+import org.apache.commons.vfs.provider.AbstractFileSystem;
+
+/**
+ * A RAM File System
+ * 
+ * @author Edgar Poce
+ */
+public class RamFileSystem extends AbstractFileSystem implements Serializable
+{
+	/** config builder */
+	private static RamFileSystemConfigBuilder confBuilder = RamFileSystemConfigBuilder
+			.getInstance();
+
+	/**
+	 * Cache of RAM File Data
+	 */
+	private Map cache;
+
+	/**
+	 * Tranformer from RAM file data to File Base Name
+	 */
+	private static Transformer dataToBaseName;
+
+	static
+	{
+		dataToBaseName = new Transformer()
+		{
+			public Object transform(Object o)
+			{
+				RamFileData data = (RamFileData) o;
+				return data.getName().getBaseName();
+			}
+		};
+	}
+
+	/**
+	 * @param rootName
+	 * @param parentLayer
+	 * @param fileSystemOptions
+	 */
+	protected RamFileSystem(FileName rootName,
+			FileSystemOptions fileSystemOptions)
+	{
+		super(rootName, null, fileSystemOptions);
+		this.cache = Collections.synchronizedMap(new HashMap());
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.provider.AbstractFileSystem#createFile(org.apache.commons.vfs.FileName)
+	 */
+	protected FileObject createFile(FileName name) throws Exception
+	{
+		RamFileObject file = new RamFileObject(name, this);
+		return file;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.commons.vfs.provider.AbstractFileSystem#addCapabilities(java.util.Collection)
+	 */
+	protected void addCapabilities(Collection caps)
+	{
+		caps.addAll(RamFileProvider.capabilities);
+	}
+
+	/**
+	 * @param name
+	 * @return children
+	 */
+	public String[] listChildren(FileName name)
+	{
+		RamFileData data = (RamFileData) this.cache.get(name);
+		Collection children = data.getChildren();
+		Collection names = CollectionUtils.collect(children, dataToBaseName);
+		String[] retu = (String[]) names.toArray(new String[names.size()]);
+		return retu;
+	}
+
+	/**
+	 * Delete a file
+	 * 
+	 * @param file
+	 * @throws FileSystemException
+	 */
+	public void delete(RamFileObject file) throws FileSystemException
+	{
+		// Remove reference from cache
+		this.cache.remove(file.getName());
+		// Notify the parent
+		RamFileObject parent = (RamFileObject) this.resolveFile(file
+				.getParent().getName());
+		parent.getData().removeChild(file.getData());
+		parent.close();
+		// Close the file
+		file.getData().clear();
+		file.close();
+	}
+
+	/**
+	 * Saves a file
+	 * 
+	 * @param file
+	 * @throws FileSystemException
+	 */
+	public void save(final RamFileObject file) throws FileSystemException
+	{
+
+		// Validate name
+		if (file.getData().getName() == null)
+		{
+			throw new FileSystemException(new IllegalStateException(
+					"The data has no name. " + file));
+		}
+
+		// Validate file system size
+		// if (size() > confBuilder.getMaxSize(this
+		// .getFileSystemOptions())) {
+		// throw new FileSystemException(
+		// "The maximum size ("
+		// + confBuilder.getMaxSize(this
+		// .getFileSystemOptions())
+		// + ") was exceeded.");
+		// }
+
+		// Validate against the predicate
+		FileSelector predicate = confBuilder.getPredicate(this
+				.getFileSystemOptions());
+		
+		FileSelectInfo info = new FileSelectInfo()
+		{
+			public FileObject getBaseFolder()
+			{
+				try
+				{
+					return getRoot();
+				}
+				catch (FileSystemException e)
+				{
+					throw new RuntimeException(e.getLocalizedMessage());
+				}
+			}
+
+			public FileObject getFile()
+			{
+				return file;
+			}
+
+			public int getDepth()
+			{
+				return -1;
+			}
+		};
+		
+		try
+		{
+			if (predicate != null && !predicate.includeFile(info))
+			{
+				throw new FileSystemException(
+						"Unable to save file, it was rejected by the predicate "
+								+ predicate.getClass().getName() + ".");
+			}
+		}
+		catch (Exception e)
+		{
+			throw new FileSystemException(e);
+		}
+
+		// Add to the parent
+		if (file.getName().getDepth() > 0)
+		{
+			RamFileData parentData = (RamFileData) this.cache.get(file
+					.getParent().getName());
+			// Only if not already added
+			if (!parentData.hasChildren(file.getData()))
+			{
+				RamFileObject parent = (RamFileObject) file.getParent();
+				parent.getData().addChild(file.getData());
+				parent.close();
+			}
+		}
+		// Store in cache
+		cache.put(file.getName(), file.getData());
+		file.close();
+	}
+
+	/**
+	 * @param object
+	 * @param newfile
+	 * @throws FileSystemException
+	 */
+	public void rename(RamFileObject from, RamFileObject to)
+			throws FileSystemException
+	{
+		if (!this.cache.containsKey(from.getName()))
+		{
+			throw new FileSystemException("File does not exist: "
+					+ from.getName());
+		}
+		// Copy data
+
+		to.getData().setBuffer(from.getData().getBuffer());
+		to.getData().setLastModified(from.getData().getLastModified());
+		to.getData().setType(from.getData().getType());
+
+		this.save(to);
+		this.delete(from);
+	}
+
+	public void attach(RamFileObject fo)
+	{
+		if (fo.getName() == null)
+		{
+			throw new IllegalArgumentException("Null argument");
+		}
+		RamFileData data = (RamFileData) this.cache.get(fo.getName());
+		if (data == null)
+		{
+			data = new RamFileData(fo.getName());
+		}
+		fo.setData(data);
+	}
+
+	/**
+	 * Import a Tree
+	 * 
+	 * @param fs
+	 *            RAM FileSyste
+	 * @param file
+	 * @param root
+	 * @throws FileSystemException
+	 */
+	public void importTree(File file) throws FileSystemException
+	{
+		FileObject fileFo = getFileSystemManager().toFileObject(file);
+		this.toRamFileObject(fileFo, fileFo);
+	}
+
+	/**
+	 * Import the given file with the name relative to the given root
+	 * 
+	 * @param fo
+	 * @param root
+	 * @throws FileSystemException
+	 */
+	public void toRamFileObject(FileObject fo, FileObject root)
+			throws FileSystemException
+	{
+		RamFileObject memFo = (RamFileObject) this.resolveFile(fo.getName()
+				.getPath().substring(root.getName().getPath().length()));
+		if (fo.getType().equals(FileType.FOLDER))
+		{
+			// Create Folder
+			memFo.createFolder();
+			// Import recursively
+			FileObject[] fos = fo.getChildren();
+			for (int i = 0; i < fos.length; i++)
+			{
+				FileObject child = fos[i];
+				this.toRamFileObject(child, root);
+			}
+		}
+		else if (fo.getType().equals(FileType.FILE))
+		{
+			// Read bytes
+			try
+			{
+				InputStream is = fo.getContent().getInputStream();
+				OutputStream os = new BufferedOutputStream(memFo
+						.getOutputStream(), 512);
+				int i;
+				while ((i = is.read()) != -1)
+				{
+					os.write(i);
+				}
+				os.flush();
+				os.close();
+				is.close();
+			}
+			catch (IOException e)
+			{
+				throw new FileSystemException(e.getClass().getName() + " "
+						+ e.getMessage());
+			}
+		}
+		else
+		{
+			throw new FileSystemException("File is not a folder nor a file"
+					+ memFo);
+		}
+	}
+
+	/**
+	 * @return Returns the size of the FileSystem
+	 */
+	public int size()
+	{
+		int size = 0;
+		Iterator iter = cache.values().iterator();
+		while (iter.hasNext())
+		{
+			RamFileData data = (RamFileData) iter.next();
+			size += data.size();
+		}
+		return size;
+	}
+
+	/**
+	 * Close the RAMFileSystem
+	 */
+	public void close()
+	{
+		this.cache = null;
+		super.close();
+	}
+}

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystem.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystem.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystem.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystemConfigBuilder.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystemConfigBuilder.java?rev=379864&view=auto
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystemConfigBuilder.java (added)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystemConfigBuilder.java Wed Feb 22 11:55:47 2006
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2003,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.commons.vfs.provider.ram;
+
+import org.apache.commons.vfs.FileSelector;
+import org.apache.commons.vfs.FileSystemConfigBuilder;
+import org.apache.commons.vfs.FileSystemOptions;
+
+/**
+ * Config Builder for the RAM filesystem.
+ * 
+ * @author edgar poce
+ * 
+ */
+public class RamFileSystemConfigBuilder extends FileSystemConfigBuilder
+{
+
+	/** max size key */
+	private static final String MAX_SIZE_KEY = "maxsize";
+
+	/** predicate key */
+	private static final String PREDICATE_KEY = "predicate";
+
+	/** config builder singleton */
+	private static RamFileSystemConfigBuilder singleton = new RamFileSystemConfigBuilder();
+
+	/**
+	 * Constructor
+	 */
+	private RamFileSystemConfigBuilder()
+	{
+		super();
+	}
+
+	/**
+	 * @return the config builder singleton
+	 */
+	public static RamFileSystemConfigBuilder getInstance()
+	{
+		return singleton;
+	}
+
+	/**
+	 * @inheritDoc
+	 */
+	protected Class getConfigClass()
+	{
+		return RamFileSystem.class;
+	}
+
+	/**
+	 * @param opts
+	 * @return
+	 * @see #setMaxSize
+	 */
+	public int getMaxSize(FileSystemOptions opts)
+	{
+		Integer size = (Integer) getParam(opts, MAX_SIZE_KEY);
+		if (size != null)
+		{
+			return size.intValue();
+		}
+		else
+		{
+			return Integer.MAX_VALUE;
+		}
+	}
+
+	/**
+	 * sets the maximum size of the file system
+	 * 
+	 * @param opts
+	 * @param sizeInBytes
+	 */
+	public void setMaxSize(FileSystemOptions opts, int sizeInBytes)
+	{
+		setParam(opts, MAX_SIZE_KEY, new Integer(sizeInBytes));
+	}
+
+	/**
+	 * @param opts
+	 * @return
+	 * @see #setPredicate
+	 */
+	public FileSelector getPredicate(FileSystemOptions opts)
+	{
+		return (FileSelector) getParam(opts, PREDICATE_KEY);
+	}
+
+	/**
+	 * sets a predicate that performs a validation test before adding it to the
+	 * file system
+	 */
+	public void setPredicate(FileSystemOptions opts, FileSelector predicate)
+	{
+		setParam(opts, PREDICATE_KEY, predicate);
+	}
+
+}

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystemConfigBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystemConfigBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystemConfigBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/package.html
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/package.html?rev=379864&view=auto
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/package.html (added)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/package.html Wed Feb 22 11:55:47 2006
@@ -0,0 +1,3 @@
+<body>
+<p>The RAM File Provider.</p>
+</body>
\ No newline at end of file

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/CustomRamProviderTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/CustomRamProviderTest.java?rev=379864&view=auto
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/CustomRamProviderTest.java (added)
+++ jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/CustomRamProviderTest.java Wed Feb 22 11:55:47 2006
@@ -0,0 +1,155 @@
+/*
+ * Copyright 2002, 2003,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.commons.vfs.provider.ram.test;
+
+import java.io.OutputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSelectInfo;
+import org.apache.commons.vfs.FileSelector;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileSystemOptions;
+import org.apache.commons.vfs.impl.DefaultFileSystemManager;
+import org.apache.commons.vfs.provider.ram.RamFileProvider;
+import org.apache.commons.vfs.provider.ram.RamFileSystemConfigBuilder;
+
+/**
+ * Custom tests
+ * 
+ * @author edgar poce
+ * @version
+ * 
+ */
+public class CustomRamProviderTest extends TestCase
+{
+	DefaultFileSystemManager manager;
+
+	FileSystemOptions zeroSized = new FileSystemOptions();
+
+	FileSystemOptions smallSized = new FileSystemOptions();
+
+	FileSystemOptions predicated = new FileSystemOptions();
+
+	protected void setUp() throws Exception
+	{
+		super.setUp();
+
+		manager = new DefaultFileSystemManager();
+		manager.addProvider("ram", new RamFileProvider());
+		manager.init();
+
+		// File Systems Options
+		RamFileSystemConfigBuilder.getInstance().setMaxSize(zeroSized, 0);
+		RamFileSystemConfigBuilder.getInstance().setMaxSize(smallSized, 10);
+		FileSelector predicate = new FileSelector()
+		{
+			public boolean includeFile(FileSelectInfo fileInfo) throws Exception
+			{
+				return "txt".equals(fileInfo.getFile().getName().getExtension());
+			}
+
+			public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception
+			{
+				// not required
+				return true;
+			}
+			
+		};
+		/*
+		Predicate predicate = new Predicate()
+		{
+			public boolean evaluate(Object o)
+			{
+				RamFileObject file = (RamFileObject) o;
+				return file.getName().getBaseName().endsWith("txt");
+			}
+		};
+		*/
+		RamFileSystemConfigBuilder.getInstance().setPredicate(predicated, predicate);
+	}
+
+	protected void tearDown() throws Exception
+	{
+		super.tearDown();
+		manager.close();
+	}
+
+	public void testSmallFS() throws Exception
+	{
+
+		// Default FS
+		FileObject fo1 = manager.resolveFile("ram:/");
+		FileObject fo2 = manager.resolveFile("ram:/");
+		assertTrue("Both files should exist in the same fs instance.", fo1
+				.getFileSystem() == fo2.getFileSystem());
+
+		// Small FS
+		FileObject fo3 = manager.resolveFile("ram:/", smallSized);
+		FileObject fo4 = manager.resolveFile("ram:/", smallSized);
+		assertTrue("Both files should exist in different fs instances.", fo3
+				.getFileSystem() == fo4.getFileSystem());
+		assertTrue("These file shouldn't be in the same file system.", fo1
+				.getFileSystem() != fo3.getFileSystem());
+
+		fo3.createFile();
+		try
+		{
+			OutputStream os = fo3.getContent().getOutputStream();
+			os.write(new byte[10]);
+			os.close();
+		}
+		catch (FileSystemException e)
+		{
+			fail("It shouldn't save such a small file");
+		}
+
+		try
+		{
+			OutputStream os = fo3.getContent().getOutputStream();
+			os.write(new byte[11]);
+			os.close();
+			fail("It shouldn't save such a big file");
+		}
+		catch (FileSystemException e)
+		{
+			// exception awaited
+			;
+		}
+
+	}
+
+	public void testPredicatedFS() throws FileSystemException
+	{
+		FileObject predFo = null;
+		try
+		{
+			predFo = manager.resolveFile("ram:/myfile.anotherExtension",
+					predicated);
+			predFo.createFile();
+			fail("It should only accept files with .txt extensions");
+		}
+		catch (FileSystemException e)
+		{
+			// Do nothing
+		}
+		predFo = manager
+				.resolveFile("ram:/myfile.anotherExtension", predicated);
+		assertTrue(!predFo.exists());
+	}
+
+}

Propchange: jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/CustomRamProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/CustomRamProviderTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/CustomRamProviderTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/RamProviderTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/RamProviderTestCase.java?rev=379864&view=auto
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/RamProviderTestCase.java (added)
+++ jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/RamProviderTestCase.java Wed Feb 22 11:55:47 2006
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2002, 2003,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.commons.vfs.provider.ram.test;
+
+import java.io.File;
+
+import junit.framework.Test;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemManager;
+import org.apache.commons.vfs.impl.DefaultFileSystemManager;
+import org.apache.commons.vfs.provider.local.DefaultLocalFileProvider;
+import org.apache.commons.vfs.provider.ram.RamFileProvider;
+import org.apache.commons.vfs.provider.ram.RamFileSystem;
+import org.apache.commons.vfs.test.AbstractProviderTestConfig;
+import org.apache.commons.vfs.test.ProviderTestConfig;
+import org.apache.commons.vfs.test.ProviderTestSuite;
+
+/**
+ * Tests for the RAM file system.
+ */
+public class RamProviderTestCase extends AbstractProviderTestConfig implements
+		ProviderTestConfig
+{
+
+	/** logger */
+	private static Log log = LogFactory.getLog(RamProviderTestCase.class);
+
+	/**
+	 * Creates the test suite for the ram file system.
+	 */
+	public static Test suite() throws Exception
+	{
+		return new ProviderTestSuite(new RamProviderTestCase());
+	}
+
+	/**
+	 * Prepares the file system manager.
+	 * 
+	 * Imports test data from the disk.
+	 * 
+	 * @throws Exception
+	 * 
+	 */
+	public void prepare(final DefaultFileSystemManager manager)
+			throws Exception
+	{
+		try
+		{
+			manager.addProvider("ram", new RamFileProvider());
+			manager.addProvider("file", new DefaultLocalFileProvider());
+			FileObject fo = manager.resolveFile("ram:/");
+			// Import the test tree
+			RamFileSystem fs = (RamFileSystem) fo.getFileSystem();
+			fs.importTree(new File("target/test-data"));
+			fo.close();
+		}
+		catch (Exception e)
+		{
+			log.error(e);
+			throw e;
+		}
+	}
+
+	/**
+	 * Returns the base folder for tests.
+	 */
+	public FileObject getBaseTestFolder(final FileSystemManager manager)
+			throws Exception
+	{
+		final String uri = "ram:/";
+		return manager.resolveFile(uri);
+	}
+}

Propchange: jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/RamProviderTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/RamProviderTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/RamProviderTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org