[Mulgara-svn] r1276 - trunk/src/jar/util/java/org/mulgara/util

pag at mulgara.org pag at mulgara.org
Tue Sep 30 05:47:43 UTC 2008


Author: pag
Date: 2008-09-29 22:47:42 -0700 (Mon, 29 Sep 2008)
New Revision: 1276

Modified:
   trunk/src/jar/util/java/org/mulgara/util/IntFile.java
   trunk/src/jar/util/java/org/mulgara/util/MappedIntFile.java
Log:
Added LongMapper interface to IntFile, and created an in-memory implementation of the interface

Modified: trunk/src/jar/util/java/org/mulgara/util/IntFile.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/IntFile.java	2008-09-28 18:20:55 UTC (rev 1275)
+++ trunk/src/jar/util/java/org/mulgara/util/IntFile.java	2008-09-30 05:47:42 UTC (rev 1276)
@@ -57,7 +57,7 @@
  *
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
-public abstract class IntFile {
+public abstract class IntFile implements LongMapper {
 
   protected final static int SIZEOF_LONG = 8;
   protected final static int SIZEOF_INT = 4;
@@ -366,8 +366,25 @@
 
 
   /**
+   * Create a temporary IntFile, using a name based on a given pattern.
+   * @param namePattern The base for the name to use.
+   * @return A new IntFile object.
+   * @throws IOException Due to a file access error.
+   */
+  public static IntFile newTempIntFile(String namePattern) throws IOException {
+    File file = null;
+    try {
+      file = TempDir.createTempFile(namePattern, null);
+      return IntFile.open(file);
+    } catch (IOException e) {
+      if (file != null) file.delete();
+      throw e;
+    }
+  }
+
+
+  /**
    * Close and optionally truncate the file.
-   *
    * @throws IOException if an I/O error occurs.
    */
   private void close(boolean truncateFile) throws IOException {

Modified: trunk/src/jar/util/java/org/mulgara/util/MappedIntFile.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/MappedIntFile.java	2008-09-28 18:20:55 UTC (rev 1275)
+++ trunk/src/jar/util/java/org/mulgara/util/MappedIntFile.java	2008-09-30 05:47:42 UTC (rev 1276)
@@ -130,8 +130,14 @@
       mapFile(nrRegions);
     }
 
-    for (long key = prevSize; key < newSize; ++key) {
-      putLong(key, 0);
+    long key = prevSize;
+    try {
+      for (key = prevSize; key < newSize; ++key) {
+        putLong(key, 0);
+      }
+    } catch (NullPointerException e) {
+      logger.error("Out of range during resize. prevSize=" + prevSize + ", newSize=" + newSize + ", bad_offset=" + key);
+      throw new IOException("Out of range during resize. prevSize=" + prevSize + ", newSize=" + newSize + ", bad_offset=" + key);
     }
   }
 
@@ -208,7 +214,13 @@
         return;
       }
 
-      setSize(key + 1);
+      try {
+        setSize(key + 1);
+      } catch (IOException e) {
+        String m = "Exception mapping " + key + "=>" + l + ". ";
+        logger.fatal(m, e);
+        throw new IOException(m + e.getMessage());
+      }
     }
 
     int regionNr = (int) (key / REGION_SIZE);




More information about the Mulgara-svn mailing list