[Mulgara-svn] r1252 - trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11

pag at mulgara.org pag at mulgara.org
Mon Sep 8 08:37:52 UTC 2008


Author: pag
Date: 2008-09-08 01:37:51 -0700 (Mon, 08 Sep 2008)
New Revision: 1252

Modified:
   trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/DataStruct.java
Log:
Was not guarding seek/reads on data.

Modified: trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/DataStruct.java
===================================================================
--- trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/DataStruct.java	2008-09-06 11:51:50 UTC (rev 1251)
+++ trunk/src/jar/store-stringpool-xa11/java/org/mulgara/store/stringpool/xa11/DataStruct.java	2008-09-08 08:37:51 UTC (rev 1252)
@@ -245,14 +245,16 @@
     if (!prefixOnly) return;
     // move the limit out to the end
     data.limit(dataSize);
-    // read the file starting at the data, plus the header, plus the already read portion
-    file.seek(toOffset(gNode) + HEADER + MAX_DATA_SIZE);
-    // read into the buffer, filling at the point where the data had been truncated.
-    int remainingBytes = dataSize - MAX_DATA_SIZE;
-    assert remainingBytes > 0;
-    // we expect read to return everything from a file, so don't use readFully
-    int dataRead = file.read(data.array(), MAX_DATA_SIZE, remainingBytes);
-    if (dataRead != remainingBytes) throw new IOException("Unable to retrieve data from file.");
+    synchronized (file) {
+      // read the file starting at the data, plus the header, plus the already read portion
+      file.seek(toOffset(gNode) + HEADER + MAX_DATA_SIZE);
+      // read into the buffer, filling at the point where the data had been truncated.
+      int remainingBytes = dataSize - MAX_DATA_SIZE;
+      assert remainingBytes > 0;
+      // we expect read to return everything from a file, so don't use readFully
+      int dataRead = file.read(data.array(), MAX_DATA_SIZE, remainingBytes);
+      if (dataRead != remainingBytes) throw new IOException("Unable to retrieve data from file.");
+    }
   }
 
 
@@ -325,13 +327,15 @@
    * @param file The file to read the data from.
    */
   public static void getRemainingBytes(ByteBuffer data, RandomAccessFile file, long gNode) throws IOException {
-    // read the file starting at the data, plus the header, plus the already read portion
-    file.seek(toOffset(gNode) + HEADER + MAX_DATA_SIZE);
-    // read into the buffer, filling at the point where the data had been truncated.
-    int remainingBytes = data.limit() - data.position();
-    assert remainingBytes > 0;
-    int dataRead = file.read(data.array(), MAX_DATA_SIZE, remainingBytes);
-    if (dataRead != remainingBytes) throw new IOException("Unable to retrieve data from file.");
+    synchronized (file) {
+      // read the file starting at the data, plus the header, plus the already read portion
+      file.seek(toOffset(gNode) + HEADER + MAX_DATA_SIZE);
+      // read into the buffer, filling at the point where the data had been truncated.
+      int remainingBytes = data.limit() - data.position();
+      assert remainingBytes > 0;
+      int dataRead = file.read(data.array(), MAX_DATA_SIZE, remainingBytes);
+      if (dataRead != remainingBytes) throw new IOException("Unable to retrieve data from file.");
+    }
   }
 
 




More information about the Mulgara-svn mailing list