Patch for Bug287563
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / stubs / org / eclipse / linuxtools / tmf / trace / TmfEventParserStub.java
index 259604aff472c1cd99fcee47fbd944fbc1ff1c22..bc49915795ab7ad5213cb89685c8ea07f5d972fd 100644 (file)
@@ -19,11 +19,13 @@ import java.util.Vector;
 
 import org.eclipse.linuxtools.tmf.event.TmfEvent;
 import org.eclipse.linuxtools.tmf.event.TmfEventContent;
+import org.eclipse.linuxtools.tmf.event.TmfEventFormat;
 import org.eclipse.linuxtools.tmf.event.TmfEventReference;
 import org.eclipse.linuxtools.tmf.event.TmfEventSource;
 import org.eclipse.linuxtools.tmf.event.TmfEventType;
 import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.parser.ITmfEventParser;
+import org.eclipse.linuxtools.tmf.stream.ITmfEventParser;
+import org.eclipse.linuxtools.tmf.stream.ITmfEventStream;
 
 /**
  * <b><u>TmfEventParserStub</u></b>
@@ -32,85 +34,71 @@ import org.eclipse.linuxtools.tmf.parser.ITmfEventParser;
  */
 public class TmfEventParserStub implements ITmfEventParser {
 
-    // ------------------------------------------------------------------------
+    // ========================================================================
     // Attributes
-    // ------------------------------------------------------------------------
+    // ========================================================================
 
-       private final int NB_TYPES = 10;
-    private final TmfEventType[] fTypes;
+       private final int NB_FORMATS = 10;
+    private final TmfEventFormat[] fFormats;
 
-    // ------------------------------------------------------------------------
+    // ========================================================================
     // Constructors
-    // ------------------------------------------------------------------------
+    // ========================================================================
 
     public TmfEventParserStub() {
-       fTypes = new TmfEventType[NB_TYPES];
-       for (int i = 0; i < NB_TYPES; i++) {
+       fFormats = new TmfEventFormat[NB_FORMATS];
+       for (int i = 0; i < NB_FORMATS; i++) {
                Vector<String> format = new Vector<String>();
                for (int j = 1; j <= i; j++) {
                        format.add(new String("Fmt-" + i + "-Fld-" + j));
                }
                String[] fields = new String[i];
-               fTypes[i] = new TmfEventType("Type-" + i, format.toArray(fields));
+               fFormats[i] = new TmfEventFormat(format.toArray(fields));
        }
     }
 
-    // ------------------------------------------------------------------------
+    // ========================================================================
     // Operators
-    // ------------------------------------------------------------------------
+    // ========================================================================
 
+    /* (non-Javadoc)
+     * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventParser#parseNextEvent()
+     */
     static final String typePrefix = "Type-";
-    @SuppressWarnings("unchecked")
-       public TmfEvent parseNextEvent(ITmfTrace eventStream, TmfContext context) throws IOException {
+    public TmfEvent getNextEvent(ITmfEventStream eventStream) throws IOException {
 
-        if (! (eventStream instanceof TmfTraceStub)) {
+        if (! (eventStream instanceof TmfEventStreamStub)) {
             return null;
         }
 
-               // Highly inefficient...
-               RandomAccessFile stream = ((TmfTraceStub) eventStream).getStream();
-               String name = eventStream.getName();
-               name = name.substring(name.lastIndexOf('/') + 1);
-
-        synchronized(stream) {
-               long location = 0;
-               if (context != null)
-                       location = ((TmfLocation<Long>) (context.getLocation())).getLocation();
-               stream.seek(location);
-
-               try {
-                       long ts        = stream.readLong();
-                       String source  = stream.readUTF();
-                       String type    = stream.readUTF();
-                       @SuppressWarnings("unused")
-                       int reference  = stream.readInt();
-                       int typeIndex  = Integer.parseInt(type.substring(typePrefix.length()));
-                       String[] fields = new String[typeIndex];
-                       for (int i = 0; i < typeIndex; i++) {
-                               fields[i] = stream.readUTF();
-                       }
-
-                       String content = "[";
-                       if (typeIndex > 0) {
-                               content += fields[0];
-                       }
-                       for (int i = 1; i < typeIndex; i++) {
-                               content += ", " + fields[i];
-                       }
-                       content += "]";
-
-                       TmfEvent event = new TmfEvent(
-                                       new TmfTimestamp(ts, (byte) -3, 0),     // millisecs
-                                       new TmfEventSource(source),
-                                       fTypes[typeIndex],
-                                       new TmfEventReference(name));
-                               TmfEventContent cnt = new TmfEventContent(event, content);
-                               event.setContent(cnt);
-                               return event;
-               } catch (EOFException e) {
-               }
+        RandomAccessFile stream = ((TmfEventStreamStub) eventStream).getStream();
+
+        try {
+            long ts        = stream.readLong();
+            String source  = stream.readUTF();
+            String type    = stream.readUTF();
+            int reference  = stream.readInt();
+            int typeIndex  = Integer.parseInt(type.substring(typePrefix.length()));
+            String[] fields = new String[typeIndex];
+            for (int i = 0; i < typeIndex; i++) {
+                fields[i] = stream.readUTF();
+            }
+            String content = "[";
+            for (int i = 0; i < typeIndex - 1; i++) {
+                content += fields[i] + ", ";
+            }
+            content += "]";
+            
+            TmfEvent event = new TmfEvent(
+                    new TmfTimestamp(ts, (byte) -3, 0),     // millisecs
+                    new TmfEventSource(source),
+                    new TmfEventType(type, fFormats[typeIndex]),
+                    new TmfEventContent(content, fFormats[typeIndex]),
+                    new TmfEventReference(reference));
+            return event;
+        } catch (EOFException e) {
         }
         return null;
     }
 
-}
\ No newline at end of file
+}
This page took 0.025888 seconds and 5 git commands to generate.