Class ThreatCSVWriter

java.lang.Object
java.io.Writer
be.kuleuven.cs.distrinet.sparta.io.ThreatWriter
be.kuleuven.cs.distrinet.sparta.io.ThreatCSVWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class ThreatCSVWriter extends ThreatWriter
A ThreatWriter to export one or more threats to a csv file. This writer does not automatically write a CSV header. If this is needed it can be manually written out using Writer.write(String) or writeHeader().
  • Constructor Details

    • ThreatCSVWriter

      public ThreatCSVWriter(Writer writer)
      Create a new ThreatCSVWriter to provided support for writing out a default set of threat properties to text-based files.
      Parameters:
      writer - a writer
    • ThreatCSVWriter

      public ThreatCSVWriter(Writer writer, Map<String,Function<Threat,? extends Object>> properties)
      Create a new ThreatCSVWriter to provided support for writing out a specified set of threat properties to text-based files. If any of the provided functions return a ModelElement, the ThreatWriter will attempt to retrieve the name of the element when writing it to the output writer.
      Parameters:
      writer - a writer
      properties - a set of functions, which applied to a threat provide the property to write out
  • Method Details

    • write

      public void write(Threat threat) throws IOException
      Write-out a threat
      Specified by:
      write in class ThreatWriter
      Parameters:
      threat - the Threat to write out
      Throws:
      IOException - If an I/O error occurs.
    • escapeField

      public static String escapeField(String arg)
      Escape a single CSV field: wrap it in double quotes and double any embedded double quote, per RFC 4180, so that values containing a quote or the ; delimiter do not break the CSV structure.
      Parameters:
      arg - the raw field value (may be null, treated as empty).
      Returns:
      the quoted and escaped field.
    • writeHeader

      public void writeHeader() throws IOException
      Write a csv header based on the provided set of property names in ThreatCSVWriter(Writer, Map)
      Throws:
      IOException - If an I/O error occurs