* if an error occurs
*/
public void goToLastEvent() throws CTFException {
- /*
- * Search in the index for the packet to search in.
- */
- final int len = fStreamInput.getIndex().size();
/*
- * Go to beginning of trace.
+ * Go to the beginning of the trace
*/
seek(0);
+
/*
- * if the trace is empty.
+ * Check that there is at least one event
*/
if ((fStreamInput.getIndex().isEmpty()) || (!fPacketReader.hasMoreEvents())) {
/*
*/
return;
}
+
+ fPacketIndex = fStreamInput.getIndex().size() - 1;
+ /*
+ * Go to last indexed packet
+ */
+ fPacketReader.setCurrentPacket(getPacket());
+
+ /*
+ * Keep going until you cannot
+ */
+ while (fPacketReader.getCurrentPacket() != null) {
+ goToNextPacket();
+ }
+
+ final int lastPacketIndex = fStreamInput.getIndex().size() - 1;
/*
* Go to the last packet that contains events.
*/
- for (int pos = len - 1; pos > 0; pos--) {
+ for (int pos = lastPacketIndex; pos > 0; pos--) {
fPacketIndex = pos;
fPacketReader.setCurrentPacket(getPacket());
+
if (fPacketReader.hasMoreEvents()) {
break;
}
public CTFTrace getTrace() {
return fTrace;
}
+
+ /**
+ * This will read the entire trace and populate all the indexes. The reader
+ * will then be reset to the first event in the trace.
+ *
+ * Do not call in the fast path.
+ *
+ * @throws CTFException
+ * A trace reading error occurred
+ * @since 1.0
+ */
+ public void populateIndex() throws CTFException {
+ for (CTFStreamInputReader sir : fPrio) {
+ sir.goToLastEvent();
+ }
+ seek(0);
+
+ }
}