Package de.dlr.proseo.ui.cli
Klasse CLIUtil
java.lang.Object
de.dlr.proseo.ui.cli.CLIUtil
Utility methods for command interpretation
- Autor:
- Dr. Thomas Bassler
-
Verschachtelte Klassen - Übersicht
Verschachtelte KlassenModifizierer und TypKlasseBeschreibungstatic class
Helper class to return username and password from a method -
Feldübersicht
Felder -
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungstatic Instant
parseDateTime
(String dateTime) 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 formatstatic 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 itselfstatic CLIUtil.Credentials
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.
-
Felddetails
-
FILE_FORMAT_YAML
YAML file format- Siehe auch:
-
FILE_FORMAT_JSON
JSON file format- Siehe auch:
-
FILE_FORMAT_XML
XML file format- Siehe auch:
-
-
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 readfileFormat
- 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 TIOException
- 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 toobject
- the object to printfileFormat
- 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 printingIOException
- 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 inattributeParameter
- 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 objectClassCastException
- if the attribute type is not supported (i. e. not listed above)
-
parseDateTime
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
- 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 criteriaFileNotFoundException
- if the file denoted by the file path does not existIOException
- if the file is not readable
-