Index: java/engine/org/apache/derby/impl/io/MemoryFile.java
===================================================================
--- java/engine/org/apache/derby/impl/io/MemoryFile.java	(revision 0)
+++ java/engine/org/apache/derby/impl/io/MemoryFile.java	(revision 0)
@@ -0,0 +1,476 @@
+/*
+
+Derby - Class org.apache.derby.impl.io.Memoryfile
+
+Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable.
+
+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.derby.impl.io;
+
+import org.apache.derby.iapi.services.sanity.SanityManager;
+import org.apache.derby.io.StorageFile;
+import org.apache.derby.io.StorageRandomAccessFile;
+//import org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream;
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.RandomAccessFile;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.StringTokenizer;
+//import java.io.RandomAccessFile;
+import org.apache.derby.impl.io.memory.BlockedByteArray;
+import org.apache.derby.impl.io.memory.MemoryInputStream;
+import org.apache.derby.impl.io.memory.MemoryOutputStream;
+import org.apache.derby.impl.io.memory.ReadOnlyFileDescriptor;
+import org.apache.derby.impl.io.memory.WritableFileDescriptor;
+import org.apache.derby.io.VirtualFileData;
+
+/**
+ * MemoryFile represents an abstract path name used to uniquely identify a file
+ * in the virtual in-memory filesystem
+ */
+
+public class MemoryFile  
+extends File
+implements StorageFile
+{
+	private final MemoryStorageFactory storageFactory;
+
+	private String cpath = null;
+
+    /**
+     * Construct a MemFile from a path name.
+     *
+     * @param path The path name.
+     */
+    MemoryFile( MemoryStorageFactory aStorageFactory, String aPath)  
+    {
+    	super(aPath);
+    	//path = super.path;
+    	storageFactory = aStorageFactory;
+    	
+    	trimPath();
+
+        //System.err.println("MemFile1--(this.path=" + getPath() +") -- passed path=" + aPath + " -- " + cpath);
+    }
+
+    /**
+     * Construct a MemFile from a directory name and a file name.
+     *
+     * @param directory The directory part of the path name.
+     * @param fileName The name of the file within the directory.
+     */
+    MemoryFile( MemoryStorageFactory aStorageFactory, String parent, String name)
+	{
+    	super(parent, name);
+    	//path = super.path;
+    	storageFactory = aStorageFactory;
+    	trimPath();
+		
+    	//System.err.println("MemFile2--(this.path=" + getPath() +") -- " + parent + " -- " +  name + " -- " + cpath);
+    }
+
+    /**
+     * Construct a MemFile from a directory StorageFile and a file name.
+     * @param dir - parent directory
+     * @param name
+     */
+    MemoryFile( MemoryFile dir, String name)
+    {
+    	super((File)dir, name);
+    	//path = super.path;
+    	this.storageFactory = dir.storageFactory;
+    	trimPath();
+        //System.out.println("MemFile3--(this.path=" + getPath() +") -- " + name + " -- " + cpath);
+    }
+    
+    private MemoryFile( MemoryStorageFactory  aStorageFactory, String child, int pathLen)
+    {
+        super( child.substring(0, pathLen));
+        //path = super.path;
+        storageFactory = aStorageFactory;
+        trimPath();
+    }
+
+ 
+    /**
+     * Creates an output stream from a file name.
+     *
+     * @param name The file name.
+     *
+     * @return an output stream suitable for writing to the virtual file.
+     *
+     * @exception FileNotFoundException if the file exists but is a directory
+     *            rather than a regular file, does not exist but cannot be created, or
+     *            cannot be opened for any other reason.
+     */
+    public OutputStream getOutputStream( ) throws FileNotFoundException
+    {
+    	return getOutputStream(false);
+    }
+    
+    /**
+     * Creates an output stream from a file name.
+     *
+     * @param append If true then data will be appended to the end of the virtual file, if it already exists.
+     *               If false and a normal file already exists with this name the file will first be truncated
+     *               to zero length.
+     *
+     * @return an output stream suitable for writing to the virtual file.
+     *
+     * @exception FileNotFoundException if the file exists but is a directory
+     *            rather than a regular file, does not exist but cannot be created, or
+     *            cannot be opened for any other reason.
+     */
+    public OutputStream getOutputStream( final boolean append) throws FileNotFoundException
+    {
+    	//System.out.println("WTF!: " +  cpath + " -- vs --" + getParentDir().getPath() + " isdir=" + getParentDir().isDirectory());
+    	if (getParentDir().isDirectory())
+     	   return storageFactory.vfs.getOutputStream(cpath, append);
+     	else
+     		throw new FileNotFoundException("Virtual file's parent directory does not exist");
+    }
+
+    /**
+     * Creates an input stream e.
+     *
+     * @return an input stream suitable for reading from the file.
+     *
+     * @exception FileNotFoundException if the file is not found.
+     */
+    public InputStream getInputStream( ) throws FileNotFoundException
+    {
+        return storageFactory.vfs.getInputStream(cpath);//new MemoryInputStream(new ReadOnlyFileDescriptor(fileData)); 
+    }
+
+    /**
+     * Get an exclusive lock. This is used to ensure that two or more JVMs do not open the same database
+     * at the same time.
+     *
+     * @param lockFile The name of the lock. In a file system implementation it will be the name of a
+     *                 lock file.
+     *
+     * @return EXCLUSIVE_FILE_LOCK_NOT_AVAILABLE if the lock cannot be acquired because it is already held.<br>
+     *    EXCLUSIVE_FILE_LOCK if the lock was successfully acquired.<br>
+     *    NO_FILE_LOCK_SUPPORT if the system does not support exclusive locks.<br>
+     */
+    public synchronized int getExclusiveFileLock()
+	{
+    	
+/*		if (exists())
+		{
+			delete();
+		}
+		try
+        {
+			//Just create an empty file
+			RandomAccessFile lockFileOpen = new RandomAccessFile( (File) this, "rw");
+			lockFileOpen.getFD().sync( );
+			lockFileOpen.close();
+		}catch(IOException ioe)
+		{
+			// do nothing - it may be read only medium, who knows what the
+			// problem is
+			if (SanityManager.DEBUG)
+			{
+				SanityManager.THROWASSERT("Unable to create Exclusive Lock File " + getPath());
+			}
+		}*/
+		return NO_FILE_LOCK_SUPPORT;
+	} // end of getExclusiveFileLock
+
+
+    /**
+     * Get a random access (read/write) file.
+     *
+     * @param name The name of the file.
+     * @param mode unused, but for compatibility
+     *
+     * @return an object that can be used for random access to the file.
+     *
+     * @exception FileNotFoundException if the file exists but is a directory rather than a regular
+     *              file, or cannot be opened or created for any other reason .
+     */
+    public StorageRandomAccessFile getRandomAccessFile( String mode) throws FileNotFoundException
+    {
+    	return storageFactory.vfs.getStorageRandomAccessFile(cpath, mode);
+    } 
+
+    /**
+     * Rename the file denoted by this name. Note that StorageFile objects are immutable. This method
+     * renames the underlying file, it does not change this StorageFile object. The StorageFile object denotes the
+     * same name as before, however the exists() method will return false after the renameTo method
+     * executes successfully.
+     *
+     *<p>It is not specified whether this method will succeed if a file already exists under the new name.
+     *
+     * @param newName the new name.
+     *
+     * @return <b>true</b> if the rename succeeded, <b>false</b> if not.
+     */
+    public boolean renameTo( StorageFile newName)
+    {
+    	try
+		{
+    	   return storageFactory.vfs.renameTo(cpath, newName.getCanonicalPath() );
+		}
+    	catch (IOException ex)
+		{
+    		return false;
+		}
+    }
+
+    /**
+     * Deletes the named file and, if it is a directory, all the files and directories it contains.
+     *
+     * @return <b>true</b> if the named file or directory is successfully deleted, <b>false</b> if not
+     */
+    public boolean deleteAll()
+    {
+    //	System.out.println("WARNING: deleteAll() on " + getCanonicalPath() + " -- path=" + path);
+        return storageFactory.vfs.deleteAll(cpath);
+    } 
+    
+    /**
+     * Tests whether the named file exists.
+     *
+     * @return <b>true</b> if the named file exists, <b>false</b> if not.
+     */
+    public boolean exists()
+    {
+       return storageFactory.vfs.exists(cpath);
+    }
+
+    /**
+     * Determine whether the named file is writable.
+     *
+     * @return <b>true</b> if the file exists and is writable, <b>false</b> if not.
+     */
+	public boolean canWrite() {
+       return storageFactory.vfs.canWrite(cpath);
+	}
+	
+    /**
+     * If the named file does not already exist then create it as an empty normal file.
+     *
+     * The implementation
+     * must synchronize with other threads accessing the same file (in the same or a different process).
+     * If two threads both attempt to create a file with the same name
+     * at the same time then at most one should succeed.
+     *
+     * @return <b>true</b> if this thread's invocation of createNewFile successfully created the named file;
+     *         <b>false</b> if not, i.e. <b>false</b> if the named file already exists or if another concurrent thread created it.
+     *
+     * @exception IOException - If the directory does not exist or some other I/O error occurred
+     */
+	public boolean createNewFile() throws IOException {
+		return storageFactory.vfs.createNewFile(cpath);
+		
+	}
+
+    /**
+     * Deletes the named file or empty directory. This method does not delete non-empty directories.
+     *
+     * @return <b>true</b> if the named file or directory is successfully deleted, <b>false</b> if not
+     */
+	public boolean delete() {
+		return storageFactory.vfs.delete(cpath);
+	}
+	
+	
+
+ 
+    /**
+     * get the canonical path name
+     * @return String
+     */
+    public String getCanonicalPath() 
+    {
+         return cpath;
+    }
+    
+    /**
+     * Get the names of all files and sub-directories in the directory named by this path name.
+     *
+     * @return An array of the names of the files and directories in this
+     *         directory denoted by this abstract pathname. The returned array will have length 0
+     *         if this directory is empty. Returns null if this StorageFile is not  a directory, or
+     *         if an I/O error occurs.
+     */
+    public String[] list()
+    {
+        return storageFactory.vfs.list(cpath);
+    }
+    
+    /**
+     * Tests whether the named file is a directory, or not. This is only called in writable storage factories.
+     *
+     * @return <b>true</b> if named file exists and is a directory, <b>false</b> if not.
+     *          The return value is undefined if the storage is read-only.
+     */
+    public boolean isDirectory()
+    {
+        return storageFactory.vfs.isDirectory(cpath);
+    }
+    
+    /**
+     * Creates the named directory.
+     *
+     * @return <b>true</b> if the directory was created; <b>false</b> if not.
+     */
+    public boolean mkdir()
+    {
+        //return storageFactory.getVirtualFS().mkdir(path);
+      //  if (isDirectory() || fileData != null) return false;
+/*    	  if (fileData != null) return false;
+        else 
+        {
+        	fileAttributes = (fileAttributes | IS_DIRECTORY);
+        	return true;
+        }*/
+ /*   	StorageFile s = getParentDir();
+    	if (s == null || s.isDirectory())
+    	   return storageFactory.vfs.mkdir(cpath);
+    	else return false;*/
+    	return storageFactory.vfs.mkdir(this, cpath);
+
+    }
+
+    /**
+     * Creates the named directory, and all nonexistent parent directories.
+     *
+     * @return <b>true</b> if the directory was created, <b>false</b> if not
+     */
+    public boolean mkdirs()
+    {
+   /* 	System.out.println("mkdirs1: " + path);
+	 	StringTokenizer s = new StringTokenizer(path, "/");
+	 	String t = "";
+	    while(s.hasMoreTokens())
+	    {
+	    	t = t + "/" + s.nextToken();
+	    	if (storageFactory.getVirtualFS().existsInTable(t) == null)
+	    	{
+	    	   storageFactory.getVirtualFS().registerFile(
+	    			new MemoryFile(this.storageFactory, t, t.length()));
+	    	}
+	    }*/
+	    //return false;
+    	return storageFactory.vfs.mkdirs(this, cpath);
+        
+    }
+
+	/**
+     * Release the resource associated with an earlier acquired exclusive lock
+     *
+     * @see #getExclusiveFileLock
+     */
+	public void releaseExclusiveFileLock()
+    {}
+    
+    
+    /**
+     * Make the named file or directory read-only. This interface does not specify whether this
+     * also makes the file undeletable.
+     *
+     * @return <b>true</b> if the named file or directory was made read-only, or it already was read-only;
+     *         <b>false</b> if not.
+     */
+    public boolean setReadOnly()
+    {
+        return false; //SLF
+    	//return storageFactory.getVirtualFS().setReadOnly(path);
+    }
+    
+    
+    /**
+     * Returns the length of the named file if it is not a directory. The return value is not specified
+     * if the file is a directory.
+     *
+     * @return The length, in bytes, of the named file if it exists and is not a directory,
+     *         0 if the file does not exist, or any value if the named file is a directory.
+     */
+    public long length()
+    {
+    	return storageFactory.vfs.length(cpath);
+    } // end of length
+    
+    
+    /**
+     * Get the file name for diagnostic purposes. Usually the same as getPath().
+     *
+     * @return the file name
+     */
+    public String toString()
+    {
+        return getPath();
+    }
+	
+    /**
+     * Get the parent of this file.
+     *
+     * @param pathLen the length of the parent's path name.
+     */
+    StorageFile getParentDir( int pathLen)
+    {
+    	//System.out.println("getparent for: " + cpath +" = " + cpath.substring(0,pathLen));
+        return new MemoryFile( storageFactory, cpath, pathLen);
+    }
+    
+    /**
+     * Get the name of the parent directory if this name includes a parent.
+     *
+     * @return An StorageFile denoting the parent directory of this StorageFile, if it has a parent, null if
+     *         it does not have a parent.
+     */   
+    public StorageFile getParentDir()
+    {
+    	if (cpath.lastIndexOf( '/') == 0) return null;
+    	return getParentDir( cpath.lastIndexOf( '/'));
+        //return storageFactory.registerFile(new MemoryFile( storageFactory, path, pathLen));
+    }
+    
+    /**
+     * makes sure no paths end with the separator
+     * also stores the canonical path
+     *
+     */
+    private void trimPath()
+    {
+    	try
+		{
+	    	cpath = super.getCanonicalPath();
+	    	String s = File.pathSeparator;
+	    	if (cpath.endsWith(s))
+	    	{ 
+	    		cpath = cpath.substring(cpath.length() -1);
+	    	}
+		}
+	    catch (IOException ex)
+		{
+	    	cpath = getPath();
+		}
+    }
+}

