Class JSONFlowUtils


  • public class JSONFlowUtils
    extends Object
    Utilities for building and saving flows from JSON data
    Author:
    Mark Hall
    • Constructor Detail

      • JSONFlowUtils

        public JSONFlowUtils()
    • Method Detail

      • writeFlow

        public static void writeFlow​(Flow flow,
                                     Writer writer)
                              throws WekaException
        Serializes the supplied flow to JSON and writes out using the supplied writer
        Parameters:
        flow - the Flow to serialize
        writer - the Writer to write to
        Throws:
        WekaException - if a problem occurs
      • writeFlow

        public static void writeFlow​(Flow flow,
                                     OutputStream os)
                              throws WekaException
        Serializes the supplied flow to JSON and writes out using the supplied output stream
        Parameters:
        flow - the Flow to serialize
        os - the OutputStream to write to
        Throws:
        WekaException - if a problem occurs
      • writeFlow

        public static void writeFlow​(Flow flow,
                                     File file)
                              throws WekaException
        Serializes the supplied flow to JSON and writes it out to the supplied file
        Parameters:
        flow - the Flow to serialize
        file - the File to write to
        Throws:
        WekaException - if a problem occurs
      • readFlow

        public static Flow readFlow​(File file)
                             throws WekaException
        Read a flow from the supplied file
        Parameters:
        file - the file to read from
        Returns:
        the deserialized Flow
        Throws:
        WekaException - if a problem occurs
      • readFlow

        public static Flow readFlow​(File file,
                                    boolean dontComplainAboutMissingConnections)
                             throws WekaException
        Read a flow from the supplied file
        Parameters:
        file - the file to read from
        dontComplainAboutMissingConnections - true if no exceptions should be raised if connections are missing in the flow
        Returns:
        the deserialized Flow
        Throws:
        WekaException - if a problem occurs
      • readFlow

        public static Flow readFlow​(InputStream is)
                             throws WekaException
        Read a Flow from the supplied input stream
        Parameters:
        is - the InputStream to read from
        Returns:
        the deserialized flow
        Throws:
        WekaException - if a problem occurs
      • readFlow

        public static Flow readFlow​(InputStream is,
                                    boolean dontComplainAboutMissingConnections)
                             throws WekaException
        Read a Flow from the supplied input stream
        Parameters:
        is - the InputStream to read from
        dontComplainAboutMissingConnections - true if no exception should be raised if there are missing connections
        Returns:
        the deserialized flow
        Throws:
        WekaException - if a problem occurs
      • readFlow

        public static Flow readFlow​(Reader sr)
                             throws WekaException
        Read a flow from the supplied reader
        Parameters:
        sr - the reader to read from
        Returns:
        the deserialized flow
        Throws:
        WekaException - if a problem occurs
      • readFlow

        public static Flow readFlow​(Reader sr,
                                    boolean dontComplainAboutMissingConnections)
                             throws WekaException
        Read a flow from the supplied reader
        Parameters:
        sr - the reader to read from
        dontComplainAboutMissingConnections - true if no exception should be raised if there are missing connections
        Returns:
        the deserialized flow
        Throws:
        WekaException - if a problem occurs
      • JSONToFlow

        public static Flow JSONToFlow​(String flowJSON,
                                      boolean dontComplainAboutMissingConnections)
                               throws WekaException
        Utility routine to deserialize a flow from the supplied JSON string
        Parameters:
        flowJSON - the string containing a flow in JSON form
        dontComplainAboutMissingConnections - to not raise any exceptions if there are missing connections in the flow
        Returns:
        the deserialized flow
        Throws:
        WekaException - if a problem occurs
      • flowToJSON

        public static String flowToJSON​(Flow flow)
                                 throws WekaException
        Utility routine to serialize a supplied flow to a JSON string
        Parameters:
        flow - the flow to serialize
        Returns:
        a string containing the flow in JSON form
        Throws:
        WekaException - if a problem occurs
      • main

        public static void main​(String[] args)
        Main method for testing this class
        Parameters:
        args - command line arguments