java.lang.Object
org.mozilla.jss.netscape.security.util.Utils

public class Utils extends Object
  • Field Details

    • logger

      private static final org.slf4j.Logger logger
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • isNT

      public static boolean isNT()
      Checks if this is NT.
    • isUnix

      public static boolean isUnix()
    • exec

      public static boolean exec(String cmd)
    • readFromStream

      public static String readFromStream(InputStream inputStream) throws IOException
      Throws:
      IOException
    • writeToStream

      public static void writeToStream(OutputStream outputStream, String input) throws IOException
      Throws:
      IOException
    • exec

      public static String exec(String[] cmd, String input) throws IOException, InterruptedException
      Utility method to execute system commands
      Parameters:
      cmd - The command to be executed and its arguments
      input - The stdin input to be passed to the cmd
      Returns:
      stdout or stderr of the command executed
      Throws:
      IOException
      InterruptedException
    • SpecialURLDecode

      public static String SpecialURLDecode(String s)
    • SpecialDecode

      public static byte[] SpecialDecode(String s)
    • SpecialEncode

      public static String SpecialEncode(byte[] data)
    • HexEncode

      public static String HexEncode(byte[] data)
    • checkHost

      public static void checkHost(String hostname) throws UnknownHostException
      Throws:
      UnknownHostException
    • copy

      public static void copy(String orig, String dest) throws Exception
      Throws:
      Exception
    • copyStream

      public static void copyStream(InputStream in, OutputStream out) throws IOException
      Throws:
      IOException
    • copyStream

      public static void copyStream(BufferedReader in, OutputStreamWriter out) throws IOException
      Throws:
      IOException
    • sortStrings

      public static void sortStrings(String[] strings)
    • lsDateStr

      public static String lsDateStr(Date date)
    • byteArraysAreEqual

      public static boolean byteArraysAreEqual(byte[] a, byte[] b)
      compares contents two byte arrays returning true if exactly same.
    • stripQuotes

      public static String stripQuotes(String s)
      strips out double quotes around String parameter
      Parameters:
      s - the string potentially bracketed with double quotes
      Returns:
      string stripped of surrounding double quotes
    • getStringArrayFromVector

      public static String[] getStringArrayFromVector(Vector<String> v)
      returns an array of strings from a vector of Strings there'll be trouble if the Vector contains something other than just Strings
    • base64encode

      public static String base64encode(byte[] bytes, boolean chunked)
      Converts a byte array into a Base-64 encoded string. If the chunked option is true, the output will be split into multiple lines. Otherwise, the output will be a single line.
      Parameters:
      bytes - byte array
      chunked - generate chunked output
      Returns:
      base-64 encoded data
    • base64encodeMultiLine

      public static String base64encodeMultiLine(byte[] bytes)
      Converts a byte array into a multi-line Base-64 encoded string. Each line is at most 64-character long and terminated with CRLF.
      Parameters:
      bytes - byte array
      Returns:
      base-64 encoded data
    • base64encodeSingleLine

      public static String base64encodeSingleLine(byte[] bytes)
      Converts a byte array into a single-line Base-64 encoded string. The line is not terminated with CRLF.
      Parameters:
      bytes - byte array
      Returns:
      base-64 encoded data
    • base64decode

      public static byte[] base64decode(String string)
      Converts a Base-64 encoded string into a byte array.
      Parameters:
      string - base-64 encoded data
      Returns:
      byte array
    • normalizeString

      public static String normalizeString(String string)
      Normalize B64 input String
      Parameters:
      string - base-64 string
      Returns:
      normalized string
    • normalizeString

      public static String normalizeString(String string, Boolean keepSpace)
      Normalize B64 input String
      Parameters:
      string - base-64 string
      keepSpace - a boolean variable to control whether to keep spaces or not
      Returns:
      normalized string