Property changes on: java/engine/org/apache/derby/impl/io/MemoryFile.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: java/engine/org/apache/derby/impl/io/MemoryStorageFactory.java
===================================================================
--- java/engine/org/apache/derby/impl/io/MemoryStorageFactory.java	(revision 0)
+++ java/engine/org/apache/derby/impl/io/MemoryStorageFactory.java	(revision 0)
@@ -0,0 +1,255 @@
+/*
+
+Derby - Class org.apache.derby.impl.io.MemoryStorageFactory
+
+Copyright 2004 The Apache Software Foundation or its licensors, as applicable.
+
+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.derby.impl.io;
+
+import org.apache.derby.iapi.services.sanity.SanityManager;
+import org.apache.derby.iapi.store.raw.data.DataFactory;
+
+import java.io.*;
+
+import org.apache.derby.io.StorageFactory;
+import org.apache.derby.io.WritableStorageFactory;
+import org.apache.derby.io.StorageFile;
+import org.apache.derby.io.StorageRandomAccessFile;
+//import org.apache.derby.iapi.services.io.DynamicByteArrayIOStreamFile;
+import org.apache.derby.io.VirtualFS;
+import org.apache.derby.impl.io.memory.MemoryFS;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.File;
+
+
+import java.util.Properties;
+import java.util.Hashtable;
+import java.util.HashMap;
+import java.util.Enumeration;
+import java.util.Vector;
+import java.util.StringTokenizer;
+/**
+* This class provides a disk based implementation of the StorageFactory interface. It is used by the
+* database engine to access in-memory data and transaction logs under the memory subsubprotocol.
+*/
+
+public class MemoryStorageFactory extends BaseStorageFactory
+implements WritableStorageFactory
+ 
+{
+	
+    VirtualFS vfs;
+    private static HashMap systemfs = new HashMap();
+	
+
+
+ public void shutdown()
+ {
+ 	//if (vfs != null) vfs.shutdown();
+ 	//System.out.println("MemFactory Shutdown: " + home + " datadir: " + dataDirectory);
+ }
+ 
+ 
+ 
+ /**
+  * Construct a persistent StorageFile from a path name.
+  *
+  * @param path The path name of the file. Guaranteed not to be in the temporary file directory. If null
+  *             then the database directory should be returned.
+  *
+  * @return A corresponding StorageFile object
+  */
+  
+StorageFile newPersistentFile( String path)
+{
+//   if( path == null)
+//   	  return {registerFile(new MemoryFile( this, dataDirectory));
+	//System.out.println("MemFile: " + path );
+	//System.out.println("Mem1: " + path);
+   if (path != null && makeDirFile(path)) return new DirFile(separatedDataDirectory+path);
+   if( path == null)
+      return new MemoryFile(this,  dataDirectory);
+   return new MemoryFile(this, dataDirectory, path);
+   //else return new MemoryFile( this, path);
+}
+ 
+ 
+ /**
+  * Construct a persistent StorageFile from a directory and path name.
+  *
+  * @param directory The path name of the directory. Guaranteed not to be in the temporary file directory.
+  *                  Guaranteed not to be null
+  * @param fileName The name of the file within the directory. Guaranteed not to be null.
+  *
+  * @return A corresponding StorageFile object
+  */
+ StorageFile newPersistentFile( String directoryName, String fileName)
+ {
+ 	//System.out.println("MemFile: " + directoryName + "--"  + fileName);
+    //if( directoryName == null || directoryName.length() == 0)
+    //    return newPersistentFile( fileName);
+ 	//System.out.println("Mem2: " + directoryName + " -- " + fileName);
+ 	if (fileName != null && makeDirFile(fileName)) return new DirFile(directoryName, fileName);
+    else return new MemoryFile( this, separatedDataDirectory + directoryName, fileName);
+ }
+
+ /**
+  * Construct a persistent StorageFile from a directory and path name.
+  *
+  * @param directory The path name of the directory. Guaranteed not to be to be null. Guaranteed to be
+  *                  created by a call to one of the newPersistentFile methods.
+  * @param fileName The name of the file within the directory. Guaranteed not to be null.
+  *
+  * @return A corresponding StorageFile object
+  */
+ StorageFile newPersistentFile( StorageFile directoryName, String fileName)
+ {
+ 	//System.out.println("Memfile: " + directoryName + "--" + fileName);
+     //if( directoryName == null)
+    //    return newPersistentFile( fileName);
+ 	
+ 	try
+	{
+    //System.out.println("Mem3: " + directoryName + " -- " + fileName);
+ 	if (fileName != null && makeDirFile(fileName)) return new DirFile(directoryName.getCanonicalPath(), fileName);
+	}
+ 	catch (IOException ex) { ex.printStackTrace();} 
+    return new MemoryFile( (MemoryFile) directoryName, fileName);
+ }
+ 
+
+
+ /**
+  * Does nothing.
+  */
+ public void sync( OutputStream stream, boolean metaData) throws IOException, SyncFailedException
+ {
+     //((FileOutputStream) stream).getFD().sync();
+ }
+
+ /**
+  * This method tests whether the "rws" and "rwd" modes are implemented. If the "rws" method is supported
+  * then the database engine will conclude that the write methods of "rws" mode StorageRandomAccessFiles are
+  * slow but the sync method is fast and optimize accordingly.
+  *
+  * @return <b>true</b> if an StIRandomAccess file opened with "rws" or "rwd" modes immediately writes data to the
+  *         underlying storage, <b>false</b> if not.
+  */
+ public boolean supportsRws()
+ {
+     return true;
+ }
+
+ public boolean isReadOnlyDatabase()
+ {
+     return false;
+ }
+
+ /**
+  * Determine whether the storage supports random access. If random access is not supported then
+  * it will only be accessed using InputStreams and OutputStreams (if the database is writable).
+  *
+  * @return <b>true</b> if the storage supports random access, <b>false</b> if it is writable.
+  */
+ public boolean supportsRandomAccess()
+ {
+     return true;
+ }
+ 
+ public boolean isFast()
+ {	
+ 	return true;
+ }
+ 
+ /**
+  * Get the pathname separator character used by the StorageFile implementation.
+  *
+  * @return the pathname separator character. (Normally '/' or '\').
+  */
+/* public char getSeparator()
+ {
+     // Temp files are always java.io.File's and use its separator.
+     return File.separatorChar;
+ }*/
+ 
+ /**
+  * Get the abstract name of the directory that holds temporary files.
+  *
+  * @return a directory name
+  */
+/* public StorageFile getTempDir()
+ {
+     return tempDir;
+ }*/
+
+
+ 
+ 
+ void doInit() throws IOException
+ {
+ 	 //System.out.print("Init MemStorageFactory...");
+     if( dataDirectory != null)
+     {
+         File dataDirectoryFile = new File( dataDirectory);
+         File databaseRoot = null;
+         if( dataDirectoryFile.isAbsolute())
+             databaseRoot = dataDirectoryFile;
+         else if( home != null && dataDirectory.startsWith( home))
+             databaseRoot = dataDirectoryFile;
+         else
+             databaseRoot = new File( home, dataDirectory);
+         canonicalName = databaseRoot.getCanonicalPath();
+         createTempDir();
+         separatedDataDirectory = dataDirectory + getSeparator();
+     }
+     else if( home != null)
+     {
+         File root = new File( home);
+         dataDirectory = root.getCanonicalPath();
+         separatedDataDirectory = dataDirectory + getSeparator();
+     }
+     
+/*     String[] str = memfs.list("/");
+     for  (int o = 0; o < str.length; o++)
+     {
+     	System.out.println(o + "=" + str[o]);
+     }*/
+    // System.out.println("done! home=" + home);
+     
+     vfs = (VirtualFS)systemfs.get(home);
+     if (vfs == null) 
+     {
+     	vfs = new MemoryFS();
+     	systemfs.put(home, vfs);
+     	
+     }
+     
+     
+ } // end of doInit
+
+private boolean makeDirFile(String path)
+{
+  return path.endsWith(".lck") || path.lastIndexOf("jar") != -1;
+}
+ 
+ 
+}
+

