Package eu.europa.esig.dss.utils
Class Utils
java.lang.Object
eu.europa.esig.dss.utils.Utils
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
areAllStringsEmpty
(String... values) Checks if all strings are emptystatic boolean
areStringsEqual
(String text1, String text2) Checks if the strings are equal Ex.static boolean
areStringsEqualIgnoreCase
(String text1, String text2) Checks if the strings are equal with case ignore Ex.static int
arraySize
(byte[] array) Gets size of the byte array.static int
arraySize
(char[] array) Gets size of the char array.static int
Gets size of the array.static void
cleanDirectory
(File directory) Cleans the directorystatic void
closeQuietly
(Closeable closeable) Closes quietlystatic int
collectionSize
(Collection collection) Gets the size of the collectionstatic boolean
compareInputStreams
(InputStream stream1, InputStream stream2) Compares content of twoInputStream
sstatic byte[]
concat
(byte[]... byteArrays) Concatenates byte arrays to a single byte array.static <T> boolean
containsAny
(Collection<T> superCollection, Collection<T> subCollection) This method returns boolean result whether thesuperCollection
contains any element of thesubCollection
Ex.static void
copy
(InputStream is, OutputStream os) Copiesis
toos
static boolean
endsWithIgnoreCase
(String text, String expected) Checks if the string ends with case ignore Ex.static byte[]
fromBase64
(String base64) Transforms a base64-encoded string to byte arraystatic byte[]
Transforms a HEX-encoded string to byte arraystatic String
getFileNameExtension
(String filename) This method returns an extension for the given filename Ex.static long
Gets the size of the InputStream contentstatic boolean
isArrayEmpty
(byte[] array) Checks if the byte array is null or emptystatic boolean
isArrayEmpty
(char[] array) Checks if the char array is null or emptystatic boolean
isArrayEmpty
(Object[] array) Checks if the array is null or emptystatic boolean
isArrayNotEmpty
(byte[] array) Checks if the byte array is not null nor emptystatic boolean
isArrayNotEmpty
(char[] array) Checks if the char array is not null nor emptystatic boolean
isArrayNotEmpty
(Object[] array) Checks if the array is not null nor emptystatic boolean
isAtLeastOneStringNotEmpty
(String... values) Checks if at least one string is not emptystatic boolean
isBase64Encoded
(String base64String) Checks if the string is base64-encodedstatic boolean
isCollectionEmpty
(Collection collection) Checks if the collection is null or emptystatic boolean
isCollectionNotEmpty
(Collection collection) Checks if the collection is not null nor emptystatic boolean
isHexEncoded
(String hexString) Checks if the string is HEX (base16) encodedstatic boolean
isMapEmpty
(Map<?, ?> map) Checks if the map is null or emptystatic boolean
isMapNotEmpty
(Map<?, ?> map) Checks if the map is not null nor emptystatic boolean
isStringBlank
(String text) Checks if the string is blank Ex.static boolean
isStringDigits
(String text) Checks if the string contains only digits Ex. "123" = true; "1a2b" = falsestatic boolean
isStringEmpty
(String text) Checks if the string is empty Ex.static boolean
isStringNotBlank
(String text) Checks if the string is not blank Ex.static boolean
isStringNotEmpty
(String text) Checks if the string is not blank Ex.static boolean
Checks if the Boolean value is set to true NOTE: if null, returns false!static String
joinStrings
(List<String> strings, String separator) Joins the strings with the given separator Ex.static Collection
<File> Lists all files from thefolder
with the givenextensions
static String
Converts a string to its lower case representation Ex.static <T> List
<T> reverseList
(List<T> list) Creates a reversed copy of the liststatic boolean
startsWith
(byte[] byteArray, byte[] prefixArray) Checks if thebyteArray
starts withprefixArray
static boolean
startsWith
(InputStream inputStream, byte[] prefixArray) Checks if theinputStream
starts withprefixArray
.static byte[]
subarray
(byte[] array, int start, int length) Returns a subArray, starting from positionstart
with the defined lengthlength
static String
substringAfter
(String text, String after) Returns a substring after the specified character Ex.static String
toBase64
(byte[] bytes) Transforms the binaries to String base64-encoded representationstatic byte[]
Reads the InputStream and returns the resulting byte arraystatic String
toHex
(byte[] bytes) Transforms the binaries to String HEX representationstatic String
Trims the string, by removing all leading and descending spaces and lines Ex. " 123 " = "123"static String
Converts a string to its upper case representation Ex.static void
write
(byte[] content, OutputStream os) Writescontent
toos
-
Field Details
-
EMPTY_STRING
-
-
Method Details
-
isStringEmpty
-
isStringNotEmpty
-
areAllStringsEmpty
-
isAtLeastOneStringNotEmpty
-
isStringBlank
-
isStringNotBlank
-
areStringsEqual
-
areStringsEqualIgnoreCase
-
isStringDigits
-
trim
-
joinStrings
-
concat
public static byte[] concat(byte[]... byteArrays) Concatenates byte arrays to a single byte array. The new array contains all bytes of each array followed by all bytes of the next array. When an array is returned, it is always a new array.- Parameters:
byteArrays
- an array of byte arrays to be concatenated- Returns:
- byte array
-
substringAfter
-
endsWithIgnoreCase
Checks if the string ends with case ignore Ex. "hello", "LO" = true; "hello", "a" = false -
getFileNameExtension
-
lowerCase
-
upperCase
-
isArrayEmpty
Checks if the array is null or empty- Parameters:
array
- to check- Returns:
- TRUE if the array is null or empty, FALSE otherwise
-
isArrayNotEmpty
Checks if the array is not null nor empty- Parameters:
array
- to check- Returns:
- TRUE if the array is not null nor empty, FALSE otherwise
-
arraySize
Gets size of the array. If null, returns 0.- Parameters:
array
- to check- Returns:
- size of the given array
-
isArrayEmpty
public static boolean isArrayEmpty(byte[] array) Checks if the byte array is null or empty- Parameters:
array
- byte array to check- Returns:
- TRUE if the byte array is null or empty, FALSE otherwise
-
isArrayNotEmpty
public static boolean isArrayNotEmpty(byte[] array) Checks if the byte array is not null nor empty- Parameters:
array
- byte array to check- Returns:
- TRUE if the byte array is not null nor empty, FALSE otherwise
-
arraySize
public static int arraySize(byte[] array) Gets size of the byte array. If null, returns 0.- Parameters:
array
- byte array to check- Returns:
- size of the given array
-
isArrayEmpty
public static boolean isArrayEmpty(char[] array) Checks if the char array is null or empty- Parameters:
array
- char array to check- Returns:
- TRUE if the char array is null or empty, FALSE otherwise
-
isArrayNotEmpty
public static boolean isArrayNotEmpty(char[] array) Checks if the char array is not null nor empty- Parameters:
array
- char array to check- Returns:
- TRUE if the char array is not null nor empty, FALSE otherwise
-
arraySize
public static int arraySize(char[] array) Gets size of the char array. If null, returns 0.- Parameters:
array
- char array to check- Returns:
- size of the given array
-
subarray
public static byte[] subarray(byte[] array, int start, int length) Returns a subArray, starting from positionstart
with the defined lengthlength
- Parameters:
array
- byte array to get subArray fromstart
- the start index of the subArraylength
- the final index of the subArray to be copied- Returns:
- subArray
-
isTrue
-
isCollectionEmpty
Checks if the collection is null or empty- Parameters:
collection
- to check- Returns:
- TRUE if the collection is null or empty, FALSE otherwise
-
isCollectionNotEmpty
Checks if the collection is not null nor empty- Parameters:
collection
- to check- Returns:
- TRUE if the collection is not null nor empty, FALSE otherwise
-
isMapEmpty
Checks if the map is null or empty- Parameters:
map
- to check- Returns:
- TRUE if the map is null or empty, FALSE otherwise
-
isMapNotEmpty
Checks if the map is not null nor empty- Parameters:
map
- to check- Returns:
- TRUE if the map is not null nor empty, FALSE otherwise
-
collectionSize
Gets the size of the collection- Parameters:
collection
-Collection
- Returns:
- size of the collection
-
isHexEncoded
-
toHex
-
fromHex
-
isBase64Encoded
-
toBase64
-
fromBase64
-
toByteArray
Reads the InputStream and returns the resulting byte array- Parameters:
is
-InputStream
- Returns:
- byte array
- Throws:
IOException
- if an exception occurs
-
closeQuietly
-
copy
Copiesis
toos
- Parameters:
is
-InputStream
to copyos
-OutputStream
to write the value into- Throws:
IOException
- if an exception occurs
-
write
Writescontent
toos
- Parameters:
content
- byte array to writeos
-OutputStream
to write the value into- Throws:
IOException
- if an exception occurs
-
getInputStreamSize
Gets the size of the InputStream content- Parameters:
is
-InputStream
- Returns:
- size
- Throws:
IOException
- if an exception occurs
-
compareInputStreams
public static boolean compareInputStreams(InputStream stream1, InputStream stream2) throws IOException Compares content of twoInputStream
s- Parameters:
stream1
-InputStream
stream2
-InputStream
- Returns:
- TRUE if the content of two
InputStream
is equal, FALSE otherwise - Throws:
IOException
- if an exception on InputStream read occurs
-
startsWith
public static boolean startsWith(byte[] byteArray, byte[] prefixArray) Checks if thebyteArray
starts withprefixArray
- Parameters:
byteArray
- byte array to verifyprefixArray
- byte array used on verification- Returns:
- TRUE if the byte array starts with a prefix array, FALSE otherwise
-
startsWith
Checks if theinputStream
starts withprefixArray
.- Parameters:
inputStream
- byte array to verifyprefixArray
- byte array used on verification- Returns:
- TRUE if the InputStream starts with a prefix array, FALSE otherwise
- Throws:
IOException
- if an exception occurs
-
cleanDirectory
Cleans the directory- Parameters:
directory
-File
- Throws:
IOException
- if an exception occurs
-
listFiles
Lists all files from thefolder
with the givenextensions
-
reverseList
-
containsAny
This method returns boolean result whether thesuperCollection
contains any element of thesubCollection
Ex. {'A', 'B', 'C'}, {'B', 'C', 'D'} = TRUE- Type Parameters:
T
- object- Parameters:
superCollection
- first collectionsubCollection
- second collection- Returns:
- TRUE if both collection intersect each other, FALSE otherwise
-