Class GoogleGuavaUtils

java.lang.Object
eu.europa.esig.dss.utils.guava.impl.GoogleGuavaUtils
All Implemented Interfaces:
IUtils

public class GoogleGuavaUtils extends Object implements IUtils
Google Guava implementation of Utils
  • Constructor Details

    • GoogleGuavaUtils

      public GoogleGuavaUtils()
      Default constructor
  • Method Details

    • isStringEmpty

      public boolean isStringEmpty(String text)
      Description copied from interface: IUtils
      Checks if the string is empty Ex. "nowina" = false; "" = true NOTE: blank string (e.g. " ") is not empty!
      Specified by:
      isStringEmpty in interface IUtils
      Parameters:
      text - String
      Returns:
      TRUE if the string is empty, FALSE otherwise
    • isStringNotEmpty

      public boolean isStringNotEmpty(String text)
      Description copied from interface: IUtils
      Checks if the string is not empty Ex. "nowina" = true; "" = false NOTE: blank string (e.g. " ") is not empty!
      Specified by:
      isStringNotEmpty in interface IUtils
      Parameters:
      text - String
      Returns:
      TRUE if the string is not empty, FALSE otherwise
    • isStringBlank

      public boolean isStringBlank(String text)
      Description copied from interface: IUtils
      Checks if the string is blank Ex. "nowina" = false; " " = true
      Specified by:
      isStringBlank in interface IUtils
      Parameters:
      text - String
      Returns:
      TRUE if the string is blank, FALSE otherwise
    • isStringNotBlank

      public boolean isStringNotBlank(String text)
      Description copied from interface: IUtils
      Checks if the string is not blank Ex. "nowina" = true; " " = false
      Specified by:
      isStringNotBlank in interface IUtils
      Parameters:
      text - String
      Returns:
      TRUE if the string is not blank, FALSE otherwise
    • areStringsEqual

      public boolean areStringsEqual(String text1, String text2)
      Description copied from interface: IUtils
      Checks if the strings are equal Ex. "nowina" == "nowina" = true; "nowina" == "Nowina" = false
      Specified by:
      areStringsEqual in interface IUtils
      Parameters:
      text1 - String
      text2 - String
      Returns:
      TRUE if the strings are equal, FALSE otherwise
    • areStringsEqualIgnoreCase

      public boolean areStringsEqualIgnoreCase(String text1, String text2)
      Description copied from interface: IUtils
      Checks if the strings are equal with case ignore Ex. "nowina" == "Nowina" = true; "water" == "fire" = false
      Specified by:
      areStringsEqualIgnoreCase in interface IUtils
      Parameters:
      text1 - String
      text2 - String
      Returns:
      TRUE if the strings are equal with case ignore, FALSE otherwise
    • isStringDigits

      public boolean isStringDigits(String text)
      Description copied from interface: IUtils
      Checks if the string contains only digits Ex. "123" = true; "1a2b" = false
      Specified by:
      isStringDigits in interface IUtils
      Parameters:
      text - String
      Returns:
      TRUE if the string contains only digits, FALSE otherwise
    • trim

      public String trim(String text)
      Description copied from interface: IUtils
      Trims the string, by removing all leading and descending spaces and lines Ex. " 123 " = "123"
      Specified by:
      trim in interface IUtils
      Parameters:
      text - String
      Returns:
      the trimmed string
    • joinStrings

      public String joinStrings(Collection<String> strings, String separator)
      Description copied from interface: IUtils
      Joins the strings with the given separator Ex. "Nowina" "123", "," = "Nowina,123"
      Specified by:
      joinStrings in interface IUtils
      Parameters:
      strings - a collection of Strings
      separator - String
      Returns:
      the joined string
    • concat

      public byte[] concat(byte[]... byteArrays)
      Description copied from interface: IUtils
      Concatenates byte arrays to a single byte array
      Specified by:
      concat in interface IUtils
      Parameters:
      byteArrays - an array of byte arrays to be concatenated
      Returns:
      byte array
    • substringAfter

      public String substringAfter(String text, String after)
      Description copied from interface: IUtils
      Returns a substring after the specified character Ex. "aaaaa?bbb", "?" = "bbb"
      Specified by:
      substringAfter in interface IUtils
      Parameters:
      text - String to get a substring from
      after - String string to get a substring after which
      Returns:
      the substring
    • endsWithIgnoreCase

      public boolean endsWithIgnoreCase(String text, String expected)
      Description copied from interface: IUtils
      Checks if the string ends with case ignore Ex. "hello", "LO" = true; "hello", "a" = false
      Specified by:
      endsWithIgnoreCase in interface IUtils
      Parameters:
      text - String to check
      expected - String the end string to check
      Returns:
      TRUE if the string ends with case ignore, FALSE otherwise
    • getFileNameExtension

      public String getFileNameExtension(String filename)
      Description copied from interface: IUtils
      This method returns an extension for the given filename Ex. "file.xml" = "xml"; "document.pdf" = "pdf"
      Specified by:
      getFileNameExtension in interface IUtils
      Parameters:
      filename - String representing a filename extracted from a file
      Returns:
      String extension
    • lowerCase

      public String lowerCase(String text)
      Description copied from interface: IUtils
      Converts a string to its lower case representation Ex. "Nowina" = "nowina"
      Specified by:
      lowerCase in interface IUtils
      Parameters:
      text - String
      Returns:
      the lower case string
    • upperCase

      public String upperCase(String text)
      Description copied from interface: IUtils
      Converts a string to its upper case representation Ex. "Nowina" = "NOWINA"
      Specified by:
      upperCase in interface IUtils
      Parameters:
      text - String
      Returns:
      the upper case string
    • isArrayEmpty

      public boolean isArrayEmpty(Object[] array)
      Description copied from interface: IUtils
      Checks if the array is null or empty
      Specified by:
      isArrayEmpty in interface IUtils
      Parameters:
      array - to check
      Returns:
      TRUE if the array is null or empty, FALSE otherwise
    • isArrayNotEmpty

      public boolean isArrayNotEmpty(Object[] array)
      Description copied from interface: IUtils
      Checks if the array is not null nor empty
      Specified by:
      isArrayNotEmpty in interface IUtils
      Parameters:
      array - to check
      Returns:
      TRUE if the array is not null nor empty, FALSE otherwise
    • isArrayEmpty

      public boolean isArrayEmpty(byte[] array)
      Description copied from interface: IUtils
      Checks if the byte array is null or empty
      Specified by:
      isArrayEmpty in interface IUtils
      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: IUtils
      Checks if the byte array is not null nor empty
      Specified by:
      isArrayNotEmpty in interface IUtils
      Parameters:
      array - byte array to check
      Returns:
      TRUE if the byte array is not null nor empty, FALSE otherwise
    • isArrayEmpty

      public boolean isArrayEmpty(char[] array)
      Description copied from interface: IUtils
      Checks if the char array is null or empty
      Specified by:
      isArrayEmpty in interface IUtils
      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: IUtils
      Checks if the char array is not null nor empty
      Specified by:
      isArrayNotEmpty in interface IUtils
      Parameters:
      array - char array to check
      Returns:
      TRUE if the char array is not null nor empty, FALSE otherwise
    • subarray

      public byte[] subarray(byte[] array, int start, int length)
      Description copied from interface: IUtils
      Returns a subArray, starting from position start with the defined length length
      Specified by:
      subarray in interface IUtils
      Parameters:
      array - byte array to get subArray from
      start - the start index of the subArray
      length - the final index of the subArray to be copied
      Returns:
      subArray
    • isTrue

      public boolean isTrue(Boolean bool)
      Description copied from interface: IUtils
      Checks if the Boolean value is set to true NOTE: if null, returns false!
      Specified by:
      isTrue in interface IUtils
      Parameters:
      bool - Boolean
      Returns:
      TRUE if the value is set to true, FALSE otherwise
    • isCollectionEmpty

      public boolean isCollectionEmpty(Collection collection)
      Description copied from interface: IUtils
      Checks if the collection is null or empty
      Specified by:
      isCollectionEmpty in interface IUtils
      Parameters:
      collection - to check
      Returns:
      TRUE if the collection is null or empty, FALSE otherwise
    • isCollectionNotEmpty

      public boolean isCollectionNotEmpty(Collection collection)
      Description copied from interface: IUtils
      Checks if the collection is not null nor empty
      Specified by:
      isCollectionNotEmpty in interface IUtils
      Parameters:
      collection - to check
      Returns:
      TRUE if the collection is not null nor empty, FALSE otherwise
    • isMapEmpty

      public boolean isMapEmpty(Map<?,?> map)
      Description copied from interface: IUtils
      Checks if the map is null or empty
      Specified by:
      isMapEmpty in interface IUtils
      Parameters:
      map - to check
      Returns:
      TRUE if the map is null or empty, FALSE otherwise
    • isMapNotEmpty

      public boolean isMapNotEmpty(Map<?,?> map)
      Description copied from interface: IUtils
      Checks if the map is not null nor empty
      Specified by:
      isMapNotEmpty in interface IUtils
      Parameters:
      map - to check
      Returns:
      TRUE if the map is not null nor empty, FALSE otherwise
    • collectionSize

      public int collectionSize(Collection collection)
      Description copied from interface: IUtils
      Gets the size of the collection
      Specified by:
      collectionSize in interface IUtils
      Parameters:
      collection - Collection
      Returns:
      size of the collection
    • isHexEncoded

      public boolean isHexEncoded(String hexString)
      Description copied from interface: IUtils
      Checks if the string is HEX (base16) encoded
      Specified by:
      isHexEncoded in interface IUtils
      Parameters:
      hexString - String
      Returns:
      TRUE if he string is HEX encoded, FALSE otherwise
    • toHex

      public String toHex(byte[] bytes)
      Description copied from interface: IUtils
      Transforms the binaries to String HEX representation
      Specified by:
      toHex in interface IUtils
      Parameters:
      bytes - byte array
      Returns:
      String HEX-encoded
    • fromHex

      public byte[] fromHex(String hex)
      Description copied from interface: IUtils
      Transforms a HEX-encoded string to byte array
      Specified by:
      fromHex in interface IUtils
      Parameters:
      hex - String hex-encoded
      Returns:
      byte array
    • isBase64Encoded

      public boolean isBase64Encoded(String base64String)
      Description copied from interface: IUtils
      Checks if the string is base64-encoded
      Specified by:
      isBase64Encoded in interface IUtils
      Parameters:
      base64String - String
      Returns:
      TRUE if the String is base64-encoded, FALSE otherwise
    • toBase64

      public String toBase64(byte[] bytes)
      Description copied from interface: IUtils
      Transforms the binaries to String base64-encoded representation
      Specified by:
      toBase64 in interface IUtils
      Parameters:
      bytes - byte array
      Returns:
      String base64-encoded
    • fromBase64

      public byte[] fromBase64(String base64)
      Description copied from interface: IUtils
      Transforms a base64-encoded string to byte array
      Specified by:
      fromBase64 in interface IUtils
      Parameters:
      base64 - String base64-encoded
      Returns:
      byte array
    • toByteArray

      public byte[] toByteArray(InputStream is) throws IOException
      Description copied from interface: IUtils
      Reads the InputStream and returns the resulting byte array
      Specified by:
      toByteArray in interface IUtils
      Parameters:
      is - InputStream
      Returns:
      byte array
      Throws:
      IOException - if an exception occurs
    • closeQuietly

      public void closeQuietly(Closeable closeable)
      Description copied from interface: IUtils
      Closes quietly
      Specified by:
      closeQuietly in interface IUtils
      Parameters:
      closeable - Closeable
    • copy

      public void copy(InputStream is, OutputStream os) throws IOException
      Description copied from interface: IUtils
      Copies is to os
      Specified by:
      copy in interface IUtils
      Parameters:
      is - InputStream to copy
      os - OutputStream to write the value into
      Throws:
      IOException - if an exception occurs
    • write

      public void write(byte[] content, OutputStream os) throws IOException
      Description copied from interface: IUtils
      Writes content to os
      Specified by:
      write in interface IUtils
      Parameters:
      content - byte array to write
      os - OutputStream to write the value into
      Throws:
      IOException - if an exception occurs
    • getInputStreamSize

      public long getInputStreamSize(InputStream is) throws IOException
      Description copied from interface: IUtils
      Gets the size of the InputStream content
      Specified by:
      getInputStreamSize in interface IUtils
      Parameters:
      is - InputStream
      Returns:
      size
      Throws:
      IOException - if an exception occurs
    • compareInputStreams

      public boolean compareInputStreams(InputStream stream1, InputStream stream2) throws IOException
      Description copied from interface: IUtils
      Compares content of two InputStreams
      Specified by:
      compareInputStreams in interface IUtils
      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 boolean startsWith(byte[] byteArray, byte[] prefixArray)
      Description copied from interface: IUtils
      Checks if the byteArray starts with prefixArray
      Specified by:
      startsWith in interface IUtils
      Parameters:
      byteArray - byte array to verify
      prefixArray - byte array used on verification
      Returns:
      TRUE if the byte array starts with a prefix array, FALSE otherwise
    • startsWith

      public boolean startsWith(InputStream inputStream, byte[] prefixArray)
      Description copied from interface: IUtils
      Checks if the inputStream starts with prefixArray.
      Specified by:
      startsWith in interface IUtils
      Parameters:
      inputStream - byte array to verify
      prefixArray - byte array used on verification
      Returns:
      TRUE if the InputStream starts with a prefix array, FALSE otherwise
    • cleanDirectory

      public void cleanDirectory(File directory) throws IOException
      Description copied from interface: IUtils
      Cleans the directory
      Specified by:
      cleanDirectory in interface IUtils
      Parameters:
      directory - File
      Throws:
      IOException - if an exception occurs
    • listFiles

      public Collection<File> listFiles(File folder, String[] extensions, boolean recursive)
      Description copied from interface: IUtils
      Lists all files from the folder with the given extensions
      Specified by:
      listFiles in interface IUtils
      Parameters:
      folder - File the directory to get files from
      extensions - Strings to get files with
      recursive - defines if the files has to be obtained recursively (from children directories)
      Returns:
      a collection of Files
    • reverseList

      public <T> List<T> reverseList(List<T> list)
      Description copied from interface: IUtils
      Creates a reversed copy of the list
      Specified by:
      reverseList in interface IUtils
      Type Parameters:
      T - the class of list elements
      Parameters:
      list - List to get a reversed copy of
      Returns:
      reversed list
    • containsAny

      public <T> boolean containsAny(Collection<T> superCollection, Collection<T> subCollection)
      Description copied from interface: IUtils
      This method returns boolean result whether the superCollection contains any element of the subCollection Ex. {'A', 'B', 'C'}, {'B', 'C', 'D'} = TRUE
      Specified by:
      containsAny in interface IUtils
      Type Parameters:
      T - object
      Parameters:
      superCollection - first collection
      subCollection - second collection
      Returns:
      TRUE if both collection intersect each other, FALSE otherwise