[armedbear-cvs] r11975 - trunk/abcl/src/org/armedbear/lisp/util

Erik Huelsmann ehuelsmann at common-lisp.net
Mon Jun 1 09:40:36 UTC 2009


Author: ehuelsmann
Date: Mon Jun  1 05:40:14 2009
New Revision: 11975

Log:
Where the underlying stream is positioned should have
*no* bearing on what we do: we have bbufpos and
bbuf.position()/bbuf.limit() to determine where
and what to read.

Modified:
   trunk/abcl/src/org/armedbear/lisp/util/RandomAccessCharacterFile.java

Modified: trunk/abcl/src/org/armedbear/lisp/util/RandomAccessCharacterFile.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/util/RandomAccessCharacterFile.java	(original)
+++ trunk/abcl/src/org/armedbear/lisp/util/RandomAccessCharacterFile.java	Mon Jun  1 05:40:14 2009
@@ -248,7 +248,6 @@
     private RandomAccessInputStream inputStream;
     private RandomAccessOutputStream outputStream;
     private FileChannel fcn;
-    private long fcnpos; /* where fcn is pointing now. */
     private long fcnsize; /* the file size */
 	
     private Charset cset;
@@ -270,7 +269,6 @@
     public RandomAccessCharacterFile(RandomAccessFile raf, String encoding) throws IOException {
 
         fcn = raf.getChannel();
-        fcnpos = fcn.position();
         fcnsize = fcn.size();
 
         cset = (encoding == null) ? Charset.defaultCharset() : Charset.forName(encoding);
@@ -339,8 +337,6 @@
             }
 
             bufReady = (fcn.read(bbuf) != -1);
-            fcnpos = fcn.position();
-            // update bbufpos.
             bbuf.flip();
         }
 
@@ -354,7 +350,7 @@
         while ((cbuf.remaining() > 0) && dataIsAvailableForRead() && ! atEof) {
 
             atEof = ! ensureReadBbuf(decodeWasUnderflow);
-            CoderResult r = cdec.decode(bbuf, cbuf, atEof);
+            CoderResult r = cdec.decode(bbuf, cbuf, atEof );
             decodeWasUnderflow = (CoderResult.UNDERFLOW == r);
         }
         if (cbuf.remaining() == len) {
@@ -365,7 +361,7 @@
     }
 
     private boolean dataIsAvailableForRead() throws IOException {
-        return ((bbuf.remaining() > 0) || (fcn.position() < fcn.size()));
+        return ((bbuf.remaining() > 0) || (bbufpos + bbuf.position() < fcn.size()));
     }
 
     private void write(char[] cb, int off, int len) throws IOException {
@@ -395,10 +391,9 @@
                 flushBbuf();
                 bbufpos += bbuf.limit();
                 bbuf.clear();
-                if (fcnpos < fcnsize) {
+                if (bbufpos < fcnsize) {
                     fcn.read(bbuf);
                     bbuf.flip();
-                    fcnpos += bbuf.remaining();
                 }
             // if we are at the end of file, bbuf is simply cleared.
             // in that case, bbufpos + bbuf.position points to the EOF, not fcnpos.
@@ -419,10 +414,9 @@
             // far seek. discard the buffer.
             flushBbuf();
             fcn.position(newPosition);
-            fcnpos = newPosition;
             bbuf.clear();
             bbuf.flip(); // "there is no useful data on this buffer yet."
-            bbufpos = fcnpos;
+            bbufpos = newPosition;
         }
     }
 	
@@ -440,8 +434,7 @@
         if (! bbufIsDirty)
             return;
 
-        if (fcnpos != bbufpos)
-            fcn.position(bbufpos);
+        fcn.position(bbufpos);
 
         bbuf.position(0);
         if (bbufpos + bbuf.limit() > fcnsize) {
@@ -450,7 +443,6 @@
             bbuf.limit((int)(fcnsize - bbufpos));
         }
         fcn.write(bbuf);
-        fcnpos = bbufpos + bbuf.limit();
         bbufIsDirty = false;
     }
 
@@ -517,9 +509,7 @@
             if (bbufIsDirty)
                 flushBbuf();
             fcn.write(ByteBuffer.wrap(b, off, len));
-            fcnpos = fcn.position();
-            if (fcnpos > fcnsize)
-                fcnsize = fcnpos;
+            fcnsize = fcn.size();
         }
         while (pos < off + len) {
             int want = len;
@@ -538,11 +528,10 @@
                 flushBbuf();
                 bbufpos += bbuf.limit();
                 bbuf.clear();
-                if (fcn.position() < fcnsize) {
-                    bbufpos = fcn.position();
+                if (bbufpos < fcnsize) {
+                    fcn.position(bbufpos);
                     fcn.read(bbuf);
                     bbuf.flip();
-                    fcnpos += bbuf.remaining();
                 }
                 // if we are at the end of file, bbuf is simply cleared.
                 // in that case, bbufpos + bbuf.position points to the EOF, not fcnpos.




More information about the armedbear-cvs mailing list