-
public final class ShellUtilsSome handy utility methods that are used in
{@code libsu}.These methods are for internal use. I personally find them pretty handy, so I gathered them here. However, since these are meant to be used internally, they are not stable APIs. I would change them without too much consideration if needed. Also, these methods are not well tested for public usage, many might not handle some edge cases correctly. You have been warned!!
-
-
Method Summary
Modifier and Type Method Description static booleanisValidOutput(List<String> out)Test whether the list is {@code null}or empty or all elements are empty strings.static StringfastCmd(Array<String> cmds)Run commands with the main shell and get a single line output. static StringfastCmd(Shell shell, Array<String> cmds)Run commands and get a single line output. static booleanfastCmdResult(Array<String> cmds)Run commands with the main shell and return whether exits with 0 (success). static booleanfastCmdResult(Shell shell, Array<String> cmds)Run commands and return whether exits with 0 (success). static booleanonMainThread()Check if current thread is main thread. static voidcleanInputStream(InputStream in)Discard all data currently available in an InputStream. static StringescapedString(String s)Format string to quoted and escaped string suitable for shell commands. static longgcd(long u, long v)Get the greatest common divisor of 2 integers with binary algorithm. -
-
Method Detail
-
isValidOutput
static boolean isValidOutput(List<String> out)
Test whether the list is
{@code null}or empty or all elements are empty strings.- Parameters:
out- the output of a shell command.
-
fastCmd
@NonNull() static String fastCmd(Array<String> cmds)
Run commands with the main shell and get a single line output.
- Parameters:
cmds- the commands.
-
fastCmd
@NonNull() static String fastCmd(Shell shell, Array<String> cmds)
Run commands and get a single line output.
- Parameters:
shell- a shell instance.cmds- the commands.
-
fastCmdResult
static boolean fastCmdResult(Array<String> cmds)
Run commands with the main shell and return whether exits with 0 (success).
- Parameters:
cmds- the commands.
-
fastCmdResult
static boolean fastCmdResult(Shell shell, Array<String> cmds)
Run commands and return whether exits with 0 (success).
- Parameters:
shell- a shell instance.cmds- the commands.
-
onMainThread
static boolean onMainThread()
Check if current thread is main thread.
-
cleanInputStream
static void cleanInputStream(InputStream in)
Discard all data currently available in an InputStream.
- Parameters:
in- the InputStream to be cleaned.
-
escapedString
static String escapedString(String s)
Format string to quoted and escaped string suitable for shell commands.
- Parameters:
s- the string to be formatted.
-
gcd
static long gcd(long u, long v)
Get the greatest common divisor of 2 integers with binary algorithm.
- Parameters:
u- an integer.v- an integer.
-
-
-
-