ctf: isolate the abstraction of memory map byte-buffer.
authorEtienne Bergeron <etienne.bergeron@gmail.com>
Wed, 11 Dec 2013 15:18:24 +0000 (10:18 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 11 Dec 2013 16:32:48 +0000 (11:32 -0500)
The concept of the memory map mechanism should not be exposed
outside the StreamInput. This is internal to StreamInput.
The API should exposed : give me a byte buffer (I don't care how).

Change-Id: I832d2776845a07173f4ef7cb47fd9c75c7db73bf
Signed-off-by: Etienne Bergeron <etienne.bergeron@gmail.com>
Reviewed-on: https://git.eclipse.org/r/19652
IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java

index f9d0c79a7578bf354ad53139324a71695d915601..8a7c8772335d56d4e91f9c58a44ab28bd1b928b5 100644 (file)
@@ -68,15 +68,6 @@ public class StreamInputTest {
         assertNotNull(fixture);
     }
 
-    /**
-     * Run the FileChannel getFileChannel() method test.
-     */
-    @Test
-    public void testGetFileChannel() {
-        FileChannel result = fixture.getFileChannel();
-        assertNull(result);
-    }
-
     /**
      * Run the String getFilename() method test.
      */
index 3ee9963ed4987193b7a89734b66a76b30ce58a2a..dc982605d350c40f3922c898e04a87b62af95dab 100644 (file)
@@ -14,7 +14,7 @@ package org.eclipse.linuxtools.ctf.core.trace;
 
 import java.io.File;
 import java.io.IOException;
-import java.nio.MappedByteBuffer;
+import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileChannel.MapMode;
 import java.util.UUID;
@@ -124,15 +124,6 @@ public class StreamInput implements IDefinitionScope {
         return index;
     }
 
-    /**
-     * Gets the filechannel of the streamInput. This is a limited Java resource.
-     *
-     * @return the filechannel
-     */
-    public FileChannel getFileChannel() {
-        return fileChannel;
-    }
-
     /**
      * Gets the filename of the streamInput file.
      *
@@ -299,6 +290,10 @@ public class StreamInput implements IDefinitionScope {
                 + ((packetIndex.getPacketSizeBits() + 7) / 8);
     }
 
+    ByteBuffer getByteBufferAt(long position, long size) throws IOException {
+        return fileChannel.map(MapMode.READ_ONLY, position, size);
+    }
+
     /**
      * @param fileSizeBytes
      * @param packetOffsetBytes
@@ -307,7 +302,7 @@ public class StreamInput implements IDefinitionScope {
      * @return
      * @throws CTFReaderException
      */
-    private MappedByteBuffer createPacketBitBuffer(long fileSizeBytes,
+    private ByteBuffer createPacketBitBuffer(long fileSizeBytes,
             long packetOffsetBytes, StreamInputPacketIndexEntry packetIndex,
             BitBuffer bitBuffer) throws CTFReaderException {
         /*
@@ -328,10 +323,10 @@ public class StreamInput implements IDefinitionScope {
         /*
          * Map the packet.
          */
-        MappedByteBuffer bb;
+        ByteBuffer bb;
 
         try {
-            bb = fileChannel.map(MapMode.READ_ONLY, packetOffsetBytes, mapSize);
+            bb = getByteBufferAt(packetOffsetBytes, mapSize);
         } catch (IOException e) {
             throw new CTFReaderException(e);
         }
index f0a5d46bbf21d8d5d7dbfd7eaa6fabe6f4f71702..1e01df9666bfdd624e88da8373c2a8d4139c6f7a 100644 (file)
@@ -12,8 +12,7 @@
 package org.eclipse.linuxtools.ctf.core.trace;
 
 import java.io.IOException;
-import java.nio.MappedByteBuffer;
-import java.nio.channels.FileChannel.MapMode;
+import java.nio.ByteBuffer;
 import java.util.Collection;
 
 import org.eclipse.linuxtools.ctf.core.CTFStrings;
@@ -216,10 +215,9 @@ public class StreamInputPacketReader implements IDefinitionScope {
             /*
              * Change the map of the BitBuffer.
              */
-            MappedByteBuffer bb = null;
+            ByteBuffer bb = null;
             try {
-                bb = streamInputReader.getStreamInput().getFileChannel()
-                        .map(MapMode.READ_ONLY,
+                bb = streamInputReader.getStreamInput().getByteBufferAt(
                                 this.currentPacket.getOffsetBytes(),
                                 (this.currentPacket.getPacketSizeBits() + 7) / 8);
             } catch (IOException e) {
This page took 0.029841 seconds and 5 git commands to generate.