Package com.topjohnwu.superuser
Class ShellUtils
java.lang.Object
com.topjohnwu.superuser.ShellUtils
Some handy utility methods that are used in 
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 SummaryModifier and TypeMethodDescriptionstatic voidDiscard all data currently available in anInputStream.static StringFormat string to quoted and escaped string suitable for shell commands.static StringRun commands and get a single line output.static StringRun commands with the main shell and get a single line output.static booleanfastCmdResult(Shell shell, String... cmds) Run commands and return whether exits with 0 (success).static booleanfastCmdResult(String... cmds) Run commands with the main shell and return whether exits with 0 (success).static longgcd(long u, long v) Get the greatest common divisor of 2 integers with binary algorithm.static booleanisValidOutput(List<String> out) Test whether the list isnullor empty or all elements are empty strings.static booleanCheck if current thread is main thread.
- 
Method Details- 
isValidOutputTest whether the list isnullor empty or all elements are empty strings.- Parameters:
- out- the output of a shell command.
- Returns:
- falseif the list is- nullor empty or all elements are empty strings.
 
- 
fastCmdRun commands with the main shell and get a single line output.- Parameters:
- cmds- the commands.
- Returns:
- the last line of the output of the command, empty string if no output is available.
 
- 
fastCmdRun commands and get a single line output.- Parameters:
- shell- a shell instance.
- cmds- the commands.
- Returns:
- the last line of the output of the command, empty string if no output is available.
 
- 
fastCmdResultRun commands with the main shell and return whether exits with 0 (success).- Parameters:
- cmds- the commands.
- Returns:
- trueif the commands succeed.
 
- 
fastCmdResultRun commands and return whether exits with 0 (success).- Parameters:
- shell- a shell instance.
- cmds- the commands.
- Returns:
- trueif the commands succeed.
 
- 
onMainThreadpublic static boolean onMainThread()Check if current thread is main thread.- Returns:
- trueif the current thread is the main thread.
 
- 
cleanInputStreamDiscard all data currently available in anInputStream.- Parameters:
- in- the- InputStreamto be cleaned.
 
- 
escapedStringFormat string to quoted and escaped string suitable for shell commands.- Parameters:
- s- the string to be formatted.
- Returns:
- the formatted string.
 
- 
gcdpublic 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.
- Returns:
- the greatest common divisor.
 
 
-