This should do it:
InputStream is = process.getInputStream();
String content = CharStreams.toString(new InputStreamReader(is, Charsets.UTF_8));
is.close();
And here is a real life example of the complete usage:
HttpURLConnection connection = null;
URL url;
InputStream is = null;
try {
url = new URL("https://graph.facebook.com/oauth/access_token?client_id=" + appId + "&client_secret=" + appSecret + "&grant_type=client_credentials");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("accept-encoding", "gzip");
is = connection.getInputStream();
String content = CharStreams.toString(new InputStreamReader(is, Charsets.UTF_8));
String[] tokens = content.split("=");
System.out.println(tokens[1]);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (is != null) try {
is.close();
} catch (IOException e) {}
connection.disconnect();
}
I know this insn't really in question, but for comparison sake he is how you'd do it with IOUtils - which IMO is a bit cleaner:
HttpURLConnection connection = null;
URL url;
InputStream is = null;
try {
url = new URL("https://graph.facebook.com/oauth/access_token?client_id=" + appId + "&client_secret=" + appSecret + "&grant_type=client_credentials");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("accept-encoding", "gzip");
is = connection.getInputStream();
String value = IOUtils.toString(is);
if (!Strings.isNullOrEmpty(value)) {
String[] splits = value.split("=");
System.out.println(splits[1]);
}
} catch (IOException e) {
} finally {
IOUtils.closeQuietly(is);
connection.disconnect();
}