Package com.api.jsonata4java
Class JSONataUtils
java.lang.Object
com.api.jsonata4java.JSONataUtils
- All Implemented Interfaces:
Serializable
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final DecimalFormatstatic final byte[]static final Stringstatic final intstatic final intstatic RandomIf this class is initialized in a different JVM is started at the same millisecond, its s_r will generate the same sequence of random numbers.static SecureRandom -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic char[]byteToHexChars(byte bIn) Converts a byte into an array of char's containing the hexadecimal digits.static voidClose a buffered reader opened usingopenTextFile(String)static SequencecreateSequence(com.fasterxml.jackson.databind.JsonNode... arguments) static StringDecodes the passed UTF-8 String using an algorithm that's compatible with JavaScript'sdecodeURIComponentfunction.static StringEncodes the passed String as UTF-8 using an algorithm that's compatible with JavaScript'sencodeURIComponentfunction.static Stringstatic byte[]Transform the string of hexadecimal digits into a byte array.static StringhexEncode(byte[] bArray) Convert the byte array into a String of hexadecimal digits.static booleanisSequence(Object value) listSourceFiles(Path dir, String ext) Construct and return a sorted list of files in a directory identified by the dir that have extensions matching the extstatic com.fasterxml.jackson.databind.JsonNodeloadJSONFile(String jsonFQFileName) Load the specified JSON file from the fully qualified file name or throw the appropriate exception.static voidstatic BufferedReaderopenTextFile(String fqFilename) static StringPrint the supplied prompt (if not null) and return the trimmed responsestatic StringPrint the supplied prompt (if not null) and return the trimmed response according to the supplied trim controlstatic StringReads a buffered reader line up to a newline and returns the content read as a String that does not contain the linefeed.static StringreadLine(BufferedReader br, HashSet<Integer> terminators) Reads a buffered reader line up to any of the terminator characters (e.g., 0x0a for newline) and returns the content read as a String that does not contain the terminator.static com.fasterxml.jackson.databind.JsonNodesaveJSONFile(String jsonFileName, com.fasterxml.jackson.databind.JsonNode jsonData) Save the specified JSONObject in serialized form to the specified file or throw the appropriate exception.static String
-
Field Details
-
FMT
-
HEX_BYTES
public static final byte[] HEX_BYTES -
DAY_MS
public static final int DAY_MS- See Also:
-
HOUR_MS
public static final int HOUR_MS- See Also:
-
MIN_MS
public static final int MIN_MS- See Also:
-
HEX_CHARS
- See Also:
-
SEED_RANDOM
If this class is initialized in a different JVM is started at the same millisecond, its s_r will generate the same sequence of random numbers. -
SEED_SECURE_RANDOM
-
-
Constructor Details
-
JSONataUtils
public JSONataUtils()
-
-
Method Details
-
closeTextFile
Close a buffered reader opened usingopenTextFile(String)- Parameters:
br- buffered reader to be closed
-
byteToHexChars
public static char[] byteToHexChars(byte bIn) Converts a byte into an array of char's containing the hexadecimal digits. For example, 0x2f would return char[] {'2','F'}- Parameters:
bIn- byte to be converted to hexadecimal digits- Returns:
- array of chars containing the hexadecimal digits for the value of the input byte.
-
getUniqueID
- Returns:
- a 40 byte String random number based on invoking the com.ibm.crypto.fips.provider.SecureRandom class.
-
hexDecode
Transform the string of hexadecimal digits into a byte array.- Parameters:
strHex- a String containing pairs of hexadecimal digits- Returns:
- a byte array created by transforming pairs of hexadecimal digits into a byte. For example "7F41" would become byte [] { 0x7f, 0x41}
- Throws:
InvalidParameterException- thrown if the input string is null or empty, or if it does not contain an even number of hexadecimal digits, or if it contains something other than a hexadecimal digit.
-
hexEncode
Convert the byte array into a String of hexadecimal digits. For example, the bytes[] {0x31,0x0a} would become "310A".- Parameters:
bArray- the array of bytes to be converted.- Returns:
- a String of hexadecimal digits formed by the hexadecimal digit for each nibble of the byte.
-
openTextFile
- Parameters:
fqFilename- fully qualified name of the text file to be opened- Returns:
- open buffered reader to allow individual lines of a text file to be read
- Throws:
Exception- if the file can not be found- See Also:
-
prompt
Print the supplied prompt (if not null) and return the trimmed response- Parameters:
strPrompt- the prompt to be displayed- Returns:
- the trimmed response to the prompt (may be the empty String ("") if nothing entered)
-
prompt
Print the supplied prompt (if not null) and return the trimmed response according to the supplied trim control- Parameters:
strPrompt- the prompt to be displayedbTrim- whether or not to trim the input- Returns:
- the trimmed response (if so commanded) to the prompt (may be the empty String ("") if nothing entered)
-
saveJSONFile
public static com.fasterxml.jackson.databind.JsonNode saveJSONFile(String jsonFileName, com.fasterxml.jackson.databind.JsonNode jsonData) throws Exception Save the specified JSONObject in serialized form to the specified file or throw the appropriate exception.- Parameters:
jsonFileName- fully qualified name of the JSON file to be savedjsonData- the JSONObject to be saved to a file.- Returns:
- the jsonData that was saved
- Throws:
Exception-IOException) if there is a problem writing the file
-
listSourceFiles
Construct and return a sorted list of files in a directory identified by the dir that have extensions matching the ext- Parameters:
dir- the path to the directory containing files to be returned in the listext- the file extension (without the leading period) used to filter files in the dir- Returns:
- sorted list of files in a directory identified by the dir that have extensions matching the ext
- Throws:
IOException- if there is difficulty accessing the files in the supplied dir
-
loadJSONFile
public static com.fasterxml.jackson.databind.JsonNode loadJSONFile(String jsonFQFileName) throws Exception Load the specified JSON file from the fully qualified file name or throw the appropriate exception.- Parameters:
jsonFQFileName- name of the JSON file to be loaded- Returns:
- the JSONObject contained in the file, or an empty JSONObject if no object exists
- Throws:
Exception- If the file can no be located, or if there is a problem reading the file
-
readLine
Reads a buffered reader line up to a newline and returns the content read as a String that does not contain the linefeed.- Parameters:
br- buffered reader- Returns:
- String containing the characters read through the terminator character. If the end of file has been reached with nothing available to be returned, then null is returned.
- Throws:
IOException- if an error occurs while reading the buffered reader.- See Also:
-
readLine
Reads a buffered reader line up to any of the terminator characters (e.g., 0x0a for newline) and returns the content read as a String that does not contain the terminator.- Parameters:
br- buffered readerterminators- the set of line terminators used to signal return of the next "line" from the buffered reader.- Returns:
- String containing the characters read through the terminator character. If the end of file has been reached with nothing available to be returned, then null is returned.
- Throws:
IOException- if an error occurs while reading the buffered reader.
-
createSequence
-
isSequence
-
main
- Throws:
Exception
-
decodeURIComponent
Decodes the passed UTF-8 String using an algorithm that's compatible with JavaScript'sdecodeURIComponentfunction. Returnsnullif the String isnull.- Parameters:
s- The UTF-8 encoded String to be decoded- Returns:
- the decoded String
- Throws:
UnsupportedEncodingException
-
encodeURIComponent
Encodes the passed String as UTF-8 using an algorithm that's compatible with JavaScript'sencodeURIComponentfunction. Returnsnullif the String isnull.- Parameters:
s- The String to be encoded- Returns:
- the encoded String
- Throws:
URISyntaxException
-
substr
- Parameters:
str-start- Location at which to begin extracting characters. If a negative number is given, it is treated as strLength - start where strLength is the length of the string. For example, str.substr(-3) is treated as str.substr(str.length - 3)length- The number of characters to extract. If this argument is null, all the characters from start to the end of the string are extracted.- Returns:
- A new string containing the extracted section of the given string. If length is 0 or a negative number, an empty string is returned.
-