Class ApacheCommonsUtils
java.lang.Object
eu.europa.esig.dss.utils.apache.impl.ApacheCommonsUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanareStringsEqual(String text1, String text2) Checks if the strings are equal Ex.booleanareStringsEqualIgnoreCase(String text1, String text2) Checks if the strings are equal with case ignore Ex.intarraySize(byte[] array) Gets size of the byte array.intarraySize(char[] array) Gets size of the byte array.intGets size of the array.voidcleanDirectory(File directory) Cleans the directoryvoidcloseQuietly(Closeable closeable) Closes quietlyintcollectionSize(Collection collection) Gets the size of the collectionbooleancompareInputStreams(InputStream stream1, InputStream stream2) Compares content of twoInputStreamsbyte[]concat(byte[]... byteArrays) Concatenates byte arrays to a single byte array<T> booleancontainsAny(Collection<T> superCollection, Collection<T> subCollection) This method returns boolean result whether thesuperCollectioncontains any element of thesubCollectionEx.voidcopy(InputStream is, OutputStream os) CopiesistoosbooleanendsWithIgnoreCase(String text, String expected) Checks if the string ends with case ignore Ex.byte[]fromBase64(String base64) Transforms a base64-encoded string to byte arraybyte[]Transforms a HEX-encoded string to byte arraygetFileNameExtension(String filename) This method returns an extension for the given filename Ex.longGets the size of the InputStream contentbooleanisArrayEmpty(byte[] array) Checks if the byte array is null or emptybooleanisArrayEmpty(char[] array) Checks if the char array is null or emptybooleanisArrayEmpty(Object[] array) Checks if the array is null or emptybooleanisArrayNotEmpty(byte[] array) Checks if the byte array is not null nor emptybooleanisArrayNotEmpty(char[] array) Checks if the char array is not null nor emptybooleanisArrayNotEmpty(Object[] array) Checks if the array is not null nor emptybooleanisBase64Encoded(String base64String) Checks if the string is base64-encodedbooleanisCollectionEmpty(Collection collection) Checks if the collection is null or emptybooleanisCollectionNotEmpty(Collection collection) Checks if the collection is not null nor emptybooleanisHexEncoded(String hexString) Checks if the string is HEX (base16) encodedbooleanisMapEmpty(Map<?, ?> map) Checks if the map is null or emptybooleanisMapNotEmpty(Map<?, ?> map) Checks if the map is not null nor emptybooleanisStringBlank(String text) Checks if the string is blank Ex.booleanisStringDigits(String text) Checks if the string contains only digits Ex. "123" = true; "1a2b" = falsebooleanisStringEmpty(String text) Checks if the string is empty Ex.booleanisStringNotBlank(String text) Checks if the string is not blank Ex.booleanisStringNotEmpty(String text) Checks if the string is not empty Ex.booleanChecks if the Boolean value is set to true NOTE: if null, returns false!joinStrings(Collection<String> strings, String separator) Joins the strings with the given separator Ex.Lists all files from thefolderwith the givenextensionsConverts a string to its lower case representation Ex.<T> List<T> reverseList(List<T> list) Creates a reversed copy of the listbooleanstartsWith(byte[] byteArray, byte[] prefixArray) Checks if thebyteArraystarts withprefixArraybooleanstartsWith(InputStream inputStream, byte[] prefixArray) Checks if theinputStreamstarts withprefixArray.byte[]subarray(byte[] array, int start, int length) Returns a subArray, starting from positionstartwith the defined lengthlengthsubstringAfter(String text, String after) Returns a substring after the specified character Ex.toBase64(byte[] bytes) Transforms the binaries to String base64-encoded representationbyte[]Reads the InputStream and returns the resulting byte arraytoHex(byte[] bytes) Transforms the binaries to String HEX representationTrims the string, by removing all leading and descending spaces and lines Ex. " 123 " = "123"Converts a string to its upper case representation Ex.voidwrite(byte[] content, OutputStream os) Writescontenttoos
-
Constructor Details
-
ApacheCommonsUtils
public ApacheCommonsUtils()Default constructor
-
-
Method Details
-
isStringEmpty
Description copied from interface:IUtilsChecks if the string is empty Ex. "nowina" = false; "" = true NOTE: blank string (e.g. " ") is not empty!- Specified by:
isStringEmptyin interfaceIUtils- Parameters:
text-String- Returns:
- TRUE if the string is empty, FALSE otherwise
-
isStringNotEmpty
Description copied from interface:IUtilsChecks if the string is not empty Ex. "nowina" = true; "" = false NOTE: blank string (e.g. " ") is not empty!- Specified by:
isStringNotEmptyin interfaceIUtils- Parameters:
text-String- Returns:
- TRUE if the string is not empty, FALSE otherwise
-
isStringBlank
Description copied from interface:IUtilsChecks if the string is blank Ex. "nowina" = false; " " = true- Specified by:
isStringBlankin interfaceIUtils- Parameters:
text-String- Returns:
- TRUE if the string is blank, FALSE otherwise
-
isStringNotBlank
Description copied from interface:IUtilsChecks if the string is not blank Ex. "nowina" = true; " " = false- Specified by:
isStringNotBlankin interfaceIUtils- Parameters:
text-String- Returns:
- TRUE if the string is not blank, FALSE otherwise
-
areStringsEqual
Description copied from interface:IUtilsChecks if the strings are equal Ex. "nowina" == "nowina" = true; "nowina" == "Nowina" = false- Specified by:
areStringsEqualin interfaceIUtils- Parameters:
text1-Stringtext2-String- Returns:
- TRUE if the strings are equal, FALSE otherwise
-
areStringsEqualIgnoreCase
Description copied from interface:IUtilsChecks if the strings are equal with case ignore Ex. "nowina" == "Nowina" = true; "water" == "fire" = false- Specified by:
areStringsEqualIgnoreCasein interfaceIUtils- Parameters:
text1-Stringtext2-String- Returns:
- TRUE if the strings are equal with case ignore, FALSE otherwise
-
isStringDigits
Description copied from interface:IUtilsChecks if the string contains only digits Ex. "123" = true; "1a2b" = false- Specified by:
isStringDigitsin interfaceIUtils- Parameters:
text-String- Returns:
- TRUE if the string contains only digits, FALSE otherwise
-
trim
-
joinStrings
Description copied from interface:IUtilsJoins the strings with the given separator Ex. "Nowina" "123", "," = "Nowina,123"- Specified by:
joinStringsin interfaceIUtils- Parameters:
strings- a collection ofStringsseparator-String- Returns:
- the joined string
-
concat
-
substringAfter
Description copied from interface:IUtilsReturns a substring after the specified character Ex. "aaaaa?bbb", "?" = "bbb"- Specified by:
substringAfterin interfaceIUtils- Parameters:
text-Stringto get a substring fromafter-Stringstring to get a substring after which- Returns:
- the substring
-
endsWithIgnoreCase
Description copied from interface:IUtilsChecks if the string ends with case ignore Ex. "hello", "LO" = true; "hello", "a" = false- Specified by:
endsWithIgnoreCasein interfaceIUtils- Parameters:
text-Stringto checkexpected-Stringthe end string to check- Returns:
- TRUE if the string ends with case ignore, FALSE otherwise
-
getFileNameExtension
Description copied from interface:IUtilsThis method returns an extension for the given filename Ex. "file.xml" = "xml"; "document.pdf" = "pdf"- Specified by:
getFileNameExtensionin interfaceIUtils- Parameters:
filename-Stringrepresenting a filename extracted from a file- Returns:
Stringextension
-
lowerCase
-
upperCase
-
isArrayEmpty
Description copied from interface:IUtilsChecks if the array is null or empty- Specified by:
isArrayEmptyin interfaceIUtils- Parameters:
array- to check- Returns:
- TRUE if the array is null or empty, FALSE otherwise
-
isArrayNotEmpty
Description copied from interface:IUtilsChecks if the array is not null nor empty- Specified by:
isArrayNotEmptyin interfaceIUtils- Parameters:
array- to check- Returns:
- TRUE if the array is not null nor empty, FALSE otherwise
-
arraySize
-
isArrayEmpty
public boolean isArrayEmpty(byte[] array) Description copied from interface:IUtilsChecks if the byte array is null or empty- Specified by:
isArrayEmptyin interfaceIUtils- Parameters:
array- byte array to check- Returns:
- TRUE if the byte array is null or empty, FALSE otherwise
-
isArrayNotEmpty
public boolean isArrayNotEmpty(byte[] array) Description copied from interface:IUtilsChecks if the byte array is not null nor empty- Specified by:
isArrayNotEmptyin interfaceIUtils- Parameters:
array- byte array to check- Returns:
- TRUE if the byte array is not null nor empty, FALSE otherwise
-
arraySize
-
isArrayEmpty
public boolean isArrayEmpty(char[] array) Description copied from interface:IUtilsChecks if the char array is null or empty- Specified by:
isArrayEmptyin interfaceIUtils- Parameters:
array- char array to check- Returns:
- TRUE if the char array is null or empty, FALSE otherwise
-
isArrayNotEmpty
public boolean isArrayNotEmpty(char[] array) Description copied from interface:IUtilsChecks if the char array is not null nor empty- Specified by:
isArrayNotEmptyin interfaceIUtils- Parameters:
array- char array to check- Returns:
- TRUE if the char array is not null nor empty, FALSE otherwise
-
arraySize
-
subarray
public byte[] subarray(byte[] array, int start, int length) Description copied from interface:IUtilsReturns a subArray, starting from positionstartwith the defined lengthlength -
isTrue
-
isCollectionEmpty
Description copied from interface:IUtilsChecks if the collection is null or empty- Specified by:
isCollectionEmptyin interfaceIUtils- Parameters:
collection- to check- Returns:
- TRUE if the collection is null or empty, FALSE otherwise
-
isCollectionNotEmpty
Description copied from interface:IUtilsChecks if the collection is not null nor empty- Specified by:
isCollectionNotEmptyin interfaceIUtils- Parameters:
collection- to check- Returns:
- TRUE if the collection is not null nor empty, FALSE otherwise
-
isMapEmpty
Description copied from interface:IUtilsChecks if the map is null or empty- Specified by:
isMapEmptyin interfaceIUtils- Parameters:
map- to check- Returns:
- TRUE if the map is null or empty, FALSE otherwise
-
isMapNotEmpty
Description copied from interface:IUtilsChecks if the map is not null nor empty- Specified by:
isMapNotEmptyin interfaceIUtils- Parameters:
map- to check- Returns:
- TRUE if the map is not null nor empty, FALSE otherwise
-
collectionSize
Description copied from interface:IUtilsGets the size of the collection- Specified by:
collectionSizein interfaceIUtils- Parameters:
collection-Collection- Returns:
- size of the collection
-
isHexEncoded
Description copied from interface:IUtilsChecks if the string is HEX (base16) encoded- Specified by:
isHexEncodedin interfaceIUtils- Parameters:
hexString-String- Returns:
- TRUE if he string is HEX encoded, FALSE otherwise
-
toHex
-
fromHex
-
isBase64Encoded
Description copied from interface:IUtilsChecks if the string is base64-encoded- Specified by:
isBase64Encodedin interfaceIUtils- Parameters:
base64String-String- Returns:
- TRUE if the String is base64-encoded, FALSE otherwise
-
toBase64
-
fromBase64
Description copied from interface:IUtilsTransforms a base64-encoded string to byte array- Specified by:
fromBase64in interfaceIUtils- Parameters:
base64-Stringbase64-encoded- Returns:
- byte array
-
toByteArray
Description copied from interface:IUtilsReads the InputStream and returns the resulting byte array- Specified by:
toByteArrayin interfaceIUtils- Parameters:
is-InputStream- Returns:
- byte array
- Throws:
IOException- if an exception occurs
-
closeQuietly
Description copied from interface:IUtilsCloses quietly- Specified by:
closeQuietlyin interfaceIUtils- Parameters:
closeable-Closeable
-
copy
Description copied from interface:IUtilsCopiesistoos- Specified by:
copyin interfaceIUtils- Parameters:
is-InputStreamto copyos-OutputStreamto write the value into- Throws:
IOException- if an exception occurs
-
write
Description copied from interface:IUtilsWritescontenttoos- Specified by:
writein interfaceIUtils- Parameters:
content- byte array to writeos-OutputStreamto write the value into- Throws:
IOException- if an exception occurs
-
getInputStreamSize
Description copied from interface:IUtilsGets the size of the InputStream content- Specified by:
getInputStreamSizein interfaceIUtils- Parameters:
is-InputStream- Returns:
- size
- Throws:
IOException- if an exception occurs
-
compareInputStreams
Description copied from interface:IUtilsCompares content of twoInputStreams- Specified by:
compareInputStreamsin interfaceIUtils- Parameters:
stream1-InputStreamstream2-InputStream- Returns:
- TRUE if the content of two
InputStreamis equal, FALSE otherwise - Throws:
IOException- if an exception on InputStream read occurs
-
startsWith
public boolean startsWith(byte[] byteArray, byte[] prefixArray) Description copied from interface:IUtilsChecks if thebyteArraystarts withprefixArray- Specified by:
startsWithin interfaceIUtils- 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
Description copied from interface:IUtilsChecks if theinputStreamstarts withprefixArray.- Specified by:
startsWithin interfaceIUtils- 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
Description copied from interface:IUtilsCleans the directory- Specified by:
cleanDirectoryin interfaceIUtils- Parameters:
directory-File- Throws:
IOException- if an exception occurs
-
listFiles
Description copied from interface:IUtilsLists all files from thefolderwith the givenextensions -
reverseList
-
containsAny
Description copied from interface:IUtilsThis method returns boolean result whether thesuperCollectioncontains any element of thesubCollectionEx. {'A', 'B', 'C'}, {'B', 'C', 'D'} = TRUE- Specified by:
containsAnyin interfaceIUtils- Type Parameters:
T- object- Parameters:
superCollection- first collectionsubCollection- second collection- Returns:
- TRUE if both collection intersect each other, FALSE otherwise
-