ctf: Throw CTFReaderException in the BitBuffer API
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 28 Nov 2013 22:26:52 +0000 (17:26 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Fri, 29 Nov 2013 21:17:43 +0000 (16:17 -0500)
Instead of the hard-to-catch BufferOverflowException. This ensures
that users of the library handle cases where the trace reader fails
to read correctly (corrupted traces, twisted test traces, etc.)

Change-Id: If79e6f4fa9650c08e66f22c91a4cf4d250551e40
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/19091
Tested-by: Hudson CI
31 files changed:
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/io/BitBufferIntTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/CTFTraceReaderTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/trace/StreamInputReaderTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/FloatDefinitionTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDefinitionTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerEndiannessTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinitionTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StringDefinitionTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/io/BitBuffer.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDefinition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDefinition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDefinition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDefinition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDefinition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDefinition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.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
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfIteratorTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventFieldTest.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfEventTest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java

index ba6a805ddfe7e733e870059c7a830cc4ee3f6a46..e5fecf0313df6feb3456a06805bc56971f5e2279 100644 (file)
@@ -52,32 +52,38 @@ public class ReadTrace {
             if (USE_TEXT) {
                 System.out.println("Event, " + " Time, " + " type, " + " CPU ");
             }
-            if (trace != null) {
-                CTFTraceReader traceReader = new CTFTraceReader(trace);
+            try {
+                if (trace != null) {
+                    CTFTraceReader traceReader = new CTFTraceReader(trace);
 
-                start = System.nanoTime();
+                    start = System.nanoTime();
 
-                while (traceReader.hasMoreEvents()) {
-                    EventDefinition ed = traceReader.getCurrentEventDef();
-                    nbEvent++;
-                    if (USE_TEXT) {
-                        String output = formatDate(ed.getTimestamp()
-                                + trace.getOffset());
-                        System.out.println(nbEvent + ", "
-                                + output + ", " + ed.getDeclaration().getName()
-                                + ", " + ed.getCPU() + ed.getFields().toString()) ;
+                    while (traceReader.hasMoreEvents()) {
+                        EventDefinition ed = traceReader.getCurrentEventDef();
+                        nbEvent++;
+                        if (USE_TEXT) {
+                            String output = formatDate(ed.getTimestamp()
+                                    + trace.getOffset());
+                            System.out.println(nbEvent + ", "
+                                    + output + ", " + ed.getDeclaration().getName()
+                                    + ", " + ed.getCPU() + ed.getFields().toString());
+                        }
+                        // long endTime = traceReader.getEndTime();
+                        // long timestamp =
+                        // traceReader.getCurrentEventDef().getTimestamp();
+                        traceReader.advance();
                     }
-                    // long endTime = traceReader.getEndTime();
-                    // long timestamp = traceReader.getCurrentEventDef().getTimestamp();
-                    traceReader.advance();
+                    // Map<Long, Stream> streams =
+                    // traceReader.getTrace().getStreams();
                 }
-                // Map<Long, Stream> streams = traceReader.getTrace().getStreams();
-            }
-            stop = System.nanoTime();
+                stop = System.nanoTime();
 
-            System.out.print('.');
-            double time = (stop - start) / (double) nbEvent;
-            benchs.add(time);
+                System.out.print('.');
+                double time = (stop - start) / (double) nbEvent;
+                benchs.add(time);
+            } catch (CTFReaderException e) {
+                System.out.println("error");
+            }
         }
         System.out.println("");
         double avg = 0;
index 81811cb1ccc6912728f4a50260df21c3353f9667..3350db85807440c9c2fbaffcb166e382056157f8 100644 (file)
@@ -17,6 +17,7 @@ import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 
 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -35,7 +36,7 @@ public class BitBufferIntTest {
      */
     @Before
     public void setUp() {
-        fixture = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
+        fixture = new BitBuffer(ByteBuffer.allocateDirect(128));
         fixture.setByteOrder(ByteOrder.BIG_ENDIAN);
         createBuffer(fixture);
     }
@@ -55,18 +56,24 @@ public class BitBufferIntTest {
 
     /**
      * Run the int getInt() method test.
+     *
+     * @throws CTFReaderException
+     *             Not expected
      */
     @Test
-    public void testGetInt_base() {
+    public void testGetInt_base() throws CTFReaderException {
         int result = fixture.getInt();
         assertEquals(0x020406, result);
     }
 
     /**
      * Run the int getInt(int) method test.
+     *
+     * @throws CTFReaderException
+     *             Not expected
      */
     @Test
-    public void testGetInt_pos0() {
+    public void testGetInt_pos0() throws CTFReaderException {
         fixture.position(0);
         int result = fixture.getInt();
         assertEquals(0x010203, result);
@@ -74,9 +81,12 @@ public class BitBufferIntTest {
 
     /**
      * Run the int getInt(int,boolean) method test.
+     *
+     * @throws CTFReaderException
+     *             Not expected
      */
     @Test
-    public void testGetInt_pos1() {
+    public void testGetInt_pos1() throws CTFReaderException {
         fixture.position(1);
         int length = 1;
         boolean signed = true;
@@ -87,9 +97,12 @@ public class BitBufferIntTest {
 
     /**
      * Run the int getInt(int,boolean) method test.
+     *
+     * @throws CTFReaderException
+     *             Not expected
      */
     @Test
-    public void testGetInt_pos2() {
+    public void testGetInt_pos2() throws CTFReaderException {
         fixture.position(2);
         int length = 0;
         boolean signed = true;
@@ -100,9 +113,12 @@ public class BitBufferIntTest {
 
     /**
      * Run the int getInt(int,int,boolean) method test.
+     *
+     * @throws CTFReaderException
+     *             Not expected
      */
     @Test
-    public void testGetInt_signed() {
+    public void testGetInt_signed() throws CTFReaderException {
         fixture.position(1);
         int length = 0;
         boolean signed = true;
@@ -113,9 +129,12 @@ public class BitBufferIntTest {
 
     /**
      * Run the int getInt(int,int,boolean) method test.
+     *
+     * @throws CTFReaderException
+     *             Not expected
      */
     @Test
-    public void testGetInt_signed_length1() {
+    public void testGetInt_signed_length1() throws CTFReaderException {
         fixture.position(1);
         int length = 1;
         boolean signed = true;
@@ -127,11 +146,13 @@ public class BitBufferIntTest {
     /**
      * Run the int getInt(int,int,boolean) method test with a little-endian
      * BitBuffer.
+     *
+     * @throws CTFReaderException
+     *             Not expected
      */
     @Test
-    public void testGetInt_le1() {
-        BitBuffer le_fixture = new BitBuffer(
-                java.nio.ByteBuffer.allocateDirect(128));
+    public void testGetInt_le1() throws CTFReaderException {
+        BitBuffer le_fixture = new BitBuffer(ByteBuffer.allocateDirect(128));
         le_fixture.setByteOrder(ByteOrder.LITTLE_ENDIAN);
         createBuffer(le_fixture);
         le_fixture.position(1);
@@ -145,11 +166,13 @@ public class BitBufferIntTest {
     /**
      * Run the int getInt(int,int,boolean) method test with a little-endian
      * BitBuffer.
+     *
+     * @throws CTFReaderException
+     *             Not expected
      */
     @Test
-    public void testGetInt_le2() {
-        BitBuffer le_fixture = new BitBuffer(
-                java.nio.ByteBuffer.allocateDirect(128));
+    public void testGetInt_le2() throws CTFReaderException {
+        BitBuffer le_fixture = new BitBuffer(ByteBuffer.allocateDirect(128));
         le_fixture.setByteOrder(ByteOrder.LITTLE_ENDIAN);
         createBuffer(le_fixture);
         le_fixture.position(0);
@@ -160,11 +183,13 @@ public class BitBufferIntTest {
 
     /**
      * Run the int getInt(int,boolean) method test and expect an overflow.
+     *
+     * @throws CTFReaderException
+     *             Expected
      */
-    @Test(expected = java.nio.BufferOverflowException.class)
-    public void testGetInt_invalid() {
-        BitBuffer small_fixture = new BitBuffer(
-                java.nio.ByteBuffer.allocateDirect(128));
+    @Test(expected = CTFReaderException.class)
+    public void testGetInt_invalid() throws CTFReaderException {
+        BitBuffer small_fixture = new BitBuffer(ByteBuffer.allocateDirect(128));
         small_fixture.setByteOrder(ByteOrder.BIG_ENDIAN);
         createBuffer(small_fixture, 2);
         small_fixture.position(10);
@@ -177,11 +202,13 @@ public class BitBufferIntTest {
 
     /**
      * Run the int getInt(int,int,boolean) method test and expect an overflow.
+     *
+     * @throws CTFReaderException
+     *             Expected
      */
-    @Test(expected = java.nio.BufferOverflowException.class)
-    public void testGetInt_invalid2() {
-        BitBuffer small_fixture = new BitBuffer(
-                java.nio.ByteBuffer.allocateDirect(128));
+    @Test(expected = CTFReaderException.class)
+    public void testGetInt_invalid2() throws CTFReaderException {
+        BitBuffer small_fixture = new BitBuffer(ByteBuffer.allocateDirect(128));
         small_fixture.setByteOrder(ByteOrder.BIG_ENDIAN);
         createBuffer(small_fixture, 2);
         small_fixture.position(1);
@@ -194,9 +221,12 @@ public class BitBufferIntTest {
 
     /**
      * Run the void putInt(int) method test.
+     *
+     * @throws CTFReaderException
+     *             Not expected
      */
     @Test
-    public void testPutInt() {
+    public void testPutInt() throws CTFReaderException {
         int value = 1;
         fixture.position(1);
         fixture.putInt(value);
@@ -204,9 +234,12 @@ public class BitBufferIntTest {
 
     /**
      * Run the void putInt(int,int,boolean) method test.
+     *
+     * @throws CTFReaderException
+     *             Not expected
      */
     @Test
-    public void testPutInt_signed() {
+    public void testPutInt_signed() throws CTFReaderException {
         int length = 1;
         int value = 1;
 
@@ -216,9 +249,12 @@ public class BitBufferIntTest {
 
     /**
      * Run the void putInt(int,int,int,boolean) method test.
+     *
+     * @throws CTFReaderException
+     *             Not expected
      */
     @Test
-    public void testPutInt_length0() {
+    public void testPutInt_length0() throws CTFReaderException {
         int length = 0;
         int value = 1;
 
@@ -228,9 +264,12 @@ public class BitBufferIntTest {
 
     /**
      * Run the void putInt(int,int,int,boolean) method test.
+     *
+     * @throws CTFReaderException
+     *             Not expected
      */
     @Test
-    public void testPutInt_length1() {
+    public void testPutInt_length1() throws CTFReaderException {
         int length = 1;
         int value = 1;
 
@@ -240,9 +279,12 @@ public class BitBufferIntTest {
 
     /**
      * Run the void putInt(int) method test.
+     *
+     * @throws CTFReaderException
+     *             Not expected
      */
     @Test
-    public void testPutInt_hex() {
+    public void testPutInt_hex() throws CTFReaderException {
         final int value = 0x010203;
         int read;
 
@@ -259,11 +301,14 @@ public class BitBufferIntTest {
 
     /**
      * Run the void putInt(int,int,int,boolean) method test.
+     *
+     * @throws CTFReaderException
+     *             Expected
      */
-    @Test(expected = java.nio.BufferOverflowException.class)
-    public void testPutInt_invalid() {
+    @Test(expected = CTFReaderException.class)
+    public void testPutInt_invalid() throws CTFReaderException {
         BitBuffer fixture2;
-        fixture2 = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
+        fixture2 = new BitBuffer(ByteBuffer.allocateDirect(128));
         fixture2.setByteOrder(ByteOrder.BIG_ENDIAN);
         createBuffer(fixture2, 4);
         fixture2.position(1);
index 1bc176645d2ecbfdd1e44d101ef170cf03aa8433..34c31edc85f83e5b21bbc4679d7c1144a643daa5 100644 (file)
@@ -94,9 +94,10 @@ public class CTFTraceReaderTest {
 
     /**
      * Run the boolean advance() method test. Test advancing normally.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testAdvance_normal() {
+    public void testAdvance_normal() throws CTFReaderException {
         boolean result = fixture.advance();
         assertTrue(result);
     }
@@ -104,9 +105,10 @@ public class CTFTraceReaderTest {
     /**
      * Run the boolean advance() method test. Test advancing when we're at the
      * end, so we expect that there is no more events.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testAdvance_end() {
+    public void testAdvance_end() throws CTFReaderException {
         int i = 0;
         boolean result = fixture.advance();
         while (result) {
@@ -128,9 +130,10 @@ public class CTFTraceReaderTest {
 
     /**
      * Run the CTFTraceReader copy constructor test.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testCopyFrom() {
+    public void testCopyFrom() throws CTFReaderException {
         CTFTraceReader result = fixture.copyFrom();
         assertNotNull(result);
     }
@@ -172,9 +175,10 @@ public class CTFTraceReaderTest {
     /**
      * Run the getCurrentEventDef() method test. Get the last event's
      * definition.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testGetCurrentEventDef_last() {
+    public void testGetCurrentEventDef_last() throws CTFReaderException {
         fixture.goToLastEvent();
         EventDefinition result = fixture.getCurrentEventDef();
         assertNotNull(result);
@@ -200,9 +204,10 @@ public class CTFTraceReaderTest {
 
     /**
      * Run the void goToLastEvent() method test.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testGoToLastEvent() {
+    public void testGoToLastEvent() throws CTFReaderException {
         fixture.goToLastEvent();
         long ts1 = getTimestamp();
         long ts2 = fixture.getEndTime();
@@ -222,54 +227,60 @@ public class CTFTraceReaderTest {
 
     /**
      * Run the void printStats() method test with no 'width' parameter.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testPrintStats_noparam() {
+    public void testPrintStats_noparam() throws CTFReaderException {
         fixture.advance();
         fixture.printStats();
     }
 
     /**
      * Run the void printStats(int) method test with width = 0.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testPrintStats_width0() {
+    public void testPrintStats_width0() throws CTFReaderException {
         fixture.advance();
         fixture.printStats(0);
     }
 
     /**
      * Run the void printStats(int) method test with width = 1.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testPrintStats_width1() {
+    public void testPrintStats_width1() throws CTFReaderException {
         fixture.advance();
         fixture.printStats(1);
     }
 
     /**
      * Run the void printStats(int) method test with width = 2.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testPrintStats_width2() {
+    public void testPrintStats_width2() throws CTFReaderException {
         fixture.advance();
         fixture.printStats(2);
     }
 
     /**
      * Run the void printStats(int) method test with width = 10.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testPrintStats_width10() {
+    public void testPrintStats_width10() throws CTFReaderException {
         fixture.advance();
         fixture.printStats(10);
     }
 
     /**
      * Run the void printStats(int) method test with width = 100.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testPrintStats_100() {
+    public void testPrintStats_100() throws CTFReaderException {
         for (int i = 0; i < 1000; i++) {
             fixture.advance();
         }
@@ -278,9 +289,10 @@ public class CTFTraceReaderTest {
 
     /**
      * Run the boolean seek(long) method test.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testSeek() {
+    public void testSeek() throws CTFReaderException {
         long timestamp = 1L;
         boolean result = fixture.seek(timestamp);
         assertTrue(result);
index d269d013472002e8252845d9021a260ef9232197..99cf6a8855cd66121ba51f37e5f1a333a9e680c6 100644 (file)
@@ -140,9 +140,10 @@ public class StreamInputReaderTest {
 
     /**
      * Run the void goToLastEvent() method test.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testGoToLastEvent1() {
+    public void testGoToLastEvent1() throws CTFReaderException {
         final long endTimestamp = goToEnd();
         final long endTime = 4287422460315L;
         assertEquals(endTime , endTimestamp  );
@@ -150,9 +151,10 @@ public class StreamInputReaderTest {
 
     /**
      * Run the void goToLastEvent() method test.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testGoToLastEvent2() {
+    public void testGoToLastEvent2() throws CTFReaderException {
         long timestamp = -1;
         while(fixture.readNextEvent()) {
             timestamp = fixture.getCurrentEvent().getTimestamp();
@@ -161,25 +163,27 @@ public class StreamInputReaderTest {
         assertEquals(0 , timestamp- endTimestamp );
     }
 
-    private long goToEnd() {
+    private long goToEnd() throws CTFReaderException {
         fixture.goToLastEvent();
         return fixture.getCurrentEvent().getTimestamp();
     }
 
     /**
      * Run the boolean readNextEvent() method test.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testReadNextEvent() {
+    public void testReadNextEvent() throws CTFReaderException {
         boolean result = fixture.readNextEvent();
         assertTrue(result);
     }
 
     /**
      * Run the void seek(long) method test. Seek by direct timestamp
+     * @throws CTFReaderException error
      */
     @Test
-    public void testSeek_timestamp() {
+    public void testSeek_timestamp() throws CTFReaderException {
         long timestamp = 1L;
         fixture.seek(timestamp);
     }
index a5493cad33d1cae5801d2c930036e4ff000fc583..8044e72ff867306293a2a72b7c441ca691db8d06 100644 (file)
@@ -29,6 +29,7 @@ import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
 import org.junit.Before;
 import org.junit.Test;
@@ -232,9 +233,10 @@ public class ArrayDefinitionTest {
     }
     /**
      * Run the void read(BitBuffer) method test.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testRead_noDefs() {
+    public void testRead_noDefs() throws CTFReaderException {
         BitBuffer input = new BitBuffer(ByteBuffer.allocateDirect(128));
 
         charArrayFixture.read(input);
@@ -242,9 +244,10 @@ public class ArrayDefinitionTest {
 
     /**
      * Run the void read(BitBuffer) method test.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testRead_withDefs() {
+    public void testRead_withDefs() throws CTFReaderException {
         charArrayFixture.setDefinitions(new Definition[] {});
         BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
 
index 20511a582047876cb66acf81c538a29011c241c7..5b5aa26695da229d5d1fc9594cb987ef1622900e 100644 (file)
@@ -23,6 +23,7 @@ import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
 import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -95,9 +96,10 @@ public class EnumDefinitionTest {
 
     /**
      * Run the void read(BitBuffer) method test.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testRead() {
+    public void testRead() throws CTFReaderException {
         fixture.setIntegerValue(1L);
         BitBuffer input = new BitBuffer(ByteBuffer.allocateDirect(128));
 
index 47c374124c45f99409f1c952a905653bfe98c717..2635d3e629a64c954f5550334693630c10bb9dc2 100644 (file)
@@ -21,6 +21,7 @@ import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
 import org.eclipse.linuxtools.ctf.core.event.types.FloatDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.FloatDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -77,7 +78,7 @@ public class FloatDefinitionTest {
     }
 
     @Test
-    public void testFloat64Bit(){
+    public void testFloat64Bit() throws CTFReaderException{
         for(int i = 1; i < 63 ; i++) {
             parent = new FloatDeclaration(i, 64-i, ByteOrder.nativeOrder(), 0);
             fixture = parent.createDefinition(null, fieldName);
@@ -90,7 +91,7 @@ public class FloatDefinitionTest {
     }
 
     @Test
-    public void testFloat48Bit(){
+    public void testFloat48Bit() throws CTFReaderException{
         parent = new FloatDeclaration(12, 32, ByteOrder.nativeOrder(), 0);
         fixture = parent.createDefinition(null, fieldName);
         assertNotNull(fixture);
@@ -122,9 +123,10 @@ public class FloatDefinitionTest {
 
     /**
      * Run the void read(BitBuffer) method test.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testRead() {
+    public void testRead() throws CTFReaderException {
         singleFixture.setValue(2.0);
         BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
         singleFixture.read(input);
index 74db10edcf9ec3cd8855a465e072d1b3e37fe3fe..5ee378894cdc1b8f0330e7f9381f5908da193733 100644 (file)
@@ -21,6 +21,7 @@ import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
 import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -86,9 +87,10 @@ public class IntegerDefinitionTest {
 
     /**
      * Run the void read(BitBuffer) method test.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testRead() {
+    public void testRead() throws CTFReaderException {
         fixture.setValue(1L);
         BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
 
index 6f2175b029faaaff09c156380a2cdca61f77f57b..8801313148791554ddd8312ea69a0a60f5398baf 100644 (file)
@@ -9,6 +9,7 @@
  * Contributors:
  *   Geneviève Bastien - Initial API and implementation
  *   Alexandre Montplaisir - Split out in separate class
+ *   Matthew Khouzam - update api (exceptions)
  *******************************************************************************/
 
 package org.eclipse.linuxtools.ctf.core.tests.types;
@@ -22,6 +23,7 @@ import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
 import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -55,36 +57,56 @@ public class IntegerEndiannessTest {
         input = new BitBuffer(bb);
     }
 
-    /** Read 32-bits BE */
+    /**
+     * Read 32-bits BE
+     *
+     * @throws CTFReaderException
+     *             error
+     */
     @Test
-    public void test32BE() {
+    public void test32BE() throws CTFReaderException {
         IntegerDeclaration be = new IntegerDeclaration(32, true, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
         IntegerDefinition fixture_be = be.createDefinition(null, name);
         fixture_be.read(input);
         assertEquals(0xabcdef12, fixture_be.getValue());
     }
 
-    /** Read 64-bits BE */
+    /**
+     * Read 64-bits BE
+     *
+     * @throws CTFReaderException
+     *             error
+     */
     @Test
-    public void test64BE() {
+    public void test64BE() throws CTFReaderException {
         IntegerDeclaration be = new IntegerDeclaration(64, true, 1, ByteOrder.BIG_ENDIAN, Encoding.NONE, clockName, 8);
         IntegerDefinition fixture_be = be.createDefinition(null, name);
         fixture_be.read(input);
         assertEquals(0xabcdef123456789aL, fixture_be.getValue());
     }
 
-    /** Read 32-bits LE */
+    /**
+     * Read 32-bits LE
+     *
+     * @throws CTFReaderException
+     *             error
+     */
     @Test
-    public void test32LE() {
+    public void test32LE() throws CTFReaderException {
         IntegerDeclaration le = new IntegerDeclaration(32, true, 1, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, clockName, 8);
         IntegerDefinition fixture_le = le.createDefinition(null, name);
         fixture_le.read(input);
         assertEquals(0x12efcdab, fixture_le.getValue());
     }
 
-    /** Read 64-bits LE */
+    /**
+     * Read 64-bits LE
+     *
+     * @throws CTFReaderException
+     *             error
+     */
     @Test
-    public void test64LE() {
+    public void test64LE() throws CTFReaderException {
         IntegerDeclaration le = new IntegerDeclaration(64, true, 1, ByteOrder.LITTLE_ENDIAN, Encoding.NONE, clockName, 8);
         IntegerDefinition fixture_le = le.createDefinition(null, name);
         fixture_le.read(input);
index 8f875f5ca1a67fad1f959b2f2b44c4105b64c22e..073e5d4a6d80fa9c51c91ab433417ef49d25942a 100644 (file)
@@ -144,9 +144,10 @@ public class SequenceDefinitionTest {
 
     /**
      * Run the void read(BitBuffer) method test.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testRead() {
+    public void testRead() throws CTFReaderException {
         BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
         fixture.read(input);
     }
index a0fa11f280e2770c653ecfdcffb89d4c8272f57a..aa890612b89ebad29b0f960558637a7d706a5248 100644 (file)
@@ -17,6 +17,7 @@ import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
 import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StringDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -89,9 +90,10 @@ public class StringDefinitionTest {
 
     /**
      * Run the void read(BitBuffer) method test.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testRead() {
+    public void testRead() throws CTFReaderException {
         fixture.setString(new StringBuilder());
         BitBuffer input = new BitBuffer(java.nio.ByteBuffer.allocateDirect(128));
         fixture.read(input);
index b595d45b191d1cc1f79f16c64d0c6f36aacf7b3a..de01dc1acde4c1ef2bd3d28367cd1ed2f396b3ab 100644 (file)
@@ -35,6 +35,7 @@ import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -218,9 +219,10 @@ public class StructDefinitionTest {
 
     /**
      * Run the void read(BitBuffer) method test.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testRead_() {
+    public void testRead_() throws CTFReaderException {
         ByteBuffer bb = ByteBuffer.allocateDirect(128);
         bb.put((byte) 20);
         BitBuffer input = new BitBuffer(bb);
index d97eb5f3f52fb3a5eec6b3c3f6af199731ff2c2a..8be895442734d12281064975eb89acc8d1215163 100644 (file)
 
 package org.eclipse.linuxtools.ctf.core.event.io;
 
-import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
 /**
  * <b><u>BitBuffer</u></b>
  * <p>
@@ -95,8 +96,11 @@ public final class BitBuffer {
      * byte order.
      *
      * @return The int value read from the buffer
+     * @throws CTFReaderException
+     *             An error occurred reading the data. When the buffer is read
+     *             beyond its end, this exception will be raised.
      */
-    public int getInt() {
+    public int getInt() throws CTFReaderException {
         return getInt(BIT_INT, true);
     }
 
@@ -112,8 +116,11 @@ public final class BitBuffer {
      * @param signed
      *            The sign extended flag
      * @return The int value read from the buffer
+     * @throws CTFReaderException
+     *             An error occurred reading the data. When the buffer is read
+     *             beyond its end, this exception will be raised.
      */
-    public int getInt(int length, boolean signed) {
+    public int getInt(int length, boolean signed) throws CTFReaderException {
 
         /* Nothing to read. */
         if (length == 0) {
@@ -122,7 +129,9 @@ public final class BitBuffer {
 
         /* Validate that the buffer has enough bits. */
         if (!canRead(length)) {
-            throw new BufferOverflowException();
+            throw new CTFReaderException("Cannot read the integer, " + //$NON-NLS-1$
+                    "the buffer does not have enough remaining space. " + //$NON-NLS-1$
+                    "Requested:" + length); //$NON-NLS-1$
         }
 
         /* Get the value from the byte buffer. */
@@ -294,8 +303,11 @@ public final class BitBuffer {
      *
      * @param value
      *            The int value to write
+     * @throws CTFReaderException
+     *             An error occurred writing the data. If the buffer is written
+     *             beyond its end, this exception will be raised.
      */
-    public void putInt(int value) {
+    public void putInt(int value) throws CTFReaderException {
         putInt(BIT_INT, value);
     }
 
@@ -312,12 +324,16 @@ public final class BitBuffer {
      *            The number of bits to write
      * @param value
      *            The value to write
+     * @throws CTFReaderException
+     *             An error occurred writing the data. If the buffer is written
+     *             beyond its end, this exception will be raised.
      */
-    public void putInt(int length, int value) {
+    public void putInt(int length, int value) throws CTFReaderException {
         final long curPos = this.pos;
 
         if (!canRead(length)) {
-            throw new BufferOverflowException();
+            throw new CTFReaderException("Cannot write to bitbuffer, " //$NON-NLS-1$
+                    + "insufficient space. Requested: " + length); //$NON-NLS-1$
         }
         if (length == 0) {
             return;
index 96d16d87a99232b72b634ed941f8789918e6e87a..023361257ff5edacd6a7fb0021d3232aa49aa0a4 100644 (file)
@@ -15,6 +15,7 @@ package org.eclipse.linuxtools.ctf.core.event.types;
 import java.util.Arrays;
 
 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 
 /**
  * A CTF array definition
@@ -127,7 +128,7 @@ public class ArrayDefinition extends Definition {
     // ------------------------------------------------------------------------
 
     @Override
-    public void read(BitBuffer input) {
+    public void read(BitBuffer input) throws CTFReaderException {
         for (Definition definition : definitions) {
             definition.read(input);
         }
index dd8cb67ed2f435b63943ba56f4d99421925ce8ed..8ecbe436c2284df14bf506bf85c2bb3f4ad65c0d 100644 (file)
@@ -13,6 +13,7 @@
 package org.eclipse.linuxtools.ctf.core.event.types;
 
 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 
 /**
  * A CTF definition
@@ -123,9 +124,12 @@ public abstract class Definition {
      *
      * @param input
      *            the bitbuffer containing the data to read.
+     * @throws CTFReaderException
+     *             An error occurred reading the data. If the buffer is reading
+     *             beyond its end, this exception will be raised.
      * @since 2.0
      */
-    public abstract void read(BitBuffer input);
+    public abstract void read(BitBuffer input) throws CTFReaderException;
 
     /**
      * Offset the buffer position wrt the current alignment.
@@ -146,7 +150,6 @@ public abstract class Definition {
             return;
         }
         pos = (pos + mask) & ~mask;
-
         input.position(pos);
     }
 
index c022b013d599b1dd71142f99e611c876ad3a8f08..82d5230989c4a78c3cfaf7fb6c359f765d1364e2 100644 (file)
@@ -13,6 +13,7 @@
 package org.eclipse.linuxtools.ctf.core.event.types;
 
 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 
 /**
  * A CTF enum definition.
@@ -102,7 +103,7 @@ public class EnumDefinition extends SimpleDatatypeDefinition {
     // ------------------------------------------------------------------------
 
     @Override
-    public void read(BitBuffer input) {
+    public void read(BitBuffer input) throws CTFReaderException {
         alignRead(input, this.declaration);
         integerValue.read(input);
         long val = integerValue.getValue();
index 044a82d233e2996f7672476543ce386335d413d5..16b7509e481bf52d5c796f490595f6882f3a750b 100644 (file)
@@ -12,6 +12,7 @@
 package org.eclipse.linuxtools.ctf.core.event.types;
 
 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 
 /**
  * A CTF float definition.
@@ -85,7 +86,7 @@ public class FloatDefinition extends Definition {
     // ------------------------------------------------------------------------
 
     @Override
-    public void read(BitBuffer input) {
+    public void read(BitBuffer input) throws CTFReaderException {
         /* Offset the buffer position wrt the current alignment */
         alignRead(input, this.declaration);
         final int exp = declaration.getExponent();
@@ -101,7 +102,7 @@ public class FloatDefinition extends Definition {
     }
 
     private static double readRawFloat64(BitBuffer input, final int manBits,
-            final int expBits) {
+            final int expBits) throws CTFReaderException {
         long low = input.getInt(32, false);
         low = low & 0x00000000FFFFFFFFL;
         long high = input.getInt(32, false);
@@ -133,7 +134,7 @@ public class FloatDefinition extends Definition {
     }
 
     private static double readRawFloat32(BitBuffer input, final int manBits,
-            final int expBits) {
+            final int expBits) throws CTFReaderException {
         long temp = input.getInt(32, false);
         return createFloat(temp, manBits - 1, expBits);
     }
index 0b63230660cd5b6d68cd0cec693cdc478100adc3..1cb980c02baf04d16c8d9447aa68e04fc9c36593 100644 (file)
@@ -16,6 +16,7 @@ import java.math.BigInteger;
 import java.nio.ByteOrder;
 
 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 
 /**
  * A CTF integer definition.
@@ -99,7 +100,7 @@ public class IntegerDefinition extends SimpleDatatypeDefinition {
     }
 
     @Override
-    public void read(BitBuffer input) {
+    public void read(BitBuffer input) throws CTFReaderException {
         final long longNegBit = 0x0000000080000000L;
         /* Offset the buffer position wrt the current alignment */
         alignRead(input, this.declaration);
index c910adbea539496f9ada14d811bf7b2f3a95f6f3..43aeac8dafedfc3fb32ef1056b992f3946fdfcfe 100644 (file)
@@ -136,7 +136,7 @@ public class SequenceDefinition extends Definition {
     // ------------------------------------------------------------------------
 
     @Override
-    public void read(BitBuffer input) {
+    public void read(BitBuffer input) throws CTFReaderException {
         currentLength = (int) lengthDefinition.getValue();
 
         if ((definitions == null) || (definitions.length < currentLength)) {
index c7d1274f91bc1fdc7105275ae9ab3180e3181f02..5e79cef7bf0a5add0534f9b007710b81e7e2081c 100644 (file)
@@ -13,6 +13,7 @@
 package org.eclipse.linuxtools.ctf.core.event.types;
 
 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 
 /**
  * A CTF string definition (similar to a C null-terminated byte array).
@@ -110,7 +111,7 @@ public class StringDefinition extends Definition {
     // ------------------------------------------------------------------------
 
     @Override
-    public void read(BitBuffer input) {
+    public void read(BitBuffer input) throws CTFReaderException {
         /* Offset the buffer position wrt the current alignment */
         alignRead(input, this.declaration);
         string.setLength(0);
index 378b2e012b59c08a98f874c9a77c7d9c6fb1ddbe..bb7f1bc0103e9a48e04d575613408e95a2396b51 100644 (file)
@@ -18,6 +18,7 @@ import java.util.ListIterator;
 import java.util.Map;
 
 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 
 /**
  * A CTF structure definition (similar to a C structure).
@@ -90,7 +91,7 @@ public class StructDefinition extends Definition implements IDefinitionScope {
     // ------------------------------------------------------------------------
 
     @Override
-    public void read(BitBuffer input) {
+    public void read(BitBuffer input) throws CTFReaderException {
         alignRead(input, this.declaration);
         final List<String> fieldList = declaration.getFieldsList();
         for (String fName : fieldList) {
index 8d73ef1d2d541e146c832a29cc46615111a2773e..ca81529db8d3d7ff53a08b50e84d00666ad58655 100644 (file)
@@ -16,6 +16,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 
 /**
  * A CTF variant definition (similar to a C union).
@@ -147,7 +148,7 @@ public class VariantDefinition extends Definition implements IDefinitionScope {
     // ------------------------------------------------------------------------
 
     @Override
-    public void read(BitBuffer input) {
+    public void read(BitBuffer input) throws CTFReaderException {
         currentField = tagDefinition.getValue();
 
         Definition field = definitions.get(currentField);
index 392900187b5197b79d3fc51559b7a134ae0479ee..6110129400b3f1c5641d509df462414e6800ed78 100644 (file)
@@ -75,8 +75,10 @@ public class CTFTraceReader {
      *
      * @param trace
      *            The trace to read from.
+     * @throws CTFReaderException
+     *             if an error occurs
      */
-    public CTFTraceReader(CTFTrace trace) {
+    public CTFTraceReader(CTFTrace trace) throws CTFReaderException {
         this.trace = trace;
         streamInputReaders.clear();
 
@@ -105,8 +107,9 @@ public class CTFTraceReader {
      * Copy constructor
      *
      * @return The new CTFTraceReader
+     * @throws CTFReaderException if an error occurs
      */
-    public CTFTraceReader copyFrom() {
+    public CTFTraceReader copyFrom() throws CTFReaderException {
         CTFTraceReader newReader = null;
 
         newReader = new CTFTraceReader(this.trace);
@@ -117,6 +120,7 @@ public class CTFTraceReader {
 
     /**
      * Dispose the CTFTraceReader
+     *
      * @since 2.0
      */
     public void dispose() {
@@ -161,15 +165,17 @@ public class CTFTraceReader {
         return prio;
     }
 
-
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
 
     /**
      * Creates one trace file reader per trace file contained in the trace.
+     *
+     * @throws CTFReaderException
+     *             if an error occurs
      */
-    private void createStreamInputReaders() {
+    private void createStreamInputReaders() throws CTFReaderException {
         Collection<Stream> streams = this.trace.getStreams().values();
 
         /*
@@ -204,8 +210,11 @@ public class CTFTraceReader {
     /**
      * Initializes the priority queue used to choose the trace file with the
      * lower next event timestamp.
+     *
+     * @throws CTFReaderException
+     *             if an error occurs
      */
-    private void populateStreamInputReaderHeap() {
+    private void populateStreamInputReaderHeap() throws CTFReaderException {
         if (this.streamInputReaders.isEmpty()) {
             this.prio = new PriorityQueue<StreamInputReader>();
             return;
@@ -255,8 +264,10 @@ public class CTFTraceReader {
      * Go to the next event.
      *
      * @return True if an event was read.
+     * @throws CTFReaderException
+     *             if an error occurs
      */
-    public boolean advance() {
+    public boolean advance() throws CTFReaderException {
         /*
          * Remove the reader from the top of the priority queue.
          */
@@ -294,8 +305,11 @@ public class CTFTraceReader {
 
     /**
      * Go to the last event in the trace.
+     *
+     * @throws CTFReaderException
+     *             if an error occurs
      */
-    public void goToLastEvent() {
+    public void goToLastEvent() throws CTFReaderException {
         seek(this.getEndTime());
         while (this.prio.size() > 1) {
             this.advance();
@@ -313,8 +327,10 @@ public class CTFTraceReader {
      *            the timestamp to seek to
      * @return true if there are events above or equal the seek timestamp,
      *         false if seek at the end of the trace (no valid event).
+     * @throws CTFReaderException
+     *             if an error occurs
      */
-    public boolean seek(long timestamp) {
+    public boolean seek(long timestamp) throws CTFReaderException {
         /*
          * Remove all the trace readers from the priority queue
          */
index 43d13ded8809bd5e724a599dd2d9b2cf3bf2643a..e5bb1c41dc8b4073836e22b965c8991aff7322ea 100644 (file)
@@ -401,7 +401,7 @@ public class StreamInput implements IDefinitionScope {
 
     private void parsePacketContext(long fileSizeBytes,
             StructDefinition streamPacketContextDef, BitBuffer bitBuffer,
-            StreamInputPacketIndexEntry packetIndex) {
+            StreamInputPacketIndexEntry packetIndex) throws CTFReaderException {
         streamPacketContextDef.read(bitBuffer);
 
         for (String field : streamPacketContextDef.getDeclaration()
index cfeca1abe9382e3e59957024940583ced41cf5cb..58b833263d2b6db5ee306359051572d7d0e30849 100644 (file)
@@ -205,8 +205,10 @@ public class StreamInputPacketReader implements IDefinitionScope {
      *
      * @param currentPacket
      *            The index entry of the packet to switch to.
+     * @throws CTFReaderException
+     *             If we get an error reading the packet
      */
-    void setCurrentPacket(StreamInputPacketIndexEntry currentPacket) {
+    void setCurrentPacket(StreamInputPacketIndexEntry currentPacket) throws CTFReaderException {
         StreamInputPacketIndexEntry prevPacket = null;
         this.currentPacket = currentPacket;
 
index fdedf042f2c837076449afe6e858b95af29b1201..c943170adbac8147edecf2318ceb240140dce9ff 100644 (file)
@@ -61,7 +61,7 @@ public class StreamInputReader {
     private CTFTraceReader parent;
 
     /** Map of all the event types */
-    private final Map<Long, EventDefinition> eventDefs = new HashMap<Long,EventDefinition>();
+    private final Map<Long, EventDefinition> eventDefs = new HashMap<Long, EventDefinition>();
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -72,9 +72,11 @@ public class StreamInputReader {
      *
      * @param streamInput
      *            The StreamInput to read.
+     * @throws CTFReaderException
+     *             if an error occurs
      * @since 2.0
      */
-    public StreamInputReader(StreamInput streamInput) {
+    public StreamInputReader(StreamInput streamInput) throws CTFReaderException {
         this.streamInput = streamInput;
         this.packetReader = new StreamInputPacketReader(this);
         /*
@@ -89,6 +91,7 @@ public class StreamInputReader {
 
     /**
      * Dispose the StreamInputReader
+     *
      * @since 2.0
      */
     public void dispose() {
@@ -158,6 +161,7 @@ public class StreamInputReader {
 
     /**
      * Gets the filename of the stream being read
+     *
      * @return The filename of the stream being read
      */
     public String getFilename() {
@@ -202,8 +206,10 @@ public class StreamInputReader {
      * Reads the next event in the current event variable.
      *
      * @return If an event has been successfully read.
+     * @throws CTFReaderException
+     *             if an error occurs
      */
-    public boolean readNextEvent() {
+    public boolean readNextEvent() throws CTFReaderException {
 
         /*
          * Change packet if needed
@@ -238,8 +244,11 @@ public class StreamInputReader {
 
     /**
      * Change the current packet of the packet reader to the next one.
+     *
+     * @throws CTFReaderException
+     *             if an error occurs
      */
-    private void goToNextPacket() {
+    private void goToNextPacket() throws CTFReaderException {
         packetIndex++;
         if (getPacketSize() >= (packetIndex + 1)) {
             this.packetReader.setCurrentPacket(getPacket());
@@ -272,8 +281,10 @@ public class StreamInputReader {
      * @param timestamp
      *            The timestamp to seek to.
      * @return The offset compared to the current position
+     * @throws CTFReaderException
+     *             if an error occurs
      */
-    public long seek(long timestamp) {
+    public long seek(long timestamp) throws CTFReaderException {
         long offset = 0;
 
         gotoPacket(timestamp);
@@ -313,8 +324,10 @@ public class StreamInputReader {
 
     /**
      * @param timestamp
+     * @throws CTFReaderException
+     *             if an error occurs
      */
-    private void gotoPacket(long timestamp) {
+    private void gotoPacket(long timestamp) throws CTFReaderException {
         this.packetIndex = this.streamInput.getIndex().search(timestamp)
                 .previousIndex();
         /*
@@ -325,8 +338,11 @@ public class StreamInputReader {
 
     /**
      * Seeks the last event of a stream and returns it.
+     *
+     * @throws CTFReaderException
+     *             if an error occurs
      */
-    public void goToLastEvent() {
+    public void goToLastEvent() throws CTFReaderException {
         /*
          * Search in the index for the packet to search in.
          */
@@ -387,7 +403,9 @@ public class StreamInputReader {
 
     /**
      * Sets the current event in a stream input reader
-     * @param currentEvent the event to set
+     *
+     * @param currentEvent
+     *            the event to set
      */
     public void setCurrentEvent(EventDefinition currentEvent) {
         this.currentEvent = currentEvent;
index 50b6223a89348ee8e77f62c1eed7982887388343..c228d079f939c17ffa45b31de3e48da268015a29 100644 (file)
@@ -19,6 +19,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assume.assumeTrue;
 
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocation;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfLocationInfo;
@@ -45,9 +46,10 @@ public class CtfIteratorTest {
 
     /**
      * Perform pre-test initialization.
+     * @throws CTFReaderException error
      */
     @Before
-    public void setUp() {
+    public void setUp() throws CTFReaderException {
         assumeTrue(testTrace.exists());
         trace = testTrace.getTrace();
         iterator = new CtfIterator(trace);
@@ -68,18 +70,20 @@ public class CtfIteratorTest {
 
     /**
      * Run the CtfIterator(CtfTmfTrace) constructor on a non init'ed trace.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testCtfIterator_noinit() {
+    public void testCtfIterator_noinit() throws CTFReaderException {
         CtfIterator result = new CtfIterator(trace);
         assertNotNull(result);
     }
 
     /**
      * Run the CtfIterator(CtfTmfTrace) constructor on an init'ed trace.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testCtfIterator_init() {
+    public void testCtfIterator_init() throws CTFReaderException {
         trace.init("test");
         CtfIterator result = new CtfIterator(trace);
 
@@ -89,9 +93,10 @@ public class CtfIteratorTest {
     /**
      * Run the CtfIterator(CtfTmfTrace,long,long) constructor test, which
      * specifies an initial position for the iterator.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testCtfIterator_position() {
+    public void testCtfIterator_position() throws CTFReaderException {
         long timestampValue = 1L;
         long rank = 1L;
         CtfIterator result = new CtfIterator(trace, new CtfLocationInfo(timestampValue, 0), rank);
@@ -120,9 +125,10 @@ public class CtfIteratorTest {
 
     /**
      * Run the int compareTo(CtfIterator) method test.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testCompareTo() {
+    public void testCompareTo() throws CTFReaderException {
         CtfIterator o = new CtfIterator(trace);
         int result = iterator.compareTo(o);
 
@@ -132,9 +138,10 @@ public class CtfIteratorTest {
     /**
      * Run the boolean equals(Object) method test. Compare with another iterator
      * on the same trace.
+     * @throws CTFReaderException error
      */
     @Test
-    public void testEquals_other() {
+    public void testEquals_other() throws CTFReaderException {
         CtfIterator obj = new CtfIterator(trace);
         CtfLocation ctfLocation1 = new CtfLocation(new CtfLocationInfo(1, 0));
         obj.setLocation(ctfLocation1);
index d3cdf07b6c4c99b75b954cb59d15f32688589ae7..42414bcfb6b93915fa747a1314942d4af3e80c32 100644 (file)
@@ -31,6 +31,7 @@ import org.eclipse.linuxtools.ctf.core.event.types.StringDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventField;
 import org.junit.Before;
 import org.junit.Test;
@@ -60,9 +61,10 @@ public class CtfTmfEventFieldTest {
 
     /**
      * Perform pre-test initialization.
+     * @throws CTFReaderException error
      */
     @Before
-    public void setUp() {
+    public void setUp() throws CTFReaderException {
         StructDeclaration sDec = new StructDeclaration(1l);
         StringDeclaration strDec = new StringDeclaration();
         IntegerDeclaration intDec = new IntegerDeclaration(8, false, 8,
index a48e7d5dca4b1a6e7c8e92ef30781ee2addde506..6071b6473b4ed8032ac98dee6d669813f83e5572 100644 (file)
@@ -22,6 +22,7 @@ import static org.junit.Assume.assumeTrue;
 
 import java.util.Set;
 
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventFactory;
@@ -58,9 +59,10 @@ public class CtfTmfEventTest {
 
     /**
      * Perform pre-test initialization.
+     * @throws CTFReaderException error
      */
     @Before
-    public void setUp() {
+    public void setUp() throws CTFReaderException {
         assumeTrue(testTrace.exists());
         CtfTmfTrace trace = testTrace.getTrace();
         CtfIterator tr = new CtfIterator(trace);
index 753ff29b38c962f2abe8c45b4ca653d12d1a0e25..d7529bcab22f8d481ad14bdac1c7f75dc38c5754 100644 (file)
  *******************************************************************************/
 package org.eclipse.linuxtools.tmf.core.ctfadaptor;
 
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
 import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
+import org.eclipse.linuxtools.internal.tmf.core.Activator;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 
 /**
  * The CTF trace reader iterator.
  *
- * It doesn't reserve a file handle, so many iterators can be used without worries
- * of I/O errors or resource exhaustion.
+ * It doesn't reserve a file handle, so many iterators can be used without
+ * worries of I/O errors or resource exhaustion.
  *
  * @version 1.0
  * @author Matthew Khouzam
@@ -32,7 +34,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
     /**
      * An invalid location
      */
-    final public static CtfLocation NULL_LOCATION = new CtfLocation(CtfLocation.INVALID_LOCATION);
+    public static final CtfLocation NULL_LOCATION = new CtfLocation(CtfLocation.INVALID_LOCATION);
 
     private CtfLocation curLocation;
     private long curRank;
@@ -43,8 +45,10 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
      *
      * @param trace
      *            the trace to iterate over
+     * @throws CTFReaderException
+     *             error
      */
-    public CtfIterator(final CtfTmfTrace trace) {
+    public CtfIterator(final CtfTmfTrace trace) throws CTFReaderException {
         super(trace.getCTFTrace());
         this.ctfTmfTrace = trace;
         if (this.hasMoreEvents()) {
@@ -69,10 +73,12 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
      *            long the timestamp in ns of the trace for positioning
      * @param rank
      *            long the index of the trace for positioning
+     * @throws CTFReaderException
+     *             error
      * @since 2.0
      */
     public CtfIterator(final CtfTmfTrace trace,
-            final CtfLocationInfo ctfLocationData, final long rank) {
+            final CtfLocationInfo ctfLocationData, final long rank) throws CTFReaderException {
         super(trace.getCTFTrace());
 
         this.ctfTmfTrace = trace;
@@ -89,6 +95,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
 
     /**
      * Method getCtfTmfTrace. gets a CtfTmfTrace
+     *
      * @return CtfTmfTrace
      */
     public CtfTmfTrace getCtfTmfTrace() {
@@ -97,6 +104,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
 
     /**
      * Method getCurrentEvent. gets the current event
+     *
      * @return CtfTmfEvent
      */
     public CtfTmfEvent getCurrentEvent() {
@@ -118,7 +126,8 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
      *
      * @param ctfLocationData
      *            The LocationData representing the position to seek to
-     * @return boolean
+     * @return boolean True if the seek was successful, false if there was an
+     *         error seeking.
      * @since 2.0
      */
     public synchronized boolean seek(final CtfLocationInfo ctfLocationData) {
@@ -132,12 +141,16 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
         /* Adjust the timestamp depending on the trace's offset */
         long currTimestamp = ctfLocationData.getTimestamp();
         final long offsetTimestamp = this.getCtfTmfTrace().getCTFTrace().timestampNanoToCycles(currTimestamp);
-        if (offsetTimestamp < 0) {
-            ret = super.seek(0L);
-        } else {
-            ret = super.seek(offsetTimestamp);
+        try {
+            if (offsetTimestamp < 0) {
+                ret = super.seek(0L);
+            } else {
+                ret = super.seek(offsetTimestamp);
+            }
+        } catch (CTFReaderException e) {
+            Activator.logError(e.getMessage(), e);
+            return false;
         }
-
         /*
          * Check if there is already one or more events for that timestamp, and
          * assign the location index correctly
@@ -170,6 +183,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
 
     /**
      * Method getRank.
+     *
      * @return long
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getRank()
      */
@@ -180,7 +194,9 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
 
     /**
      * Method setRank.
-     * @param rank long
+     *
+     * @param rank
+     *            long
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#setRank(long)
      */
     @Override
@@ -191,12 +207,17 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
     @Override
     public CtfIterator clone() {
         CtfIterator clone = null;
-        clone = new CtfIterator(ctfTmfTrace, this.getLocation().getLocationInfo(), curRank);
+        try {
+            clone = new CtfIterator(ctfTmfTrace, this.getLocation().getLocationInfo(), curRank);
+        } catch (CTFReaderException e) {
+            Activator.logError(e.getMessage(), e);
+        }
         return clone;
     }
 
     /**
      * Method dispose.
+     *
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#dispose()
      */
     @Override
@@ -206,7 +227,9 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
 
     /**
      * Method setLocation.
-     * @param location ITmfLocation<?>
+     *
+     * @param location
+     *            ITmfLocation<?>
      * @since 3.0
      */
     @Override
@@ -218,6 +241,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
 
     /**
      * Method getLocation.
+     *
      * @return CtfLocation
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#getLocation()
      */
@@ -228,6 +252,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
 
     /**
      * Method increaseRank.
+     *
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#increaseRank()
      */
     @Override
@@ -240,6 +265,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
 
     /**
      * Method hasValidRank, if the iterator is valid
+     *
      * @return boolean
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfContext#hasValidRank()
      */
@@ -250,13 +276,19 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
 
     /**
      * Method advance go to the next event
+     *
      * @return boolean successful or not
      */
     @Override
     public synchronized boolean advance() {
         long index = curLocation.getLocationInfo().getIndex();
         long timestamp = curLocation.getLocationInfo().getTimestamp();
-        boolean ret = super.advance();
+        boolean ret = false;
+        try {
+            ret = super.advance();
+        } catch (CTFReaderException e) {
+            Activator.logError(e.getMessage(), e);
+        }
 
         if (ret) {
             final long timestampValue = getCurrentEvent().getTimestamp().getValue();
@@ -273,7 +305,9 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
 
     /**
      * Method compareTo.
-     * @param o CtfIterator
+     *
+     * @param o
+     *            CtfIterator
      * @return int -1, 0, 1
      */
     @Override
index f39a1a71324195c5f14a809f922a62f74f80440c..98f59ed5b17e35e1430378801289294409e35e28 100644 (file)
@@ -439,7 +439,12 @@ public class CtfTmfTrace extends TmfTrace
      * @since 2.0
      */
     public CtfIterator createIterator() {
-        return new CtfIterator(this);
+        try {
+            return new CtfIterator(this);
+        } catch (CTFReaderException e) {
+            Activator.logError(e.getMessage(), e);
+        }
+        return null;
     }
 
     // ------------------------------------------------------------------------
This page took 0.055581 seconds and 5 git commands to generate.