Last active
August 29, 2015 14:06
-
-
Save orip/2957730757e9246c3cfd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.common.io.CharStreams; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
/** | |
* Zero error checking or recovery. Apologies. | |
* | |
* Requires the READ_LOGS permission. | |
*/ | |
public class ReadingLogcat { | |
public static String getLogcatOutputWithGuava() throws IOException { | |
Process logcat = Runtime.getRuntime().exec("logcat -d"); | |
return CharStreams.toString(new InputStreamReader(logcat.getInputStream())); | |
} | |
public static String getLogcatOutputNoGuava() throws IOException { | |
Process logcat = Runtime.getRuntime().exec("logcat -d"); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(logcat.getInputStream())); | |
StringBuilder result = new StringBuilder(); | |
String line; | |
while ((line = reader.readLine()) != null) { | |
result.append(line); | |
} | |
return result.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment