From: Etienne Bergeron Date: Wed, 11 Dec 2013 15:18:24 +0000 (-0500) Subject: ctf: isolate the abstraction of memory map byte-buffer. X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=526c823cf42cbeb1b4c891880bac445be36f2135;p=deliverable%2Ftracecompass.git ctf: isolate the abstraction of memory map byte-buffer. 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 Reviewed-on: https://git.eclipse.org/r/19652 IP-Clean: Matthew Khouzam Tested-by: Hudson CI Reviewed-by: Matthew Khouzam --- diff --git a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java index f9d0c79a75..8a7c877233 100644 --- a/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java +++ b/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputTest.java @@ -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. */ diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java index 3ee9963ed4..dc982605d3 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java @@ -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); } diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java index f0a5d46bbf..1e01df9666 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java @@ -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) {