Klasse CLIUtil

java.lang.Object
de.dlr.proseo.ui.cli.CLIUtil

public class CLIUtil extends Object
Utility methods for command interpretation
Autor:
Dr. Thomas Bassler
  • Verschachtelte Klassen - Übersicht

    Verschachtelte Klassen
    Modifizierer und Typ
    Klasse
    Beschreibung
    static class 
    Helper class to return username and password from a method
  • Feldübersicht

    Felder
    Modifizierer und Typ
    Feld
    Beschreibung
    static final String
    JSON file format
    static final String
    XML file format
    static final String
    YAML file format
  • Konstruktorübersicht

    Konstruktoren
    Konstruktor
    Beschreibung
     
  • Methodenübersicht

    Modifizierer und Typ
    Methode
    Beschreibung
    static Instant
    Parse a date and time string in the format "yyyy-MM-dd'T'HH:mm:ss.SSSSSS[zZX]", whereby all of the following variants are allowed: yyyy-MM-dd yyyy-MM-ddTHH:mm yyyy-MM-ddTHH:mm:ss yyyy-MM-ddTHH:mm:ss.S[SSSSS] any of the above plus a time zone in general, RFC 822 or ISO 8601 format Missing parts are set to zero, a missing time zone is set to UTC.
    static <T> T
    parseObjectFile(File objectFile, String fileFormat, Class<T> clazz)
    Read the description for an object of the given type from a file in Json, XML or Yaml format
    static void
    printObject(PrintStream out, Object object, String fileFormat)
    Print the given object to the given output stream according to the requested file format; if the object is a list or set of size 1, then the single element of the collection is printed, not the list/set itself
    readIdentFile(String filePathString)
    Read the user credentials from a file consisting of one or two lines, the first line containing the username (without mission prefix) and the second line the password.
    static void
    setAttribute(Object restObject, String attributeParameter)
    Set an object attribute from an "attribute=value" parameter using reflection.

    Von Klasse geerbte Methoden java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Felddetails

  • Konstruktordetails

    • CLIUtil

      public CLIUtil()
  • Methodendetails

    • parseObjectFile

      public static <T> T parseObjectFile(File objectFile, String fileFormat, Class<T> clazz) throws IllegalArgumentException, IOException
      Read the description for an object of the given type from a file in Json, XML or Yaml format
      Typparameter:
      T - the type parameter
      Parameter:
      objectFile - the file to read
      fileFormat - the file format (one of { JSON, XML, YAML })
      clazz - the class object for type T
      Gibt zurück:
      a deserialized object of type T
      Löst aus:
      IllegalArgumentException - if the file format is not valid or the object file does not conform to the file format or the object file cannot be deserialized into an object of type T
      IOException - if an error occurs while reading the object file
    • printObject

      public static void printObject(PrintStream out, Object object, String fileFormat) throws IllegalArgumentException, IOException
      Print the given object to the given output stream according to the requested file format; if the object is a list or set of size 1, then the single element of the collection is printed, not the list/set itself
      Parameter:
      out - the output stream to print to
      object - the object to print
      fileFormat - the file format requested (one of JSON, XML, YAML)
      Löst aus:
      IllegalArgumentException - if the file format is not one of the above, or if a formatting error occurs during printing
      IOException - if an I/O error occurs during printing
    • setAttribute

      public static void setAttribute(Object restObject, String attributeParameter) throws IllegalArgumentException, ClassCastException
      Set an object attribute from an "attribute=value" parameter using reflection. Supported attribute types are String, Date, Long and List<String>.
      Parameter:
      restObject - the object to set the attribute in
      attributeParameter - a string of the form "attribute=value", where "value" may be a comma-separated string list
      Löst aus:
      IllegalArgumentException - if the given attribute name does not exist or is not accessible in the given object
      ClassCastException - if the attribute type is not supported (i. e. not listed above)
    • parseDateTime

      public static Instant parseDateTime(String dateTime) throws DateTimeException
      Parse a date and time string in the format "yyyy-MM-dd'T'HH:mm:ss.SSSSSS[zZX]", whereby all of the following variants are allowed:
      • yyyy-MM-dd
      • yyyy-MM-ddTHH:mm
      • yyyy-MM-ddTHH:mm:ss
      • yyyy-MM-ddTHH:mm:ss.S[SSSSS]
      • any of the above plus a time zone in general, RFC 822 or ISO 8601 format
      Missing parts are set to zero, a missing time zone is set to UTC.
      Parameter:
      dateTime - the date and time string to parse
      Gibt zurück:
      the parsed point in time
      Löst aus:
      DateTimeException - if the given string cannot be parsed according to the format given above
    • readIdentFile

      public static CLIUtil.Credentials readIdentFile(String filePathString) throws SecurityException, FileNotFoundException, IOException
      Read the user credentials from a file consisting of one or two lines, the first line containing the username (without mission prefix) and the second line the password. The file will only be read, if it is only readable by the current system user (as far as warranted by the operating system).
      Parameter:
      filePathString - path to the file containing the credentials
      Gibt zurück:
      a Credentials object with username and password set from the file
      Löst aus:
      SecurityException - if the file denoted by the file path does not meet the security criteria
      FileNotFoundException - if the file denoted by the file path does not exist
      IOException - if the file is not readable