Class Utils

java.lang.Object
org.vafer.jdeb.utils.Utils

public final class Utils extends Object
Simple utils functions. ATTENTION: don't use outside of jdeb
  • Constructor Details

  • Method Details

    • copy

      public static int copy(InputStream pInput, OutputStream pOutput) throws IOException
      Throws:
      IOException
    • toHex

      public static String toHex(byte[] bytes)
    • stripPath

      public static String stripPath(int p, String s)
    • joinUnixPath

      public static String joinUnixPath(String... paths)
    • joinLocalPath

      public static String joinLocalPath(String... paths)
    • stripLeadingSlash

      public static String stripLeadingSlash(String s)
    • replaceVariables

      public static String replaceVariables(VariableResolver pResolver, String pExpression, String pOpen, String pClose)
      Substitute the variables in the given expression with the values from the resolver
      Parameters:
      pResolver -
      pExpression -
    • toUnixLineEndings

      public static byte[] toUnixLineEndings(InputStream input) throws IOException
      Replaces new line delimiters in the input stream with the Unix line feed.
      Parameters:
      input -
      Throws:
      IOException
    • convertToDebianVersion

      public static String convertToDebianVersion(String version, boolean apply, String envName, String template, Date timestamp)
      Convert the project version to a version suitable for a Debian package. -SNAPSHOT suffixes are replaced with a timestamp (~yyyyMMddHHmmss). The separator before a rc, alpha or beta version is replaced with '~' such that the version is always ordered before the final or GA release.
      Parameters:
      version - the project version to convert to a Debian package version
      template - the template used to replace -SNAPSHOT, the timestamp format is in brackets, the rest of the string is preserved (prefix[yyMMdd]suffix -> prefix151230suffix)
      timestamp - the UTC date used as the timestamp to replace the SNAPSHOT suffix.
    • movePath

      public static String movePath(String file, String target)
      Construct new path by replacing file directory part. No files are actually modified.
      Parameters:
      file - path to move
      target - new path directory
    • lookupIfEmpty

      public static String lookupIfEmpty(String value, Map<String,​String> props, String key)
      Extracts value from map if given value is null.
      Parameters:
      value - current value
      props - properties to extract value from
      key - property name to extract
      Returns:
      initial value or value extracted from map
    • getKnownPGPSecureRingLocations

      Get the known locations where the secure keyring can be located. Looks through known locations of the GNU PG secure keyring.
      Returns:
      The location of the PGP secure keyring if it was found, null otherwise
    • guessKeyRingFile

      Tries to guess location of the user secure keyring using various heuristics.
      Returns:
      path to the keyring file
      Throws:
      FileNotFoundException - if no keyring file found
    • isNullOrEmpty

      public static boolean isNullOrEmpty(String str)
      Returns true if string is null or empty.
    • defaultString

      public static String defaultString(String str, String fallback)
      Return fallback if first string is null or empty
    • isBlank

      public static boolean isBlank(CharSequence cs)
      Check if a CharSequence is whitespace, empty ("") or null.
       StringUtils.isBlank(null)      = true
       StringUtils.isBlank("")        = true
       StringUtils.isBlank(" ")       = true
       StringUtils.isBlank("bob")     = false
       StringUtils.isBlank("  bob  ") = false
       
      Parameters:
      cs - the CharSequence to check, may be null
      Returns:
      true if the CharSequence is null, empty or whitespace