[Webfunds-commits] java/webfunds/store SepFileStore.java

Ian Grigg iang@cypherpunks.ai
Mon, 26 Mar 2001 21:46:33 -0400 (AST)


iang        01/03/26 21:46:33

  Modified:    webfunds/store SepFileStore.java
  Log:
  separated out the initialisation of debugs from the actual dir,
  so that non-debugging callers could use it.

Revision  Changes    Path
1.44      +31 -39    java/webfunds/store/SepFileStore.java

Index: SepFileStore.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/store/SepFileStore.java,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- SepFileStore.java	2000/10/02 14:13:19	1.43
+++ SepFileStore.java	2001/03/27 01:46:33	1.44
@@ -1,5 +1,5 @@
 /*
- * $Id: SepFileStore.java,v 1.43 2000/10/02 14:13:19 iang Exp $
+ * $Id: SepFileStore.java,v 1.44 2001/03/27 01:46:33 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -11,10 +11,7 @@
 import java.lang.reflect.InvocationTargetException;
 
 import webfunds.utils.Diagnostics;
-// import webfunds.store.AppendFileStore;
-// import webfunds.store.Store;
-// import webfunds.store.StoreException;
-// import webfunds.store.*;
+import webfunds.utils.Panic;
 import webfunds.sox.Encodable;
 import webfunds.sox.SOXPacketException;
 
@@ -31,7 +28,6 @@
     public static final int VERSION = 1;
     //protected int version = VERSION;
 
-//    protected   Core  c = null;
     protected   File dir;
     protected   boolean syncbool = false;
     protected   boolean error = false;
@@ -69,8 +65,8 @@
     public SepFileStore(File dir)
     {
         super();
-        this.dir = dir;
-        this.name = dir.getPath();
+
+        init(dir);
     }
     
     /**
@@ -79,24 +75,39 @@
     public SepFileStore(File dir, PrintWriter pw, String logfix)
     {
         super();
-        init(dir, pw, logfix);
+
+        init(dir);
+        initDiags(pw, logfix);
     }
     
+
+
+/////////  Initialisation  //////////////////////////////////
+
     /**
-     * Open an empty, new SepFileStore with diags
+     * Set up the directory
      */
-    public void init(File dir, PrintWriter pw, String logfix)
+    public void init(File dir)
     {
+        if (!dir.exists())
+            dir.mkdirs();
+        if (!dir.isDirectory() || !dir.canRead())
+            throw new Panic("Cannot read as directory: " + dir);
+
         this.dir = dir;
         this.name = dir.getPath();
+    }
+    
+    /**
+     * Set up the diags
+     */
+    public void initDiags(PrintWriter pw, String logfix)
+    {
         this.bug  = new PrintWriter(pw, true);
         this.fix  = logfix;
     }
     
 
-
-/////////  Initialisation  //////////////////////////////////
-
     // XXX: should use Store.getInstance(type, loc) or just (loc)
     public static Store getInstance(File dir)
     {
@@ -111,23 +122,14 @@
     public static SepFileStore getInstance(File dir,
                                PrintWriter pw, String logfix)
     {
-        checkDir(dir);
-
         SepFileStore store = new SepFileStore();
-        store.init(dir, pw, logfix);
+        store.init(dir);
+        store.initDiags(pw, logfix);
 
         store.initFiles();
         return store ;
     }
     
-    protected static void checkDir(File dir)
-    {
-        if (!dir.exists())
-            dir.mkdirs();
-        if (!dir.isDirectory() || !dir.canRead())
-            throw new RuntimeException("Cannot read as directory: " + dir);
-    }
-    
     protected void initFiles()
     {
         setSync(false);
@@ -268,13 +270,6 @@
 
 
 
-//    /** All Core components (CorePart) need the parent Core set.  */
-//    public void   setCore(Core core)      { if (c == null) { c = core; } }
-//    /** Another CorePart requirement.  */
-//    public String getType()               { return "Store"; }
-        
-
-
     /**
      * Call with true if sync-to-disk is required for all puts.
      */
@@ -321,14 +316,13 @@
     {
         SepFileStore st; //  = getInstance(d, bug, fix);
         st = new SepFileStore();
-//        st.setCore(c);
 logmsg(name + ": setting (OLD) class loader " + getClassLoader());
         st.setClassLoader(getClassLoader());
 
         // this needs cleaning up...
         File d = new File(dir, name);
-        checkDir(d);
-        st.init(d, bug, fix);
+        st.init(d);
+        st.initDiags(bug, fix);
         st.initFiles();
         stores.put(name, st);
         return st;
@@ -376,9 +370,7 @@
 
         // this needs cleaning up...
         File d = new File(dir, name);
-        checkDir(d);
         st.init(d, bug, fix);
-        //st.setCore(c);
         stores.put(name, st);
         return st;
     }
@@ -435,8 +427,8 @@
 
         // this needs cleaning up...
         File d = new File(dir, name);
-        checkDir(d);
-        st.init(d, bug, " (cl): ");
+        st.init(d);
+        st.initDiags(bug, " (cl): ");
 logmsg("init()ed");
         st.initFiles();
 logmsg("initFiles()d");