public class JSONataUtils extends Object implements Serializable
| Modifier and Type | Field and Description |
|---|---|
static int |
DAY_MS |
static DecimalFormat |
FMT |
static byte[] |
HEX_BYTES |
static String |
HEX_CHARS |
static int |
HOUR_MS |
static int |
MIN_MS |
static Random |
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.
|
static SecureRandom |
SEED_SECURE_RANDOM |
| Constructor and Description |
|---|
JSONataUtils() |
| Modifier and Type | Method and Description |
|---|---|
static char[] |
byteToHexChars(byte bIn)
Converts a byte into an array of char's containing the hexadecimal digits.
|
static void |
closeTextFile(BufferedReader br)
Close a buffered reader opened using
openTextFile(String) |
static Sequence |
createSequence(com.fasterxml.jackson.databind.JsonNode... arguments) |
static String |
decodeURIComponent(String s)
Decodes the passed UTF-8 String using an algorithm that's compatible with
JavaScript's
decodeURIComponent function. |
static String |
encodeURIComponent(String s)
Encodes the passed String as UTF-8 using an algorithm that's compatible
with JavaScript's
encodeURIComponent function. |
static String |
getUniqueID() |
static byte[] |
hexDecode(String strHex)
Transform the string of hexadecimal digits into a byte array.
|
static String |
hexEncode(byte[] bArray)
Convert the byte array into a String of hexadecimal digits.
|
static boolean |
isSequence(Object value) |
static List<Path> |
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 ext
|
static com.fasterxml.jackson.databind.JsonNode |
loadJSONFile(String jsonFQFileName)
Load the specified JSON file from the fully qualified file name or throw the
appropriate exception.
|
static void |
main(String[] args) |
static BufferedReader |
openTextFile(String fqFilename) |
static String |
prompt(String strPrompt)
Print the supplied prompt (if not null) and return the trimmed response
|
static String |
prompt(String strPrompt,
boolean bTrim)
Print the supplied prompt (if not null) and return the trimmed response
according to the supplied trim control
|
static String |
readLine(BufferedReader br)
Reads a buffered reader line up to a newline and returns the content read as
a String that does not contain the linefeed.
|
static String |
readLine(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.JsonNode |
saveJSONFile(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 |
substr(String str,
Integer start,
Integer length) |
public static final DecimalFormat FMT
public static final byte[] HEX_BYTES
public static final int DAY_MS
public static final int HOUR_MS
public static final int MIN_MS
public static final String HEX_CHARS
public static Random SEED_RANDOM
public static SecureRandom SEED_SECURE_RANDOM
public static void closeTextFile(BufferedReader br)
openTextFile(String)br - buffered reader to be closedpublic static char[] byteToHexChars(byte bIn)
bIn - byte to be converted to hexadecimal digitspublic static String getUniqueID()
public static byte[] hexDecode(String strHex) throws InvalidParameterException
strHex - a String containing pairs of hexadecimal digitsInvalidParameterException - 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.public static String hexEncode(byte[] bArray)
bArray - the array of bytes to be converted.public static BufferedReader openTextFile(String fqFilename) throws Exception
fqFilename - fully qualified name of the text file to be openedException - if the file can not be foundto close the reader returned by this
functionpublic static String prompt(String strPrompt)
strPrompt - the prompt to be displayedpublic static String prompt(String strPrompt, boolean bTrim)
strPrompt - the prompt to be displayedbTrim - whether or not to trim the inputpublic static com.fasterxml.jackson.databind.JsonNode saveJSONFile(String jsonFileName, com.fasterxml.jackson.databind.JsonNode jsonData) throws Exception
jsonFileName - fully qualified name of the JSON file to be savedjsonData - the JSONObject to be saved to a file.Exception - IOException) if there is a problem writing the filepublic static List<Path> listSourceFiles(Path dir, String ext) throws IOException
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 dirIOException - if there is difficulty accessing the files in the
supplied dirpublic static com.fasterxml.jackson.databind.JsonNode loadJSONFile(String jsonFQFileName) throws Exception
jsonFQFileName - name of the JSON file to be loadedException - If the file can no be located, or if there is a problem
reading the filepublic static String readLine(BufferedReader br) throws IOException
br - buffered readerIOException - if an error occurs while reading the buffered reader.readLine(BufferedReader, HashSet)public static String readLine(BufferedReader br, HashSet<Integer> terminators) throws IOException
br - buffered readerterminators - the set of line terminators used to signal return of the
next "line" from the buffered reader.IOException - if an error occurs while reading the buffered reader.public static Sequence createSequence(com.fasterxml.jackson.databind.JsonNode... arguments)
public static boolean isSequence(Object value)
public static String decodeURIComponent(String s) throws UnsupportedEncodingException
decodeURIComponent function. Returns
null if the String is null.s - The UTF-8 encoded String to be decodedUnsupportedEncodingExceptionpublic static String encodeURIComponent(String s) throws URISyntaxException
encodeURIComponent function. Returns
null if the String is null.s - The String to be encodedURISyntaxExceptionpublic static String substr(String str, Integer start, Integer length)
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.Copyright © 2022. All rights reserved.