* <b><u>StreamInput</u></b>
* <p>
* Represents a trace file that belongs to a certain stream.
+ *
* @since 2.0
*/
public class StreamInput implements IDefinitionScope {
}
/**
- * Gets the filechannel of the streamInput. This is a limited Java
- * resource.
+ * Gets the filechannel of the streamInput. This is a limited Java resource.
*
* @return the filechannel
*/
StructDefinition streamPacketContextDef, BitBuffer bitBuffer)
throws CTFReaderException {
- /* Ignoring the return value, but this call is needed to initialize the input */
+ /*
+ * Ignoring the return value, but this call is needed to initialize the
+ * input
+ */
createPacketBitBuffer(fileSizeBytes, packetOffsetBytes, packetIndex, bitBuffer);
/*
if (packetIndex.getPacketSizeBits() > ((fileSizeBytes - packetIndex
.getOffsetBytes()) * 8)) {
- throw new CTFReaderException(
- "Not enough data remaining in the file for the size of this packet"); //$NON-NLS-1$
+ throw new CTFReaderException("Not enough data remaining in the file for the size of this packet"); //$NON-NLS-1$
}
/*
long streamID = streamIDDef.getValue();
if (streamID != getStream().getId()) {
- throw new CTFReaderException(
- "Stream ID changing within a StreamInput"); //$NON-NLS-1$
+ throw new CTFReaderException("Stream ID changing within a StreamInput"); //$NON-NLS-1$
}
}
}
String device = (String) packetIndex.lookupAttribute("device"); //$NON-NLS-1$
// LTTng Specific
Long cpuId = (Long) packetIndex.lookupAttribute("cpu_id"); //$NON-NLS-1$
- Long lostEvents = (Long) packetIndex.lookupAttribute("events_discarded"); //$NON-NLS-1$
+ Long lostEvents = (Long) packetIndex.lookupAttribute("events_discarded"); //$NON-NLS-1$
/* Read the content size in bits */
if (contentSize != null) {
packetIndex.setContentSizeBits(contentSize.intValue());
+ } else if (packetSize != null) {
+ packetIndex.setContentSizeBits(packetSize.longValue());
} else {
packetIndex.setContentSizeBits((int) (fileSizeBytes * 8));
}
+
/* Read the packet size in bits */
if (packetSize != null) {
packetIndex.setPacketSizeBits(packetSize.intValue());
this.currentPacket.getOffsetBytes(),
(this.currentPacket.getPacketSizeBits() + 7) / 8);
} catch (IOException e) {
- /*
- * The streamInputReader object is already allocated, so this
- * shouldn't fail bar some very bad kernel or RAM errors...
- */
- e.printStackTrace();
+ throw new CTFReaderException(e.getMessage(), e);
}
bitBuffer.setByteBuffer(bb);
final StructDefinition sehd = streamEventHeaderDef;
final BitBuffer currentBitBuffer = bitBuffer;
-
+ final long posStart = currentBitBuffer.position();
/* Read the stream event header. */
if (sehd != null) {
sehd.read(currentBitBuffer);
*/
eventDef.setTimestamp(timestamp);
+ if (posStart == currentBitBuffer.position()) {
+ throw new CTFReaderException("Empty event not allowed, event: " + eventDef.getDeclaration().getName()); //$NON-NLS-1$
+ }
+
return eventDef;
}
if (getPacketSize() >= (packetIndex + 1)) {
this.packetReader.setCurrentPacket(getPacket());
} else {
- try {
- if (this.streamInput.addPacketHeaderIndex()) {
- packetIndex = getPacketSize() - 1;
- this.packetReader.setCurrentPacket(getPacket());
- } else {
- this.packetReader.setCurrentPacket(null);
- }
-
- } catch (CTFReaderException e) {
+ if (this.streamInput.addPacketHeaderIndex()) {
+ packetIndex = getPacketSize() - 1;
+ this.packetReader.setCurrentPacket(getPacket());
+ } else {
this.packetReader.setCurrentPacket(null);
}
}
/*
* Advance until either of these conditions are met
* <ul>
- * <li> reached the end of the trace file (the given timestamp is after the last event), </li>
- * <li> found the first event with a timestamp greater or equal the given timestamp. </li>
+ * <li> reached the end of the trace file (the given timestamp is after the last event), </li>
+ * <li> found the first event with a timestamp greater or equal the given timestamp. </li>
* </ul>
*/
readNextEvent();