poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1761636 - /poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java
Date Tue, 20 Sep 2016 20:24:54 GMT
Author: centic
Date: Tue Sep 20 20:24:54 2016
New Revision: 1761636

URL: http://svn.apache.org/viewvc?rev=1761636&view=rev
Log:
Adjust handling of ByteBuffer some more

Modified:
    poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java

Modified: poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java?rev=1761636&r1=1761635&r2=1761636&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java Tue Sep 20 20:24:54
2016
@@ -88,27 +88,26 @@ public class FileBackedDataSource extend
          throw new IndexOutOfBoundsException("Position " + position + " past the end of the
file");
       }
       
-      // Do we read or map (for read/write?
+      // Do we read or map (for read/write)?
       ByteBuffer dst;
-      int worked = -1;
       if (writable) {
           dst = channel.map(FileChannel.MapMode.READ_WRITE, position, length);
-          worked = 0;
-          // remember the buffer for cleanup if necessary
-          buffersToClean.add(dst);  
+
+          // remember this buffer for cleanup
+          buffersToClean.add(dst);
       } else {
-          // Read
+          // allocate the buffer on the heap if we cannot map the data in directly
           channel.position(position);
           dst = ByteBuffer.allocate(length);
-          worked = IOUtils.readFully(channel, dst);
-      }
 
-      // Check
-      if(worked == -1) {
-         throw new IndexOutOfBoundsException("Position " + position + " past the end of the
file");
+          // Read the contents and check that we could read some data
+          int worked = IOUtils.readFully(channel, dst);
+          if(worked == -1) {
+              throw new IndexOutOfBoundsException("Position " + position + " past the end
of the file");
+          }
       }
 
-      // Ready it for reading
+      // make it ready for reading
       dst.position(0);
 
       // All done



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message