General improvements:
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / stubs / org / eclipse / linuxtools / tmf / trace / TmfTraceStub.java
1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.trace;
14
15 import java.io.FileNotFoundException;
16 import java.io.IOException;
17 import java.io.RandomAccessFile;
18
19 import org.eclipse.linuxtools.tmf.event.TmfEvent;
20
21 /**
22 * <b><u>TmfTraceStub</u></b>
23 * <p>
24 * Dummy test trace. Use in conjunction with TmfEventParserStub.
25 */
26 public class TmfTraceStub extends TmfTrace {
27
28 // ========================================================================
29 // Attributes
30 // ========================================================================
31
32 // The actual stream
33 private final RandomAccessFile fTrace;
34
35 // The associated event parser
36 private final ITmfEventParser fParser;
37
38 // ========================================================================
39 // Constructors
40 // ========================================================================
41
42 /**
43 * @param filename
44 * @throws FileNotFoundException
45 */
46 public TmfTraceStub(String filename) throws FileNotFoundException {
47 this(filename, DEFAULT_CACHE_SIZE, false);
48 }
49
50 /**
51 * @param filename
52 * @throws FileNotFoundException
53 */
54 public TmfTraceStub(String filename, boolean waitForCompletion) throws FileNotFoundException {
55 this(filename, DEFAULT_CACHE_SIZE, waitForCompletion);
56 }
57
58 /**
59 * @param filename
60 * @param cacheSize
61 * @throws FileNotFoundException
62 */
63 public TmfTraceStub(String filename, int cacheSize) throws FileNotFoundException {
64 this(filename, cacheSize, false);
65 }
66
67 /**
68 * @param filename
69 * @param cacheSize
70 * @throws FileNotFoundException
71 */
72 public TmfTraceStub(String filename, int cacheSize, boolean waitForCompletion) throws FileNotFoundException {
73 super(filename, cacheSize, waitForCompletion);
74 fTrace = new RandomAccessFile(filename, "r");
75 fParser = new TmfEventParserStub();
76 indexStream();
77 }
78
79 // ========================================================================
80 // Accessors
81 // ========================================================================
82
83 public RandomAccessFile getStream() {
84 return fTrace;
85 }
86
87 // ========================================================================
88 // Operators
89 // ========================================================================
90
91 /* (non-Javadoc)
92 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#seekLocation(java.lang.Object)
93 */
94 public TmfTraceContext seekLocation(Object location) {
95 TmfTraceContext context = null;
96 try {
97 synchronized(fTrace) {
98 fTrace.seek((location != null) ? (Long) location : 0);
99 context = new TmfTraceContext(getCurrentLocation(), null, 0);
100 }
101 } catch (IOException e) {
102 // TODO Auto-generated catch block
103 e.printStackTrace();
104 }
105 return context;
106 }
107
108 /* (non-Javadoc)
109 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation()
110 */
111 @Override
112 public Object getCurrentLocation() {
113 try {
114 return new Long(fTrace.getFilePointer());
115 } catch (IOException e) {
116 // TODO Auto-generated catch block
117 e.printStackTrace();
118 }
119 return null;
120 }
121
122 /* (non-Javadoc)
123 * @see org.eclipse.linuxtools.tmf.trace.TmfTrace#parseEvent()
124 */
125 @Override
126 public TmfEvent parseEvent(TmfTraceContext context) {
127 try {
128 // paserNextEvent updates the context
129 TmfEvent event = fParser.parseNextEvent(this, context);
130 if (event != null) {
131 context.setTimestamp(event.getTimestamp());
132 }
133 return event;
134 }
135 catch (IOException e) {
136 e.printStackTrace();
137 }
138 return null;
139 }
140
141 // ========================================================================
142 // Helper functions
143 // ========================================================================
144
145 }
This page took 0.032655 seconds and 5 git commands to generate.