Fixed a few annotations and removed the JNI's prefs file to put it in lime with the...
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / stubs / org / eclipse / linuxtools / tmf / trace / TmfTraceStub.java
CommitLineData
d18dd09b 1/*******************************************************************************
e31e01e8 2 * Copyright (c) 2009, 2010 Ericsson
d18dd09b
ASL
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
13package org.eclipse.linuxtools.tmf.trace;
14
15import java.io.FileNotFoundException;
16import java.io.IOException;
17import java.io.RandomAccessFile;
18
19import org.eclipse.linuxtools.tmf.event.TmfEvent;
e31e01e8 20import org.eclipse.linuxtools.tmf.parser.ITmfEventParser;
d18dd09b
ASL
21
22/**
23 * <b><u>TmfTraceStub</u></b>
24 * <p>
8d2e2848 25 * Dummy test trace. Use in conjunction with TmfEventParserStub.
d18dd09b 26 */
e31e01e8 27public class TmfTraceStub extends TmfTrace<TmfEvent> {
d18dd09b 28
e31e01e8 29 // ------------------------------------------------------------------------
d18dd09b 30 // Attributes
e31e01e8 31 // ------------------------------------------------------------------------
d18dd09b
ASL
32
33 // The actual stream
146a887c 34 private final RandomAccessFile fTrace;
d18dd09b
ASL
35
36 // The associated event parser
146a887c 37 private final ITmfEventParser fParser;
d18dd09b 38
e31e01e8 39 // ------------------------------------------------------------------------
d18dd09b 40 // Constructors
e31e01e8 41 // ------------------------------------------------------------------------
d18dd09b
ASL
42
43 /**
44 * @param filename
45 * @throws FileNotFoundException
46 */
47 public TmfTraceStub(String filename) throws FileNotFoundException {
8d2e2848
FC
48 this(filename, DEFAULT_CACHE_SIZE, false);
49 }
50
51 /**
52 * @param filename
e31e01e8 53 * @param cacheSize
8d2e2848
FC
54 * @throws FileNotFoundException
55 */
e31e01e8
FC
56 public TmfTraceStub(String filename, int cacheSize) throws FileNotFoundException {
57 this(filename, cacheSize, false);
d18dd09b
ASL
58 }
59
60 /**
61 * @param filename
d18dd09b
ASL
62 * @throws FileNotFoundException
63 */
e31e01e8
FC
64 public TmfTraceStub(String filename, boolean waitForCompletion) throws FileNotFoundException {
65 this(filename, DEFAULT_CACHE_SIZE, waitForCompletion);
8d2e2848
FC
66 }
67
68 /**
69 * @param filename
70 * @param cacheSize
71 * @throws FileNotFoundException
72 */
73 public TmfTraceStub(String filename, int cacheSize, boolean waitForCompletion) throws FileNotFoundException {
e31e01e8 74 super(TmfEvent.class, filename, cacheSize);
d18dd09b
ASL
75 fTrace = new RandomAccessFile(filename, "r");
76 fParser = new TmfEventParserStub();
e31e01e8 77 indexTrace(waitForCompletion);
d18dd09b
ASL
78 }
79
e31e01e8 80 // ------------------------------------------------------------------------
d18dd09b 81 // Accessors
e31e01e8 82 // ------------------------------------------------------------------------
d18dd09b
ASL
83
84 public RandomAccessFile getStream() {
85 return fTrace;
86 }
87
e31e01e8 88 // ------------------------------------------------------------------------
d18dd09b 89 // Operators
e31e01e8 90 // ------------------------------------------------------------------------
d18dd09b 91
9f584e4c
FC
92 @SuppressWarnings("unchecked")
93 public TmfContext seekLocation(ITmfLocation location) {
d18dd09b 94 try {
4e3aa37d 95 synchronized(fTrace) {
9f584e4c
FC
96 // Position the trace at the requested location and
97 // returns the corresponding context
98 long loc = (location != null) ? ((TmfLocation<Long>) location).getValue() : 0;
99 if (loc != fTrace.getFilePointer()) {
100 fTrace.seek(loc);
101 }
102 TmfContext context = new TmfContext(getCurrentLocation(), 0);
e31e01e8 103 return context;
4e3aa37d 104 }
d18dd09b
ASL
105 } catch (IOException e) {
106 e.printStackTrace();
107 }
e31e01e8 108 return null;
d18dd09b
ASL
109 }
110
4e3aa37d 111 @Override
9f584e4c 112 public TmfLocation<Long> getCurrentLocation() {
d18dd09b 113 try {
9f584e4c 114 return new TmfLocation<Long>(fTrace.getFilePointer());
d18dd09b
ASL
115 } catch (IOException e) {
116 e.printStackTrace();
117 }
118 return null;
119 }
120
4e3aa37d 121 @Override
9f584e4c 122 public TmfEvent parseEvent(TmfContext context) {
cc6eec3e 123 try {
8d2e2848
FC
124 // paserNextEvent updates the context
125 TmfEvent event = fParser.parseNextEvent(this, context);
cc6eec3e
FC
126 return event;
127 }
128 catch (IOException e) {
129 e.printStackTrace();
130 }
131 return null;
d18dd09b
ASL
132 }
133
e31e01e8 134}
This page took 0.031388 seconds and 5 git commands to generate.