Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

1gravity commented Feb 11, 2016

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

@drjasonharrison

This comment has been minimized.

Copy link

drjasonharrison commented Jan 18, 2017

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
You can’t perform that action at this time.