--- /dev/null
+public class DFile {
+ char [] data;
+ int size;
+ public DFile() {
+ data=global new char[4096];
+ size=data.length;
+ }
+ public void write(int offset, char[] towrite) {
+ int length=offset+towrite.length;
+ if (length>size) {
+ if (length>data.length) {
+ char [] ptr=global new char[length];
+ for(int i=0;i<size;i++) {
+ ptr[i]=data[i];
+ }
+ this.data=ptr;
+ }
+ size=length;
+ }
+ int j=0;
+ for(int i=offset;i<length;i++)
+ data[i]=towrite[j++];
+ }
+ public char[] read() {
+ char[] ptr=new char[size];
+ for(int i=0;i<size;i++)
+ ptr[i]=data[i];
+ return ptr;
+ }
+}
--- /dev/null
+public class Directory {
+ GlobalString name;
+ DistributedHashMap table;
+ DistributedLinkedList files;
+
+ public Directory(GlobalString name) {
+ this.name=name;
+ this.table=global new DistributedHashMap(500, 0.75f);
+ this.files=global new DistributedLinkedList();
+ }
+
+ public DFile getFile(GlobalString name) {
+ return (DFile) table.get(name);
+ }
+
+ public DFile createFile(GlobalString name) {
+ DFile file=global new DFile();
+ if (!table.containsKey(name)) {
+ files.add(name);
+ }
+ table.put(name, file);
+ return file;
+ }
+
+ public Directory getDirectory(GlobalString name) {
+ return (Directory) table.get(name);
+ }
+
+ public Directory makeDirectory(GlobalString name) {
+ if (!table.containsKey(name)) {
+ Directory d=global new Directory(name);
+ files.add(name);
+ table.put(name, d);
+ return d;
+ } else
+ return (Directory) table.get(name);
+ }
+
+ public void init() {
+ Random r=new Random();
+ for(int count=0; count<100; count++) {
+ GlobalString filename=global new GlobalString(String.valueOf(r.nextInt(200)));
+ createFile(filename);
+ }
+ }
+}