Property changes on: java/engine/org/apache/derby/impl/io/MemoryStorageFactory.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: java/engine/org/apache/derby/impl/io/memory/MemoryFS.java
===================================================================
--- java/engine/org/apache/derby/impl/io/memory/MemoryFS.java	(revision 0)
+++ java/engine/org/apache/derby/impl/io/memory/MemoryFS.java	(revision 0)
@@ -0,0 +1,556 @@
+/*
+
+Derby - Class org.apache.derby.impl.io.memory.MemoryFS
+
+Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable.
+
+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.derby.impl.io.memory;
+
+import org.apache.derby.io.StorageRandomAccessFile;
+
+import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.StringTokenizer;
+import java.util.Vector;
+import java.io.File;
+import org.apache.derby.io.VirtualFS;
+import org.apache.derby.impl.io.MemoryFile;
+import org.apache.derby.io.StorageFile;
+import org.apache.derby.impl.io.memory.MemoryFileNode;
+import org.apache.derby.impl.io.MemoryRandomAccessFile;
+import java.io.IOException;
+
+public class MemoryFS implements VirtualFS
+{
+	/**
+	 * Implementation of a virtual file system specifically for in-memory
+	 * StorageFactory
+	 */
+	
+	
+    /**
+	 * contains a hashtable keyed by pathnames which contains all data written 
+	 * to that "file"
+	 */
+	private Hashtable dbdir;
+	
+	static final int MFS_EXISTS = 0x01;//anything in use will be in the table
+	static final int MFS_REGULAR = 0x02;
+	static final int MFS_DIRECTORY = 0x04;
+	
+	/**
+	 * initialize and store a new filetable
+	 *
+	 */
+	public MemoryFS()
+	{
+		//System.err.println("MEMFS!");
+		dbdir = new Hashtable();
+		
+	}
+	
+	/**
+	 * create a new entry in the filetable and allocate the file if it does not exist
+	 * @param path String 
+	 * @ return boolean - true if file was created. otherwise false.
+	 */
+	public boolean createNewFile(String path) 
+	{
+		MemoryFileNode mem = get(path);
+		if (mem == null)
+		{
+			mem = new MemoryFileNode();
+			register(path, mem);
+			mem.setAttr(MFS_EXISTS);
+			mem.setAttr(MFS_REGULAR);
+			return true;
+		}
+		else 
+	       return false;
+	}
+	
+	/**
+	 * return an output stream
+	 * @param path String
+	 * @return OutputStream
+	 */
+	public OutputStream getOutputStream(String path) throws FileNotFoundException
+	{
+		return getOutputStream(path, false);
+		//System.err.println("getOutputStream() 1 on " + path);
+		
+		
+	}
+	
+	
+	/**
+	 * get an outputstream and possibly append the file it points to
+	 * @param path String
+	 * @param append boolean - if true, append to file
+	 */
+	public OutputStream getOutputStream(String path, boolean append) throws FileNotFoundException
+	 {
+
+		MemoryFileNode mem = get(path);
+		MemoryOutputStream o;
+		if (mem != null) 
+		{
+			if (!hasDirAttr(mem.getAttr()))
+			{
+				o = new MemoryOutputStream(new WritableFileDescriptor(mem.getData()));
+			}
+			else
+			{
+				throw new FileNotFoundException("Virtual file is a directory: " + path);
+			}
+			
+		}
+		else 
+		{
+			if (createNewFile(path))
+			{
+				mem = get(path);
+				o = new MemoryOutputStream(new WritableFileDescriptor(mem.getData()));
+			}
+			else
+				throw new FileNotFoundException("Error creating file");
+			
+		}
+	
+		try
+		{
+			//position stream
+			if (append) o.seek(o.length());
+		}
+		catch (IOException ex)
+		{
+			throw new FileNotFoundException("Error appending to file");
+		}
+		
+		return o;
+	 }
+
+	/**
+	 * get an input stream
+	 * @param path String
+	 * @exception FileNotFoundException if path nto in filetable
+	 */
+	public InputStream getInputStream(String path) throws FileNotFoundException
+	 {
+	 	//System.err.println("getInputStream() on " + path);
+	 	MemoryFileNode mem = get(path);
+		if (mem != null && hasExistAttr(mem.getAttr()) && !hasDirAttr(mem.getAttr()))
+		{
+			return new MemoryInputStream(new ReadOnlyFileDescriptor(mem.getData()));
+		}
+		else throw new 
+		FileNotFoundException("Entry not found in table (getInputStream): " 
+				+ path);
+		
+	 }
+
+	/**
+	 * Return a MemoryStorageRandomAccessFile for the requested file
+	 * allocate it if it exists
+	 * @param path String
+	 * @param mode String
+	 * @return StorageRandomAccessFile
+	 * @exception FileNotFoundException 
+	 */
+	public StorageRandomAccessFile getStorageRandomAccessFile(String path, 
+			String mode) throws FileNotFoundException
+	 {
+	 	//System.err.println("getStorageRandomAccessFile()  on " + path);
+	 	MemoryFileNode mem = get(path);
+		if (mem != null && !hasDirAttr(mem.getAttr()))
+		{
+			if (mem.getData() == null) System.err.println("mem.data is null wtf?");
+			//return new MemoryRandomAccessFile(path, mode, new WritableFileDescriptor(mem.getData()));
+		
+			return new MemoryRandomAccessFile(path, mode, new WritableFileDescriptor(mem.getData()));
+		}
+		else if (mem == null)
+		{
+			if (!createNewFile(path))
+				throw new FileNotFoundException("Entry not found in table1 (getStorageRandomAccessFile): " + path);
+		    return getStorageRandomAccessFile(path, mode);	
+			
+    	}
+		else
+			throw new FileNotFoundException("Entry not found in table2 (getStorageRandomAccessFile): " + path);
+	 }
+	 
+	/**
+	 * can the file be written to?
+	 * @param String path
+	 * @return boolean - true if the file is a regular file and writable, otherwise false
+	 */
+	public boolean canWrite(String path)
+	{
+		MemoryFileNode mem = get(path);
+		if (mem != null)
+		{
+			return hasExistAttr(mem.getAttr()) && !hasDirAttr(mem.getAttr());
+		}
+		return false;
+	}
+	
+	/**
+	 * rename an entry in the filetable
+	 * @param String path
+	 * @return boolean - true if successfulle renamed. otherwise false.
+	 */
+	public boolean renameTo(String path, String newPath)
+	 {
+	 	if (dbdir.containsKey(path))
+	 	{
+	 		dbdir.put(newPath, dbdir.remove(path)); 	
+	 		return true;
+	 	}
+	 	else return false;
+	 }
+	 
+	/**
+	 * delete all paths starting with the given path from the file table.
+	 * @param path String
+	 * @return boolean - true if successful. otherwise false.
+	 */
+	public boolean deleteAll(String path)
+	 {
+	 	Enumeration keys = dbdir.keys();
+	 	if (!keys.hasMoreElements()) 
+	 	{
+	 		//System.err.println("Removing: " + "NULL" + " -- NO Matches with: " + path);
+	 		return true;
+	 	}
+	 	while(keys.hasMoreElements())
+	 	{
+	 		String s = (String)keys.nextElement();
+	 		if (s.lastIndexOf(path) >= 0)
+	 		{
+	 			//System.err.println("Removing: " + s + " -- Matches with: " + path);
+	 			dbdir.remove(s);
+	 		}
+	 	}
+	 	return true;
+	 }
+	 
+	/**
+	 * delete an entry from the file table if it exists
+	 * @param path String
+	 * @return boolean - true if successful. else false.
+	 */
+	public boolean delete(String path)
+	 {
+	 	//System.err.println("Delete: " + path);
+	 		return dbdir.remove(path) != null;
+	 }
+	 
+	/**
+	 * does an entry with the given path exist in the file table?
+	 * @param path String 
+	 * @return boolean true if the path is in the file table and exists
+	 */
+	public boolean exists(String path)
+	 {
+	 	MemoryFileNode mem = get(path);
+	 	
+	 	if (mem != null) return hasExistAttr(mem.getAttr());
+	 	else return false;
+	 }
+	 
+	 
+	 /**
+	  * Get the names of all files and sub-directories in the directory named by this path name.
+	  *
+	  * @param path String
+	  * @return An array of the names of the files and directories in this
+	  *         directory denoted by this abstract pathname. The returned array will have length 0
+	  *         if this directory is empty. Returns null if this StorageFile is not  a directory, or
+	  *         if an I/O error occurs.
+	  */
+	public String[] list(String path)
+	 {
+	 	//System.err.println("LIST FOR:" + path);
+		Enumeration keys = dbdir.keys();
+	 	if (!keys.hasMoreElements()) 
+	 	{
+	 		//System.err.println("List(): " + "NULL" + " -- NO Matches with: " + path);
+	 		return null;
+	 	}
+	    Vector v = new Vector();
+	 	while(keys.hasMoreElements())
+	 	{
+	 		String s = (String)keys.nextElement();
+	 		//System.err.println("Find Match for: " + path + " try: " + s  + " = " + s.indexOf(path) + " lidx of file sep=" + s.lastIndexOf(File.separator));
+	 		int idx = s.indexOf(path);
+	 		if (idx == 0 && s.lastIndexOf(File.separator) <= path.length() && !path.equals(s))
+	 		{
+	 			//System.err.println("FOUND MATCH: " + s + " -- Matches with: " + s.substring(path.length()+1));
+	 			v.add(s.substring(path.length()+1));
+	 		}
+	 	}
+	 	//System.err.println("Done List()");
+	 	String[] s = new String[v.size()];
+	 	for (int i = 0; i < s.length; ++i)
+	 	{
+	 		s[i] = (String)v.elementAt(i);
+	 	}
+	 	v = null;
+	 	return s;
+	 }
+	 
+	 /**
+	  * Tests whether the named file is a directory, or not. This is only called in writable storage factories.
+	  *
+	  * @param path String
+	  * @return <b>true</b> if named file exists and is a directory, <b>false</b> if not.
+	  *          The return value is undefined if the storage is read-only.
+	  */
+	public boolean isDirectory(String path)
+	 {
+		//System.err.print("ISDIR: " + path);
+	 	MemoryFileNode mem = get(path);
+	 	if (mem != null)
+	 	{
+	 		//System.err.println("!=null -- " + hasDirAttr(mem.getAttr()));
+	       return hasDirAttr(mem.getAttr());
+	 	}
+	 	else 
+	 	{
+	 		//System.err.println("=null -- " + false);
+	 		return false;
+	 	}
+	 }
+	
+	 
+	 /**
+	  * Creates the named directory.
+	  *
+	  * @param mem StorageFile - used to get the parent of a file
+	  * @param path String
+	  * @return <b>true</b> if the directory was created; <b>false</b> if not.
+	  */
+	public boolean mkdir(StorageFile mem, String path)
+	 {
+		
+		//System.err.print("mkdir: " + path + " -- ");
+	   	StorageFile s = mem.getParentDir();
+    	if (s == null || s.isDirectory())
+    	{
+    		MemoryFileNode n = new MemoryFileNode();
+			register(path, n);
+			n.setAttr(MFS_EXISTS);
+			n.setAttr(MFS_DIRECTORY);
+    	    return true;
+    	}
+    	else return false;
+
+	     
+	 }
+
+	 /**
+	  * Creates the named directory, and all nonexistent parent directories.
+	  *
+	  *	@param mem StorageFile - used to get the parent of a file
+	  * @param path String
+	  * @return <b>true</b> if the directory was created, <b>false</b> if not
+	  */
+	public boolean mkdirs(StorageFile mem, String path)
+	 {
+		//System.err.println("mkdirs: " + path);
+    	StorageFile f = mem.getParentDir();
+    	if (f == null || f.isDirectory())
+    	{
+    		return mkdir(mem, path);
+    	}
+    	else
+		{
+    		if (f.exists()) return false;
+    		else if (f.mkdirs())
+    		{
+    			return mkdir(mem, path);
+    		}
+    		else return false;
+		}
+	 	/*
+	 	StringTokenizer s = new StringTokenizer(path, "/");
+	 	String t = "";
+	    while(s.hasMoreTokens())
+	    {
+	    	t = t + "/" + s.nextToken();
+	    	boolean b = mkdir(t);
+	    	if (!s.hasMoreTokens())	
+	        {
+	    		System.err.println("mkdirs done " + b);
+	    		return b;
+	        }
+	    	
+	    }
+	    return false;*/
+	 }
+	 
+	/**
+	 * length of the file pointed to byt he abstract path
+	 * 
+	 * @param path String
+	 * @return long - length of file if it exists, otherwise 0
+	 */
+	public long length(String path)
+	 {
+	    MemoryFileNode mem = get(path);
+	    if (mem != null)
+	    {
+	    	return mem.length();
+	    }
+	    return 0;
+
+
+
+	 }
+	 
+	/*public boolean setReadOnly(String path)
+	 {
+	 	MemoryFile mem = get(path);
+	 	if (mem != null)
+	 	{
+	 		mem.setReadOnly(true);
+	 		return true;
+	 	}
+	 	return false;
+	 }*/
+	 
+	/**
+	 * adds a path and the file node for it to the filetable
+	 * @param path String
+	 * @param m MemoryFileNode - file node to add to the filetable
+	 */
+	public void register(String path, MemoryFileNode m)
+	 {
+	 	if (path.endsWith("/")) dbdir.put(path.substring(0, path.length()-1), m);
+	 	else dbdir.put(path, m);
+	 }
+	 
+	/**
+	 * get a filenode from the file table
+	 * @param path String
+	 * @return MemoryfileNode
+	 */
+	 private MemoryFileNode get(String path)
+	 {
+	 	//if (path.endsWith("/")) 
+	 		//System.err.println("Putting: " + path.substring(0, path.length()-1));
+	 	
+	 	if (path.endsWith("/")) return (MemoryFileNode)dbdir.get(path.substring(0, path.length()-1));
+	 	return (MemoryFileNode)dbdir.get(path);
+	 }
+	 
+	/* public StorageFile existsInTable(String path)
+	 {
+	 	return get(path);
+	 }*/
+	 
+/*	 public boolean createNewFile(String path)
+	 {
+	 	MemoryFile mem = get(path);
+	 	if (mem != null && !exists(path))
+	 	{
+	 		mem.setExists(true);
+	 		return true;
+	 	}
+	 	else return false;
+	 }*/
+	 /*public StorageFile registerFile(MemoryFile m)
+	 {
+	 	System.err.println("Hashtable put: " + m.getCanonicalPath());
+		MemoryFile e;
+		String s = m.getCanonicalPath();
+		if (s.endsWith("/"))
+		{
+			e = (MemoryFile)existsInTable(s.substring(s.length()-1));
+		}
+		else
+		{
+		   e = (MemoryFile)existsInTable(m.getCanonicalPath());
+		}
+	 	  //if ((vfs.existsInTable(m.getCanonicalPath()))) //System.err.println("ATTEMPTED Hashtable put: " + m.getCanonicalPath());
+		if (e != null)
+	 	{
+	 	   return e;  	
+	 	}
+	 	  else 
+	 	  {
+	 	  	 // System.err.println("Hashtable put: " + m.getCanonicalPath());
+	 	  	  register(m.getCanonicalPath(), m);
+	 	  	return m;
+	 	  }
+	 	  
+	 }*/
+	 
+	 /**
+	  * do these attributes have the directory flag?
+	  * @param attr int
+	  * @return boolean - if the given attributes have the directory flag
+	  */
+	 private boolean hasDirAttr(int attr)
+	 {
+	 	return (attr & MFS_DIRECTORY) == MFS_DIRECTORY;
+	 }
+	
+	 /**
+	  * do these attributes have the exists flag?
+	  * @param attr int
+	  * @return boolean - if the given attributes have the exists flag
+	  */
+	 private boolean hasExistAttr(int attr)
+	 {
+	 	return (attr & MFS_EXISTS) == MFS_EXISTS;
+	 }
+	 
+	 /**
+	  * do these attributes have the regular flag?
+	  * @param attr int
+	  * @return boolean - if the given attributes have the regular flag
+	  */
+	 private boolean hasRegularAttr(int attr)
+	 {
+	 	return (attr & MFS_REGULAR) == MFS_REGULAR;
+	 }
+	 
+	 public void shutdown()
+	 {
+	 	Enumeration keys = dbdir.keys();
+	 	if (!keys.hasMoreElements()) 
+	 	{
+	 		return;
+	 	}
+	 	while(keys.hasMoreElements())
+	 	{
+	 		String s = (String)keys.nextElement();
+
+	 			dbdir.remove(s);
+	 		
+	 	}
+	 }
+
+	 
+	 
+}

Property changes on: java/engine/org/apache/derby/impl/io/memory/MemoryFS.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: java/engine/org/apache/derby/impl/io/memory/MemoryInputStream.java
===================================================================
--- java/engine/org/apache/derby/impl/io/memory/MemoryInputStream.java	(revision 0)
+++ java/engine/org/apache/derby/impl/io/memory/MemoryInputStream.java	(revision 0)
@@ -0,0 +1,183 @@
+/*
+
+Derby - Class org.apache.derby.impl.io.memory.MemoryInputStream
+
+Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable.
+
+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.derby.impl.io.memory;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+
+public class MemoryInputStream extends InputStream
+{
+	/**
+	 * seekable inputstream.
+	 */
+	private ReadOnlyFileDescriptor fd;
+	private long mark = -1;
+	private int markLimit;
+	
+   /**
+    * Make an Inputstream using a Read-only file descriptor
+    * @param f ReadOnlyFileDescriptor
+    */
+	public MemoryInputStream(ReadOnlyFileDescriptor f)
+	{
+		fd = f;
+	}
+	
+    /**
+     * how many bytes are available without blocking? all of them!
+     * @return int 
+     * @exception IOException - shouldnt be one tho.
+     */
+	public int available() throws IOException
+	{
+		
+		long avail = fd.length() - fd.getFilePointer();
+		return (avail > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)avail);
+	}
+	
+	/**
+	 * does nothing in an in-memory implementation.
+	 */
+	public void close()
+	{
+		
+	}
+	
+	/**
+	 * remember a position so you can go back to it later
+	 * @param readlimit int - max number of bytes to remember
+	 */
+	public void mark(int readlimit)
+	{
+		mark = fd.getFilePointer();
+		markLimit = readlimit;
+	}
+	
+   /**
+    * resets the filepointer to the saved position if there is one
+    * @exception IOException if the saved mark is invalid
+    */
+	public void reset()  throws IOException
+	{
+		if (mark !=-1 && fd.getFilePointer() - mark <= markLimit) fd.seek(mark);
+		else throw new IOException("reset() due to invalid mark");
+	}
+	
+
+	/**
+	 * is mark supported?
+	 * @return boolean true
+	 */
+	public boolean markSupported() 
+	{
+		return true;
+	}
+	
+	
+	/**
+	 * skip ahead n bytes
+	 * @param n long - number of bytes to skip ahead
+	 * @return long - new stream position
+	 * @exception IOException
+	 */
+	public long skip(long n) throws IOException
+	{
+		long newPos = fd.getFilePointer()+n;
+		if (newPos <= fd.length())
+		{
+			fd.seek(newPos);
+			return n;
+		}
+		else
+		{
+			long oldPos = fd.getFilePointer();
+			fd.seek(fd.length());
+			return (fd.length() - oldPos);
+		}
+	}
+	
+	/**
+	 * read one byte.
+	 * @return int
+	 * @exception IOException - if there's a problem.
+	 */
+	public int read() throws IOException
+	{
+		return fd.read();
+	}
+	
+	/**
+	 * read bytes into an array
+	 * @param b byte[]
+	 * @return int - number of bytes read
+	 * @exception IOException - if there's a problem
+	 */
+	public int read(byte[] b) throws IOException
+	{
+		return fd.read(b);
+	}
+	
+	/**
+	 * read a certain amout of bytes into an array at an offset 
+	 * @param b byte[]
+	 * @param off int - offset for b
+	 * @param len int - number of bytes to read
+	 * @return int - number of bytes read
+	 * @exception IOException - if there's a problem
+	 */
+	public int read(byte[] b, int off, int len) throws IOException
+	{
+		return fd.read(b, off, len);
+	}
+	
+	/**
+	 * get the current position
+	 * @return long - current position
+	 */
+	public long getFilePointer()
+	{
+		return fd.getFilePointer();
+	}
+	
+	/**
+	 * get the length
+	 * @return long - length
+	 * @throws IOException
+	 */
+	public long length() throws IOException
+	{
+		return fd.length();
+	}
+	
+	/**
+	 * seek the stream. 
+	 * @param newPos long - new file position!
+	 * @throws IOException
+	 */
+	public void seek(long newPos) throws IOException
+	{
+		fd.seek(newPos);
+	}
+	
+	
+	
+}
\ No newline at end of file

Property changes on: java/engine/org/apache/derby/impl/io/memory/MemoryInputStream.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: java/engine/org/apache/derby/impl/io/memory/MemoryOutputStream.java
===================================================================
--- java/engine/org/apache/derby/impl/io/memory/MemoryOutputStream.java	(revision 0)
+++ java/engine/org/apache/derby/impl/io/memory/MemoryOutputStream.java	(revision 0)
@@ -0,0 +1,129 @@
+/*
+
+Derby - Class org.apache.derby.impl.io.memory.MemoryOutputStream
+
+Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable.
+
+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.derby.impl.io.memory;
+
+import java.io.OutputStream;
+import java.io.IOException;
+public class MemoryOutputStream extends OutputStream
+{
+	/**
+	 * seekable outputstream.
+	 */
+	private WritableFileDescriptor fd;
+	
+	/**
+	 * make an output stream usinf a writable file descriptor
+	 * @param f WritableFileDescriptor
+	 */
+	public MemoryOutputStream(WritableFileDescriptor f)
+	{
+		fd = f;
+	}
+
+	/**
+	 * 
+	 */
+	public void close()
+	{
+		
+	}
+
+	/**
+	 * 
+	 */
+	public void flush()
+	{
+		
+	}
+	
+	/**
+	 * write one byte
+	 * @param b byte
+	 * @exception IOException
+	 */
+	public void write(int b) throws IOException
+	{
+		fd.write(b);
+	}
+	
+	/**
+	 * write bytes from an array
+	 * @param b byte[]
+	 * @exception IOException - if there's a problem
+	 */
+	public void write(byte[] b) throws IOException
+	{
+		fd.write(b);
+	}
+	
+	/**
+	 * write a certain amout of bytes from an array at an offset 
+	 * @param b byte[]
+	 * @param off int - offset for b
+	 * @param len int - number of bytes to write
+	 * @exception IOException - if there's a problem
+	 */
+	public void write(byte[] b, int off, int len) throws IOException
+	{
+		fd.write(b, off, len);
+	}
+	
+	/**
+	 * seek to a new position in the stream, possibly past EOF!
+	 * @param newPos long
+	 * @throws IOException
+	 */
+	public void seek(long newPos) throws IOException
+	{
+		fd.seek(newPos);
+	}
+	
+	/**
+	 * get the position
+	 * @return long - position
+	 */
+	public long getFilePointer()
+	{
+		return fd.getFilePointer();
+	}
+	
+	/**
+	 * aduh.
+	 * @return long - length
+	 * @throws IOException
+	 */
+	public long length() throws IOException
+	{
+		return fd.length();
+	}
+	
+	/**
+	 * sets the file length.
+	 * @param newLen long
+	 * @throws IOException
+	 */
+	public void setLength(long newLen) throws IOException
+	{
+		fd.setLength(newLen);
+	}
+	
+	
+}
\ No newline at end of file

Property changes on: java/engine/org/apache/derby/impl/io/memory/MemoryOutputStream.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: java/engine/org/apache/derby/impl/io/memory/BlockedByteArray.java
===================================================================
--- java/engine/org/apache/derby/impl/io/memory/BlockedByteArray.java	(revision 0)
+++ java/engine/org/apache/derby/impl/io/memory/BlockedByteArray.java	(revision 0)
@@ -0,0 +1,430 @@
+/*
+
+   Derby - Class org.apache.derby.impl.io.memory.BlockedByteArray
+
+   Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable.
+
+   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.derby.impl.io.memory;
+
+
+
+import java.io.IOException;
+import org.apache.derby.io.VirtualFileData;
+
+/**
+ * 	An array of byte arrays masquerading as a single byte array.
+ * 	allows dynamic access and resizable.
+ * 	No stream positioning present.
+ */
+
+
+public class BlockedByteArray implements VirtualFileData
+{
+	//minimum numbers of blocks to add when resizing
+	protected static int BLOCKS_TO_ADD = 4;
+	
+	//block size
+	protected static int BLOCK_SIZE = 4*1024;
+
+	protected byte[][] buf;
+	protected long		used;		// how many bytes are used
+	
+	//number of allocated blocks. Is <= buf.length
+	protected int allocatedBlocks = 0;
+	
+
+
+	public BlockedByteArray() {
+		this(BLOCKS_TO_ADD);
+	}
+
+	/**
+	 * 
+	 * @param size int - initial number of blocks to allocate
+	 */
+	public BlockedByteArray(int size) {
+
+		buf = new byte[size][BLOCK_SIZE];
+		allocatedBlocks = size;
+	}
+
+
+
+
+
+	/**
+	 *	write a byte at a particular position. alocates more space if necessary
+	 * @param byte b
+	 * @param long position
+	 */
+	public synchronized void write(int b, long position) 
+	{
+		int block = calculateBlock(position);
+		int index = calculateIndex(position);
+		if (exceedsAllocatedSpace(block)) allocate(block);
+
+
+		buf[block][index] = (byte) b;
+
+		if (position > used)
+			used = position;
+		else used++;
+	}
+	
+	/**
+	 *	write part of a byte array at a particular position. 
+	 * alocates more space if necessary
+	 * @param byte[] b - bytes to write
+	 * @param int offset - offset of data in b
+	 * @param int len - number of bytes to write
+	 * @param long position
+	 */
+	public synchronized void write(byte[] b, int off, int len, long position) 
+	{
+
+		int lastBlock = calculateBlock(position+len);
+		int lastIndex = calculateIndex(position+len);
+
+		if (exceedsAllocatedSpace(lastBlock)) allocate(lastBlock);
+
+		//calculatePosition(position);
+		int block = calculateBlock(position);
+		int index = calculateIndex(position);
+		
+		int offset = off;
+
+		//System.err.print(" Write Lastblock: " + lastBlock + " lastIndex: " + lastIndex);
+		//System.err.print(" block: " + block + " index: " + index);
+        //System.err.print(" position: " + position + " len: " + len);
+	    //System.err.println(" used: " + used + " allocatedBlocks: " + allocatedBlocks);
+//		}
+//else System.err.println();
+		while(block <= lastBlock)
+		{ 
+			int length= 0;
+
+			//if we're at our last block calculate the index of the final byte
+			if (block == lastBlock)
+			{
+			   
+			   length = lastIndex - index;	
+               if (length == 0) 
+               { 
+			      break;
+			   }	
+			}
+			else
+			{
+				length = BLOCK_SIZE - index;
+			}
+			//System.err.print("Block:" + block + " index: " + index);
+			//System.err.println("b.len=" + b.length +" offset=" + offset +" len=" + length);
+			
+			
+			//if (buf[block] == null) System.err.println("WTF NULL BLOCK!?");
+			System.arraycopy(b, offset, buf[block], index, length);
+
+			position += length;
+			offset += length;
+
+			if (position > used) used = position;
+			
+			if (block == lastBlock) break;
+            block++;
+            index = 0;
+
+
+		}
+
+	}
+
+	
+	/*
+	 *	Specific methods
+	 */
+
+	/**
+		Reset the stream for reuse
+	*/
+/*	public void reset()
+	{
+		used = 0;
+	}*/
+
+	
+	/**
+		Get the number of bytes that was used.
+	*/
+	public long getUsed()
+	{
+		return used;
+	}
+
+
+
+
+
+	/**
+	 * Used to allocate space if seek goes beyond the end of the array. 
+	 * does not handle posititioning.
+	 * @param newPosition long - 
+	*/
+	public void seek(long newPosition)
+	{
+		//calculatePosition(newPosition);
+		int block = calculateBlock(newPosition);
+		int index = calculateIndex(newPosition);
+		if (exceedsAllocatedSpace(block)) allocate(block);
+
+		used = block*BLOCK_SIZE + index;
+	}
+
+
+
+
+
+	
+	
+
+	/**
+	 * get the number of used bytes
+	 */
+	public long length()  
+	{
+	   return getUsed();
+	}
+		
+	/**
+	 * set the length of the file. expand if larger, deallocate if smaller.
+	 * @param newLength int - new length of the file
+	 */
+	public synchronized void setLength(long newLength) throws IOException {
+		
+		int block = calculateBlock(newLength);
+		int index = calculateIndex(newLength);
+
+		if (exceedsAllocatedSpace(block)) allocate(block);
+		else if (newLength < used) deallocate(block);
+		used = newLength;
+	}
+
+
+	
+
+	public void close()
+	{
+		//?
+	}
+	
+	/**
+	 * read one byte at the given position.
+	 * @param position long - position to read from
+	 */
+	public synchronized int read(long position) throws IOException
+	{
+		//System.err.println("Read() pos=" + position + " used=" + used);
+		int block = calculateBlock(position);
+		int index = calculateIndex(position);
+		if (position < used)
+		   return buf[block][index] & 0xff;
+		//should I be throwing an exception here? EOFException?
+		return -1;
+	}
+	
+	/**
+	 * read len bytes starting at position position into b at offset off
+	 * @param b byte[] - read bytes into this
+	 * @param off int - offset in b
+	 * @param len int - number of bytes to read
+	 * @param position long - where to start the read
+	 * @return int - number of bytes read. -1 for error
+	 */
+	public synchronized int read(byte b[], int off, int len, long position) throws IOException
+    {
+		//if file pointer positioning is somehow off
+		if (position >= used) return -1;
+		
+		/* if we're trying to read past the end of the array, 
+		only read to the end of the array */
+	    if (position + len > used) 
+	    {
+	        len = (int)(used - position);
+	    }
+	    
+	    //we're not reading anything (?)
+	    if (len <= 0) 
+	    {
+	        return 0;
+	    }
+	    
+
+        int read = 0;
+
+		int lastBlock = calculateBlock(position+len);
+		int lastIndex = calculateIndex(position+len);
+
+		int block = calculateBlock(position);
+		int index = calculateIndex(position);
+		int offset = off;
+		//System.err.print(" Read  Lastblock: " + lastBlock + " lastIndex: " + lastIndex);
+		//System.err.print(" block: " + block + " index: " + index);
+		//	System.err.print(" position: " + position + " len: " + len);
+	    //System.err.println(" used: " + used + " allocatedBlocks: " + allocatedBlocks);
+/*			System.err.println("Lastblock: " + lastBlock + " lastIndex: " + lastIndex);
+			System.err.println("used: " + used + " allocatedBlocks: " + allocatedBlocks);
+			System.err.print(" Read Lastblock: " + lastBlock + " lastIndex: " + lastIndex);
+			System.err.print(" block: " + block + " index: " + index);
+			System.err.println(" position: " + position + " len: " + len);
+			System.err.println("used: " + used + " allocatedBlocks: " + allocatedBlocks);*/
+		while(block <= lastBlock)
+		{
+				//int length = (block == lastBlock ? lastIndex : BLOCK_SIZE - index);
+			int length;
+			if (block == lastBlock)
+			{
+				   
+			   length = lastIndex - index;	
+               if (length == 0)
+               { 
+				  break;
+               }
+			}
+			else
+			{
+				length = BLOCK_SIZE - index;
+			}
+				//System.err.println("Block:" + block + " index: " + index);
+				//System.err.println("b.len=" + b.length +" offset=" + offset +" len=" + length);
+		
+			System.arraycopy(buf[block], index, b, offset, length);
+			read += length;
+					
+
+			position += length;
+			offset += length;
+			if (block == lastBlock) break;
+            block++;
+            index = 0;
+
+
+		}
+
+return read;
+
+    }
+	
+	/**
+	 * calculates the block for a given position
+	 * @param pos long - position to calculate
+	 * @return int - the block where position falls
+	 */
+	private int calculateBlock(long pos)
+	{
+		//possible loss of precision or overflow
+		//but you need like Integer.MAX_VALUE * BLOCK_SIZE for it
+		return (int)(pos/BLOCK_SIZE);		
+	}
+	
+	/**
+	 * calculates the index within a block for a given position
+	 * @param pos long - position to calculate
+	 * @return int - index of position in whatever block its in
+	 */
+	private int calculateIndex(long pos)
+	{
+        return (int)(pos % BLOCK_SIZE); 
+	}
+	
+	/**
+	 * does the given block exceed the space currently allocated?
+	 * @param block int - the block in question
+	 * @return boolean - true if there is enough space. otherwise false.
+	 */
+	private synchronized boolean exceedsAllocatedSpace(int block)
+	{
+		return block >= allocatedBlocks;
+	}
+	
+	/**
+	 * does the given position exeed the number of valid bytes stored?
+	 * @param position long - the position in question
+	 * @return boolean - true if the position is greater or equal to the number
+	 * of used bytes. otherwise false.
+	 */
+	private synchronized boolean exceedsUsedSpace(long position)
+	{
+		return position >= used; 
+	}
+	
+	/**
+	 * allocate up to and including the specified block
+	 * @param block int - number of blocks to have allocated
+	 */
+	private synchronized void allocate(int block)
+	{
+		//System.err.println("alloc--block=" + block + " buf.len=" + buf.length);
+		
+		if (block >= buf.length) expandBuffer(block+1);
+		
+		//System.err.println("Allocating up to block " + block);
+		for (int i = allocatedBlocks; i <= block; ++i)
+		{
+			//System.err.println("A")
+			buf[i] = new byte[BLOCK_SIZE];
+			allocatedBlocks++;
+		}
+	}
+	
+	/**
+	 * deallocate due to shrinkage. new size = given number of blocks
+	 * @param block int - number of block to leave in tact
+	 */
+	private synchronized void deallocate(int block)
+	{
+		//System.err.println("DEALLOC -- from: " + allocatedBlocks + " to: " + block);
+		
+		for (int i = buf.length-1; i >=0; i--)
+		{
+			if (i > block) buf[i] = null;
+			else break;
+		}
+		allocatedBlocks = block;
+	}
+	
+	/**
+	 * expand the buffer by max(minSize, min blocks to expand by)
+	 * @param minSize int - minimum number of blocks to expand by
+	 */
+	protected void expandBuffer(int minSize)
+	{
+		
+	    if (minSize >= buf.length)
+	    {
+	    	int max = Math.max(minSize, buf.length+BLOCKS_TO_ADD);
+	    	//System.err.print("Exapnding buffer to " +  max + "--");
+	    	
+			byte[][] b = new byte[max][];
+			System.arraycopy(buf, 0, b, 0, buf.length); 
+			buf = b;
+		}
+	
+	    
+			
+	}
+
+}

Property changes on: java/engine/org/apache/derby/impl/io/memory/BlockedByteArray.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: java/engine/org/apache/derby/impl/io/memory/WritableFileDescriptor.java
===================================================================
--- java/engine/org/apache/derby/impl/io/memory/WritableFileDescriptor.java	(revision 0)
+++ java/engine/org/apache/derby/impl/io/memory/WritableFileDescriptor.java	(revision 0)
@@ -0,0 +1,108 @@
+/*
+
+Derby - Class org.apache.derby.impl.io.memory.WritableFileDescriptor
+
+Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable.
+
+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.derby.impl.io.memory;
+import java.io.IOException;
+import org.apache.derby.io.VirtualFileData;
+public class WritableFileDescriptor extends ReadOnlyFileDescriptor
+{
+	/**
+	 * writable extension of a read-only file descriptor
+	 * @param b
+	 */
+
+	/**
+	 * @param b VirtualFileData
+	 */
+	public WritableFileDescriptor(VirtualFileData b)
+	{
+		super(b);
+	}
+	
+	/**
+	 * write a byte
+	 * @param b int - byte to write
+	 * @throws IOException
+	 */
+	public synchronized void write(int b) throws IOException
+	{
+		vf.write(b, getFilePointer());
+		position++;
+	}
+	
+	/**
+	 * write a byte array
+	 * @param b byte[]
+	 * @throws IOException
+	 */
+	public synchronized void write(byte[] b) throws IOException
+	{
+		write(b, 0, b.length);
+	}
+	
+	/**
+	 * write a certain amout of bytes from an array at an offset 
+	 * @param b byte[]
+	 * @param off int - offset for b
+	 * @param len int - number of bytes to write
+	 * @exception IOException - if there's a problem
+	 */
+	public synchronized void write(byte[]b, int off, int len) throws IOException
+	{
+		vf.write(b, off, len, position);
+		position += len;
+	}
+	
+	/**
+	 * seek. possibly beyond EOF!
+	 * @paqam newPosition long
+	 * @exception IOException
+	 */
+	public void seek(long newPosition) throws IOException
+	{
+		//System.out.println("WDF SEEK!: " + newPosition);
+		if (newPosition > vf.length()) vf.setLength(newPosition);
+		//	System.out.println("WDF SEEK2!: " + position);
+		position = newPosition;
+	}
+	
+	/**
+	 * 
+	 *
+	 */
+	public void flush()
+	{
+		
+	}
+	
+	/**
+	 * adjust file length
+	 * @param newLen long - new file length
+	 * @throws IOException
+	 */
+	public void setLength(long newLen) throws IOException
+	{
+		vf.setLength(newLen);
+		if (position > newLen) position = newLen; 
+	}
+	   
+	   
+	
+
+}
\ No newline at end of file

Property changes on: java/engine/org/apache/derby/impl/io/memory/WritableFileDescriptor.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: java/engine/org/apache/derby/impl/io/memory/ReadOnlyFileDescriptor.java
===================================================================
--- java/engine/org/apache/derby/impl/io/memory/ReadOnlyFileDescriptor.java	(revision 0)
+++ java/engine/org/apache/derby/impl/io/memory/ReadOnlyFileDescriptor.java	(revision 0)
@@ -0,0 +1,124 @@
+/*
+
+Derby - Class org.apache.derby.impl.io.memory.ReadOnlyFileDescriptor
+
+Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable.
+
+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.derby.impl.io.memory;
+import org.apache.derby.io.VirtualFileData;
+import java.io.IOException;
+
+public class ReadOnlyFileDescriptor
+{
+	/** read only wrapper for a VirtualFileData object
+	 * 
+	 */
+   //file (?) or stream(?) position
+   protected long position;
+   protected VirtualFileData vf;
+   
+   /**
+    * 
+    * @param v VirtualFileData
+    */
+   public ReadOnlyFileDescriptor(VirtualFileData v)
+   {
+   	  vf = v;
+   	  position = 0;
+   }
+   
+   /**
+    * 
+    *
+    */
+   public void close()
+   {
+   	
+   }
+   
+   /**
+    * read one byte
+    * @return int - the byte read
+    * @exception IOException
+    */
+   public synchronized int read() throws IOException
+   {
+   	  return vf.read(position++);
+   }
+   
+   /**
+    * read b.length bytes
+    * @param b byte[]
+    * @return int - number of bytes read
+    * @exception IOException
+    */
+   public synchronized int read(byte[] b) throws IOException
+   {
+   	   return read(b, 0, b.length);
+   }
+   
+	/**
+	 * read a certain amout of bytes into an array at an offset 
+	 * @param b byte[]
+	 * @param off int - offset for b
+	 * @param len int - number of bytes to read
+	 * @return int - number of bytes read
+	 * @exception IOException - if there's a problem
+	 */
+   public synchronized int read(byte[] b, int off, int length) throws IOException
+   {
+   	//System.out.print("readFullyFD=" + " len=" + b.length + " off=" + off);
+   	  int bytesRead = vf.read(b, off, length, position);
+   	  position += bytesRead;
+   	 // System.out.println(" read=" + bytesRead + " postpos=" + position + " size=" + vf.length());
+   	  return bytesRead;
+   }
+   
+   /**
+    * get the current position
+    * @return long - position
+    */
+   public long getFilePointer()
+   {
+   	  return position;
+   }
+   
+   /**
+    * seek the damned stream! but only til the end!
+    * @param newPosition long - new position
+    * @throws IOException - if new position > file length
+    */
+   public void seek(long newPosition) throws IOException
+   {
+   	  if (newPosition > vf.length()) throw new IOException("seek exceeds virtual file size");
+   	  else position = newPosition;
+   }
+   
+   /**
+    * length
+    * @return long - length
+    * @throws IOException
+    */
+   public long length() throws IOException
+   {
+   	  return vf.length();
+   }
+   
+   
+
+}
\ No newline at end of file

Property changes on: java/engine/org/apache/derby/impl/io/memory/ReadOnlyFileDescriptor.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: java/engine/org/apache/derby/impl/io/memory/MemoryFileNode.java
===================================================================
--- java/engine/org/apache/derby/impl/io/memory/MemoryFileNode.java	(revision 0)
+++ java/engine/org/apache/derby/impl/io/memory/MemoryFileNode.java	(revision 0)
@@ -0,0 +1,92 @@
+/*
+
+Derby - Class org.apache.derby.impl.io.memory.MemoryFileNode
+
+Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable.
+
+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.derby.impl.io.memory;
+import org.apache.derby.impl.io.memory.MemoryFS;
+import org.apache.derby.io.VirtualFileData;
+//import org.apache.derby.impl.io.memory.DynamicByteArrayIOStream;
+
+public class MemoryFileNode 
+{
+	/**
+	 * a node representing virtual file attributes and data (if allocated)
+	
+    */	
+	
+	
+	int attr = 0;
+	private VirtualFileData data = null;
+	
+	/**
+	 * set the passed attribute if not already set.
+	 * if we're makign a regular "file, allocate it
+	 * @param newAttr int - the attribute to add
+	 */
+	public void setAttr(int newAttr)
+	{
+		if ((attr & newAttr) != newAttr) attr += newAttr;
+		if ((newAttr & MemoryFS.MFS_REGULAR) == MemoryFS.MFS_REGULAR) data = new BlockedByteArray();
+		//if ((newAttr & MemoryFS.MFS_REGULAR) == MemoryFS.MFS_REGULAR) data = new DynamicByteArrayIOStream();
+		
+	}
+	
+	/**
+	 * unset the passed attribute. deallocate the data if it is no longer a 
+	 * regular "file"
+	 * @param unAttr int - attribute to unset
+	 */
+	public void unsetAttr(int unAttr)
+	{
+		if ((attr & unAttr) == unAttr) attr -= unAttr;
+		if ((unAttr & MemoryFS.MFS_EXISTS) == MemoryFS.MFS_EXISTS) data = null;
+		if ((unAttr & MemoryFS.MFS_REGULAR) == MemoryFS.MFS_REGULAR) data = null;
+	}
+	
+	/**
+	 * get the attributes
+	 * @return int - the attributes represented by an int
+	 */
+	public int getAttr()
+	{
+		return attr;
+	}
+	
+	/**
+	 * returns the raw container for the data in this "file"
+	 * @return VirtualFileData - the data of this node
+	 */
+	public VirtualFileData getData()
+	{
+		return data;
+	}
+	
+	/**
+	 * length of "file
+	 * @return long - length of file is allocated
+	 */
+	public long length()
+	{
+		if (data != null) return data.length();
+		else return 0;
+	}
+	
+
+	
+
+}

Property changes on: java/engine/org/apache/derby/impl/io/memory/MemoryFileNode.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: java/engine/org/apache/derby/impl/io/memory/build.xml
===================================================================
--- java/engine/org/apache/derby/impl/io/memory/build.xml	(revision 0)
+++ java/engine/org/apache/derby/impl/io/memory/build.xml	(revision 0)
@@ -0,0 +1,76 @@
+<?xml version="1.0"?>
+
+<project default="compile_impl_io" basedir="../../../../../../../..">
+
+<!-- Set Properties -->
+  <!-- User settings -->
+  <property file="${user.home}/ant.properties"/>
+  <!-- Set property lib dir -->
+  <property name="properties.dir" value="tools/ant/properties"/>
+  <!-- Significant dirs -->
+  <property file="${properties.dir}/dirs.properties"/>
+  <!-- Compiler settings -->
+<property file="${properties.dir}/defaultcompiler.properties"/> 
+  <property file="${properties.dir}/${build.compiler}.properties"/>
+  <!-- Compile-time classpath properties files -->
+  <property file="${properties.dir}/extrapath.properties"/>
+  <property file="${properties.dir}/compilepath.properties"/>
+
+<!-- Targets -->
+
+  <target name="compile_impl_io_memory">
+    <javac
+      bootclasspath="${empty}"
+      nowarn="on"
+      debug="${debug}"
+      depend="${depend}"
+      deprecation="${deprecation}"
+      optimize="${optimize}"
+      proceed="${proceed}"
+      verbose="${verbose}"
+      srcdir="${derby.engine.src.dir}"
+      destdir="${out.dir}">
+      <classpath>
+        <pathelement path="${compile.classpath}"/>
+      </classpath>
+      <include name="${derby.dir}/impl/io/memory/**"/>
+    </javac>
+  </target>
+  <target name="compile_impl_io">
+    <javac
+      bootclasspath="${empty}"
+      nowarn="on"
+      debug="${debug}"
+      depend="${depend}"
+      deprecation="${deprecation}"
+      optimize="${optimize}"
+      proceed="${proceed}"
+      verbose="${verbose}"
+      srcdir="${derby.engine.src.dir}"
+      destdir="${out.dir}">
+      <classpath>
+        <pathelement path="${compile.classpath}"/>
+      </classpath>
+      <include name="${derby.dir}/impl/io/memory/**"/>
+    </javac>
+  </target>
+  <target name="compile_impl_io_169">
+    <javac
+      bootclasspath="${empty}"
+      nowarn="on"
+      debug="${debug}"
+      depend="${depend}"
+      deprecation="${deprecation}"
+      optimize="${optimize}"
+      proceed="${proceed}"
+      verbose="${verbose}"
+      srcdir="${derby.engine.src.dir}"
+      destdir="${out.dir}">
+      <classpath>
+        <pathelement path="${compile.classpath}"/>
+      </classpath>
+      <include name="${derby.dir}/impl/io/memory/**"/>
+    </javac>
+  </target>
+</project>
+

Property changes on: java/engine/org/apache/derby/impl/io/memory/build.xml
___________________________________________________________________
Name: svn:eol-style
   + native

Index: java/engine/org/apache/derby/impl/io/MemoryRandomAccessFile.java
===================================================================
--- java/engine/org/apache/derby/impl/io/MemoryRandomAccessFile.java	(revision 0)
+++ java/engine/org/apache/derby/impl/io/MemoryRandomAccessFile.java	(revision 0)
@@ -0,0 +1,344 @@
+/*
+
+Derby - Class org.apache.derby.impl.io.MemoryRandomAccessFile
+
+Copyright 2004 The Apache Software Foundation or its licensors, as applicable.
+
+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.derby.impl.io;
+
+import org.apache.derby.iapi.services.sanity.SanityManager;
+
+import org.apache.derby.io.StorageFile;
+import org.apache.derby.io.StorageRandomAccessFile;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+//import java.io.File;
+//import java.io.RandomAccessFile;
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.io.FileNotFoundException;
+import java.io.RandomAccessFile;
+//import org.apache.derby.iapi.services.io.DynamicByteArrayIOStream;
+import org.apache.derby.impl.io.memory.MemoryInputStream;
+import org.apache.derby.impl.io.memory.MemoryOutputStream;
+import org.apache.derby.impl.io.memory.WritableFileDescriptor;
+
+/**
+ * This class provides a RAM based implementation of the StIRandomAccess File interface. It is used by the
+ * database engine to access persistent data and transaction logs under the memory (default) subsubprotocol.
+ */
+public class MemoryRandomAccessFile
+//extends RandomAccessFile 
+		implements StorageRandomAccessFile
+
+{
+	private String path;
+
+	private String mode;
+
+	private MemoryInputStream in;
+
+	private MemoryOutputStream out;
+
+	private DataInputStream dataIn;
+
+	private DataOutputStream dataOut;
+
+	public MemoryRandomAccessFile(String name, String mode,
+			WritableFileDescriptor f) {
+		path = name;
+		in = new MemoryInputStream(f);
+		out = new MemoryOutputStream(f);
+		dataIn = new DataInputStream(in);
+		dataOut = new DataOutputStream(out);
+
+	}
+
+	/**
+	 * Doesn't do anything in a pure in-memory implementation
+	 *
+	 * @param metaData If true then this method is required to force changes to both the file's
+	 *          content and metadata to be written to storage; otherwise, it need only force content changes
+	 *          to be written.
+	 *
+	 * @exception IOException If an IO error occurs.
+	 */
+	public void sync(boolean metaData) throws IOException {
+
+	}
+
+	public String toString() {
+
+		return path;
+	}
+
+	/**
+	 * Closes this file.
+	 */
+	public void close() throws IOException {
+
+	}
+
+	/**
+	 * Get the current offset in this file.
+	 */
+	public long getFilePointer() throws IOException {
+		return out.getFilePointer();
+	}
+
+	/**
+	 * Gets the length of this file.
+	 */
+	public long length() throws IOException {
+		return out.length();
+	}
+
+	/**
+	 * Set the file pointer. 
+	 */
+	public void seek(long newFilePointer) throws IOException {
+		out.seek(newFilePointer);
+	}
+
+	/**
+	 * Sets the length of this file, either extending or truncating it.
+	 */
+	public void setLength(long newLength) throws IOException {
+		out.setLength(newLength);
+	}
+
+	/*** Following functions Implement DataInput interfaces ****/
+
+	/**
+	 * Reads some bytes from an input  stream into the byte array.
+	 */
+	public void readFully(byte b[]) throws IOException {
+		//System.out.println("readFully=" + path + " len=" + b.length);
+		dataIn.readFully(b);
+	}
+
+	/**
+	 *
+	 * Reads the specified number of  bytes from an input stream.
+	 */
+	public void readFully(byte b[], int off, int len) throws IOException {
+		//System.out.println("readFully=" + path + " len=" + b.length + " off=" + off);
+		dataIn.readFully(b, off, len);
+	}
+
+	/**
+	 * skip over <code>nBytes</code> bytes of data 
+	 */
+	public int skipBytes(int nBytes) throws IOException {
+		return dataIn.skipBytes(nBytes);
+	}
+
+	/**
+	 * Reads a  byte and returns true if the byte is not zero
+	 * otherwise false. 
+	 */
+	public boolean readBoolean() throws IOException {
+		return dataIn.readBoolean();
+	}
+
+	/**
+	 * returns one input byte from the stream.
+	 */
+	public byte readByte() throws IOException {
+		return dataIn.readByte();
+	}
+
+	/**
+	 * Reads one input byte in the unsigned form. 
+	 */
+	public int readUnsignedByte() throws IOException {
+		return dataIn.readUnsignedByte();
+	}
+
+	/**
+	 * returns a short  value from the stream. 
+	 */
+	public short readShort() throws IOException {
+		return dataIn.readShort();
+	}
+
+	/**
+	 * returns unsigned short.
+	 */
+	public int readUnsignedShort() throws IOException {
+		return dataIn.readUnsignedShort();
+	}
+
+	/**
+	 * returns a char value from the stream.
+	 */
+	public char readChar() throws IOException {
+		return dataIn.readChar();
+	}
+
+	/**
+	 * returns an Int from the stream.
+	 */
+	public int readInt() throws IOException {
+		return dataIn.readInt();
+	}
+
+	/**
+	 * returns a long from the stream.
+	 */
+	public long readLong() throws IOException {
+		return dataIn.readLong();
+	}
+
+	/**
+	 * returns a float from the stream. 
+	 */
+	public float readFloat() throws IOException {
+		return dataIn.readFloat();
+	}
+
+	/**
+	 * returns a double from the stream.
+	 */
+	public double readDouble() throws IOException {
+		return dataIn.readDouble();
+	}
+
+	/**
+	 * returns the next line of text from the input stream.
+	 */
+	public String readLine() throws IOException {
+		return dataIn.readLine();
+	}
+
+	/**
+	 * returns a string that has been encoded using in the  UTF-8 format.
+	 */
+	public String readUTF() throws IOException {
+		return dataIn.readUTF();
+	}
+
+	/* Proxy Implementation of DataOutput interface */
+
+	/**
+	 * Writes an int to the output stream .
+	 */
+	public void write(int b) throws IOException {
+		dataOut.write(b);
+	}
+
+	/**
+	 * Writes all the bytes in array to the stream.
+	 */
+	public void write(byte b[]) throws IOException {
+		//System.out.print("write=" + path + " len=" + b.length);
+		dataOut.write(b);
+	}
+
+	/**
+	 * Writes specified number bytes from array to the stream.
+	 * If the corruption flags are enabled, byte array
+	 * is corrupted before doing the real write.
+	 */
+	public void write(byte b[], int off, int len) throws IOException {
+		//System.out.print("write=" + path + " len=" + b.length + " off=" + off);
+		dataOut.write(b, off, len);
+	}
+
+	/**
+	 * Writes a boolean value to this output stream.
+	 */
+	public void writeBoolean(boolean value) throws IOException {
+		dataOut.writeBoolean(value);
+	}
+
+	/**
+	 * Writes to  the eight low-order bits of ant int.
+	 *
+	 */
+	public void writeByte(int value) throws IOException {
+		dataOut.writeByte(value);
+	}
+
+	/**
+	 * Writes a short value to the output stream  
+	 */
+	public void writeShort(int value) throws IOException {
+		dataOut.writeShort(value);
+	}
+
+	/**
+	 * Writes a char value to the output stream.
+	 *
+	 * @param      value   the <code>char</code> value to be written.
+	 * @exception  IOException  if an I/O error occurs.
+	 */
+	public void writeChar(int value) throws IOException {
+		dataOut.writeChar(value);
+	}
+
+	/**
+	 * Writes an int value to the output stream.
+	 */
+	public void writeInt(int value) throws IOException {
+		dataOut.writeInt(value);
+	}
+
+	/**
+	 * Writes a long  value to the output stream.
+	 */
+	public void writeLong(long value) throws IOException {
+		dataOut.writeLong(value);
+	}
+
+	/**
+	 * Writes a float value to the output stream.
+	 */
+	public void writeFloat(float value) throws IOException {
+		dataOut.writeFloat(value);
+	}
+
+	/**
+	 * Writes a a double value to the stream.
+	 */
+	public void writeDouble(double value) throws IOException {
+		dataOut.writeDouble(value);
+	}
+
+	/**
+	 * Writes a string as bytes to the stream.
+	 */
+	public void writeBytes(String str) throws IOException {
+		dataOut.writeBytes(str);
+	}
+
+	/**
+	 * Writes  the string to the stream.
+	 */
+	public void writeChars(String str) throws IOException {
+		dataOut.writeChars(str);
+	}
+
+	/**
+	 * Writes the string in the utf format. 
+	 */
+	public void writeUTF(String str) throws IOException {
+		dataOut.writeUTF(str);
+	}
+
+}
\ No newline at end of file

Property changes on: java/engine/org/apache/derby/impl/io/MemoryRandomAccessFile.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: java/engine/org/apache/derby/impl/build.xml
===================================================================
--- java/engine/org/apache/derby/impl/build.xml	(revision 383439)
+++ java/engine/org/apache/derby/impl/build.xml	(working copy)
@@ -22,6 +22,7 @@
   <target name="compile" depends="compile_impl_169">
     <ant dir="${derby.engine.dir}/impl/services"/>
     <ant dir="${derby.engine.dir}/impl/io"/>
+    <ant dir="${derby.engine.dir}/impl/io/memory"/>
     <ant dir="${derby.engine.dir}/impl/sql"/>
     <ant dir="${derby.engine.dir}/impl/store"/>
     <ant dir="${derby.engine.dir}/impl/db"/>
@@ -35,5 +36,6 @@
   <target name="compile_impl_169">
     <ant dir="${derby.engine.dir}/impl/services" target="compile_impl_services_169"/>
     <ant dir="${derby.engine.dir}/impl/io" target="compile_impl_io_169"/>
+    <ant dir="${derby.engine.dir}/impl/io/memory" target="compile_impl_io_169"/>
   </target>
 </project>
Index: java/engine/org/apache/derby/io/VirtualFS.java
===================================================================
--- java/engine/org/apache/derby/io/VirtualFS.java	(revision 0)
+++ java/engine/org/apache/derby/io/VirtualFS.java	(revision 0)
@@ -0,0 +1,66 @@
+package org.apache.derby.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import org.apache.derby.impl.io.MemoryFile;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+//import org.apache.derby.iapi.services.io.DynamicByteArrayIOStreamFile;
+
+
+public interface VirtualFS
+{
+
+	
+	
+	public OutputStream getOutputStream(String path) throws FileNotFoundException;
+	
+	public OutputStream getOutputStream(String path, boolean append) throws FileNotFoundException;
+	
+	public InputStream getInputStream(String path) throws FileNotFoundException;
+
+	public  StorageRandomAccessFile getStorageRandomAccessFile(String path, String dummy) throws FileNotFoundException;
+	 
+	 
+	public  boolean renameTo(String path, String newPath);
+	 
+	public  boolean deleteAll(String path);
+	 
+	public boolean delete(String path);
+	 
+	public boolean exists(String path);
+	 
+
+	public String[] list(String path);
+	 
+
+	public boolean isDirectory(String path);
+	 
+
+	public boolean mkdir(StorageFile s, String str);
+	 
+	public boolean mkdirs(StorageFile s, String str);
+	 
+	public long length(String path);
+	public boolean createNewFile(String path);
+	
+	public boolean canWrite(String path);
+	//public boolean setReadOnly(String path);
+	 
+	//public void register(String path, StorageFile m);
+	 
+public void shutdown();
+//public StorageFile registerFile(MemoryFile m);
+//ublic StorageFile existsInTable(String path);
+	 
+//public boolean createNewFile(String path);
+
+	 
+	
+}

Property changes on: java/engine/org/apache/derby/io/VirtualFS.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: java/engine/org/apache/derby/io/VirtualFileData.java
===================================================================
--- java/engine/org/apache/derby/io/VirtualFileData.java	(revision 0)
+++ java/engine/org/apache/derby/io/VirtualFileData.java	(revision 0)
@@ -0,0 +1,30 @@
+package org.apache.derby.io;
+
+import java.io.IOException;
+
+public interface VirtualFileData
+{
+
+
+	public void write(int b, long position)  throws IOException;	
+	public void write(byte[] b, int off, int len, long position) throws IOException;
+
+	/**
+		Set the position of the stream pointer.
+		It is up to the caller to make sure the stream has no gap of garbage in
+		it or useful information is not left out at the end because the stream
+		does not remember anything about the previous position.
+	*/
+	public void seek(long newPosition);
+
+	public long length() ;
+		
+	public void setLength(long newLength) throws IOException ;
+
+	public void close();
+	
+	public int read(long position) throws IOException;
+	
+	public int read(byte b[], int off, int len, long position) throws IOException;
+	
+}
\ No newline at end of file

Property changes on: java/engine/org/apache/derby/io/VirtualFileData.java
___________________________________________________________________
Name: svn:eol-style
   + native

