Class ThreatWriter
java.lang.Object
java.io.Writer
be.kuleuven.cs.distrinet.sparta.io.ThreatWriter
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
- Direct Known Subclasses:
ThreatCSVWriter,ThreatTextWriter
Writes
Threats to a character-output stream.
A newLine() method is provided, which uses the platform's own notion of line
separator as defined by the system property line.separator. Not all platforms
use the newline character ('\n') to terminate lines. Calling this method to
terminate each output line is therefore preferred to writing a newline
character directly.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionThreatWriter(Writer writer) Create a new ThreatWriter to provided support for writing out a default set of threat properties to text-based files.Create a new ThreatWriter to provided support for writing out a specified set of threat properties to text-based files. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the stream, flushing it first.voidflush()Flushes the stream.Retrieve the set of properties that are being exported by thisThreatWriter.voidnewLine()Writes a line separator.voidwrite(char[] cbuf, int off, int len) Writes a portion of an array of characters.abstract voidWrite-out a threatvoidWrite-out multiple threats
-
Field Details
-
writer
-
-
Constructor Details
-
ThreatWriter
Create a new ThreatWriter to provided support for writing out a default set of threat properties to text-based files.- Parameters:
writer- a writer
-
ThreatWriter
Create a new ThreatWriter to provided support for writing out a specified set of threat properties to text-based files. If any of the provided functions return aModelElement, theThreatWriterwill attempt to retrieve the name of the element when writing it to the output writer.- Parameters:
writer- a writerproperties- a set of functions, which applied to a threat provide the property to write out
-
-
Method Details
-
close
Closes the stream, flushing it first. Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-
flush
Flushes the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams. If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException
-
write
Writes a portion of an array of characters.- Specified by:
writein classWriter- Parameters:
cbuf- Array of charactersoff- Offset from which to start writing characterslen- Number of characters to write- Throws:
IndexOutOfBoundsException- Implementations should throw this exception if off is negative, or len is negative, or off + len is negative or greater than the length of the given arrayIOException- If an I/O error occurs
-
getProperties
Retrieve the set of properties that are being exported by thisThreatWriter.- Returns:
- a
Mapcontaining the property name and the function to apply on a threat to retrieve that property
-
write
Write-out a threat- Parameters:
threat- theThreatto write out- Throws:
IOException- If an I/O error occurs.
-
write
Write-out multiple threats- Parameters:
threats- theThreats to write out- Throws:
IOException- If an I/O error occurs.
-
newLine
Writes a line separator. The line separator string is defined by the system property line.separator, and is not necessarily a single newline ('\n') character.- Throws:
IOException- If an I/O error occurs.
-