Skip to content

Instantly share code, notes, and snippets.

@XinyueZ
Created October 9, 2015 13:31
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save XinyueZ/440e015b3a1afb692812 to your computer and use it in GitHub Desktop.
Read input-stream without 3rd library anyway
public static String readFromInputStream(InputStream is) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
return builder.toString();
}
@1gravity
Copy link

Explicitly set the encoding or you WILL run into problems sometimes down the line: new InputStreamReader(is, "UTF-8") e.g.

@drjasonharrison
Copy link

This drops line endings, so it does not convert the input data without loss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment