1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.trace
;
15 import java
.io
.EOFException
;
16 import java
.io
.IOException
;
17 import java
.io
.RandomAccessFile
;
18 import java
.util
.Vector
;
20 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
21 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventContent
;
22 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventFormat
;
23 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventReference
;
24 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventSource
;
25 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventType
;
26 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
27 import org
.eclipse
.linuxtools
.tmf
.stream
.ITmfEventParser
;
28 import org
.eclipse
.linuxtools
.tmf
.stream
.ITmfEventStream
;
31 * <b><u>TmfEventParserStub</u></b>
33 * TODO: Implement me. Please.
35 public class TmfEventParserStub
implements ITmfEventParser
{
37 // ========================================================================
39 // ========================================================================
41 private final int NB_FORMATS
= 10;
42 private final TmfEventFormat
[] fFormats
;
44 // ========================================================================
46 // ========================================================================
48 public TmfEventParserStub() {
49 fFormats
= new TmfEventFormat
[NB_FORMATS
];
50 for (int i
= 0; i
< NB_FORMATS
; i
++) {
51 Vector
<String
> format
= new Vector
<String
>();
52 for (int j
= 1; j
<= i
; j
++) {
53 format
.add(new String("Fmt-" + i
+ "-Fld-" + j
));
55 String
[] fields
= new String
[i
];
56 fFormats
[i
] = new TmfEventFormat(format
.toArray(fields
));
60 // ========================================================================
62 // ========================================================================
65 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventParser#parseNextEvent()
67 static final String typePrefix
= "Type-";
68 public TmfEvent
getNextEvent(ITmfEventStream eventStream
) throws IOException
{
70 if (! (eventStream
instanceof TmfEventStreamStub
)) {
74 RandomAccessFile stream
= ((TmfEventStreamStub
) eventStream
).getStream();
77 long ts
= stream
.readLong();
78 String source
= stream
.readUTF();
79 String type
= stream
.readUTF();
80 int reference
= stream
.readInt();
81 int typeIndex
= Integer
.parseInt(type
.substring(typePrefix
.length()));
82 String
[] fields
= new String
[typeIndex
];
83 for (int i
= 0; i
< typeIndex
; i
++) {
84 fields
[i
] = stream
.readUTF();
87 for (int i
= 0; i
< typeIndex
- 1; i
++) {
88 content
+= fields
[i
] + ", ";
92 TmfEvent event
= new TmfEvent(
93 new TmfTimestamp(ts
, (byte) -3, 0), // millisecs
94 new TmfEventSource(source
),
95 new TmfEventType(type
, fFormats
[typeIndex
]),
96 new TmfEventContent(content
, fFormats
[typeIndex
]),
97 new TmfEventReference(reference
));
99 } catch (EOFException e
) {