Interface Trace
- All Superinterfaces:
ImmutableTrace
A trace can have multiple types (e.g. file or chat). For these types, the trace can contain a set of properties and
associated values. A trace can be associated with a set of data sequences
.
During extraction, an extraction plugin
may receive a currently processed trace
and accompanying data sequence.
Implementers of a plugin should ensure that setting a property on a trace is valid as per the trace model which is defined for the traces generated by the plugin.
Note: implementations are not required to implement any kind of thread safety. It is up to the client to ensure this if necessary.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
a Tracelet represents tracedata that can be present multiple times within a trace.static interface
static class
a TraceletProperty is a property of a Tracelet. -
Method Summary
Modifier and TypeMethodDescriptiondefault Trace
addTracelet
(String type, Consumer<Trace.TraceletBuilder> callback) Add a tracelet to the trace.addTracelet
(Trace.Tracelet tracelet) Deprecated.Add a type to this trace (for example:"file"
).newChild
(String name, ThrowingConsumer<Trace, IOException> enrichChildCallback) Create and store new childtrace
of this trace.Set a property on this trace with a givenvalue
.default Trace
setData
(String dataType, InputStream stream) setData
(String dataType, List<DataTransformation> transformation) Set a series of data transformations for a specific dataType.setData
(String dataType, DataWriter writer) default Trace
setData
(String dataType, DataTransformation... transformations) Set a series of data transformations for a specific dataType.Methods inherited from interface org.hansken.plugin.extraction.api.ImmutableTrace
get, properties, traceId, types
-
Method Details
-
addType
Add a type to this trace (for example:"file"
). If this trace already had given type, nothing changes.- Parameters:
type
- the type to add- Returns:
this
-
set
Set a property on this trace with a givenvalue
.- Parameters:
name
- the name of the property to setvalue
- the value of the property- Returns:
this
- Throws:
IllegalArgumentException
- if the property or value of the property is invalid as per the trace model
-
addTracelet
Add a tracelet to the trace.Example usage:
trace.addTracelet("prediction", tracelet -> tracelet .set("type", "type") .set("model", "model") .set("label", "label") .set("confidence", .50));
); }- Parameters:
type
- the type of tracelet to addcallback
- callback to set the tracelet properties- Returns:
this
-
addTracelet
Deprecated.useaddTracelet(type, callback)
Add a tracelet to the trace.- Parameters:
tracelet
- the name and properties of the Tracelet- Returns:
this
-
setData
Add a data stream of a given type to thisTrace
(for example,'raw'
or'html'
). A trace can only have a single data stream for each data type. A callback function can be passed which receives anOutputStream
to write the data to.Note: the received output stream should not be closed by the user. It should also only be used within the scope of the callback, other usage may be guarded against or otherwise result in undefined behaviour.
Example usage:
final PacketSequencer sequencer = ...; final RandomAccessData input = dataContext.data(); trace.setData("packets", data -> { sequencer.process(input).forEach(packet -> { data.write(packet); }); });
- Parameters:
dataType
- the type of the data stream to addwriter
- callback that receives the stream to write to as input- Returns:
this
- Throws:
IllegalArgumentException
- if this trace already had an associated data stream of given typeIOException
- when the given callback throws one
-
setData
Set a series of data transformations for a specific dataType. Transformations are pointers to actual raw data. They describe how data can be obtained by reading on certain positions, using decryption, or combinations of these. The benefit of using Transformations is that they take up less space than the actual data.- Parameters:
dataType
- the type of the datastreamtransformations
- the data transformations- Returns:
this
-
setData
Set a series of data transformations for a specific dataType.- Parameters:
dataType
- the type of the datastreamtransformation
- the data transformations- Returns:
this
-
setData
Add a data stream of a given type to thisTrace
(for example,'raw'
or'html'
). A trace can only have a single data stream for each data type.The given
InputStream
will not be closed by this method.Example usage:
final ThumbnailDetector detector = ...; final RandomAccessData input = dataContext.data(); final InputStream thumbnails = detector.detect(input); trace.setData("preview", thumbnails);
- Parameters:
dataType
- the type of the data stream to addstream
- the data stream itself- Returns:
this
- Throws:
IllegalArgumentException
- if this trace already had an associated data stream of given typeIOException
- when an I/O error occurs while reading the input
-
newChild
Trace newChild(String name, ThrowingConsumer<Trace, IOException> enrichChildCallback) throws IOExceptionCreate and store new childtrace
of this trace. A callback function can be passed in order to enrich the created child trace (which will have no types or properties set yet), or even recursively add new children under it. After the trace goes out of scope of the callback, it can no longer be updated.As an example, say we have a
Node
type with the following API
A recursive function for creating traces from a node, where the initial node should be mapped to a single child under the trace being processed:interface Node { String name(); List<Node> children(); }
public void process(final Trace trace, final DataContext dataContext) { final Node node = createNode(); // get the node from somewhere createTree(node, trace); } void createTree(final Node childNode, final Trace parentTrace) { parentTrace.newChild(childNode.name(), child -> { // set information from child node on child trace child.type("file").set("file.name", "password.txt"); // recursively create more children childNode.children().forEach(node -> { createTree(node, child); }); }); }
- Parameters:
name
- the name of the childenrichChildCallback
- callback that gets the new child trace as input- Returns:
this
- Throws:
IllegalStateException
- if the trace was not yet savedIOException
- when the given callback throws one
-
addTracelet(type, callback)