Class Utils
- java.lang.Object
-
- org.mozilla.jss.netscape.security.util.Utils
-
public class Utils extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]
base64decode(java.lang.String string)
Converts a Base-64 encoded string into a byte array.static java.lang.String
base64encode(byte[] bytes, boolean chunked)
Converts a byte array into a Base-64 encoded string.static java.lang.String
base64encodeMultiLine(byte[] bytes)
Converts a byte array into a multi-line Base-64 encoded string.static java.lang.String
base64encodeSingleLine(byte[] bytes)
Converts a byte array into a single-line Base-64 encoded string.static boolean
byteArraysAreEqual(byte[] a, byte[] b)
compares contents two byte arrays returning true if exactly same.static void
checkHost(java.lang.String hostname)
static void
copy(java.lang.String orig, java.lang.String dest)
static void
copyStream(java.io.BufferedReader in, java.io.OutputStreamWriter out)
static void
copyStream(java.io.InputStream in, java.io.OutputStream out)
static boolean
exec(java.lang.String cmd)
static java.lang.String
exec(java.lang.String[] cmd, java.lang.String input)
Utility method to execute system commandsstatic java.lang.String[]
getStringArrayFromVector(java.util.Vector<java.lang.String> v)
returns an array of strings from a vector of Strings there'll be trouble if the Vector contains something other than just Stringsstatic java.lang.String
HexEncode(byte[] data)
static boolean
isNT()
Checks if this is NT.static boolean
isUnix()
static java.lang.String
lsDateStr(java.util.Date date)
static java.lang.String
normalizeString(java.lang.String string)
Normalize B64 input Stringstatic java.lang.String
normalizeString(java.lang.String string, java.lang.Boolean keepSpace)
Normalize B64 input Stringstatic java.lang.String
readFromStream(java.io.InputStream inputStream)
static void
sortStrings(java.lang.String[] strings)
static byte[]
SpecialDecode(java.lang.String s)
static java.lang.String
SpecialEncode(byte[] data)
static java.lang.String
SpecialURLDecode(java.lang.String s)
static java.lang.String
stripQuotes(java.lang.String s)
strips out double quotes around String parameterstatic void
writeToStream(java.io.OutputStream outputStream, java.lang.String input)
-
-
-
Method Detail
-
isNT
public static boolean isNT()
Checks if this is NT.
-
isUnix
public static boolean isUnix()
-
exec
public static boolean exec(java.lang.String cmd)
-
readFromStream
public static java.lang.String readFromStream(java.io.InputStream inputStream) throws java.io.IOException
- Throws:
java.io.IOException
-
writeToStream
public static void writeToStream(java.io.OutputStream outputStream, java.lang.String input) throws java.io.IOException
- Throws:
java.io.IOException
-
exec
public static java.lang.String exec(java.lang.String[] cmd, java.lang.String input) throws java.io.IOException, java.lang.InterruptedException
Utility method to execute system commands- Parameters:
cmd
- The command to be executed and its argumentsinput
- The stdin input to be passed to the cmd- Returns:
- stdout or stderr of the command executed
- Throws:
java.io.IOException
java.lang.InterruptedException
-
SpecialURLDecode
public static java.lang.String SpecialURLDecode(java.lang.String s)
-
SpecialDecode
public static byte[] SpecialDecode(java.lang.String s)
-
SpecialEncode
public static java.lang.String SpecialEncode(byte[] data)
-
HexEncode
public static java.lang.String HexEncode(byte[] data)
-
checkHost
public static void checkHost(java.lang.String hostname) throws java.net.UnknownHostException
- Throws:
java.net.UnknownHostException
-
copy
public static void copy(java.lang.String orig, java.lang.String dest) throws java.lang.Exception
- Throws:
java.lang.Exception
-
copyStream
public static void copyStream(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
copyStream
public static void copyStream(java.io.BufferedReader in, java.io.OutputStreamWriter out) throws java.io.IOException
- Throws:
java.io.IOException
-
sortStrings
public static void sortStrings(java.lang.String[] strings)
-
lsDateStr
public static java.lang.String lsDateStr(java.util.Date date)
-
byteArraysAreEqual
public static boolean byteArraysAreEqual(byte[] a, byte[] b)
compares contents two byte arrays returning true if exactly same.
-
stripQuotes
public static java.lang.String stripQuotes(java.lang.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 java.lang.String[] getStringArrayFromVector(java.util.Vector<java.lang.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 java.lang.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 arraychunked
- generate chunked output- Returns:
- base-64 encoded data
-
base64encodeMultiLine
public static java.lang.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 java.lang.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(java.lang.String string)
Converts a Base-64 encoded string into a byte array.- Parameters:
string
- base-64 encoded data- Returns:
- byte array
-
normalizeString
public static java.lang.String normalizeString(java.lang.String string)
Normalize B64 input String- Parameters:
string
- base-64 string- Returns:
- normalized string
-
normalizeString
public static java.lang.String normalizeString(java.lang.String string, java.lang.Boolean keepSpace)
Normalize B64 input String- Parameters:
string
- base-64 stringkeepSpace
- a boolean variable to control whether to keep spaces or not- Returns:
- normalized string
-
-