Skip to content

Instantly share code, notes, and snippets.

@ognian-
Created November 18, 2014 12:12
Show Gist options
  • Save ognian-/98d07c6654615aaea1bf to your computer and use it in GitHub Desktop.
Save ognian-/98d07c6654615aaea1bf to your computer and use it in GitHub Desktop.
Convert UTF-8 InputStream to String
public static String toString(InputStream is) throws IOException {
InputStreamReader isr = null;
try {
isr = new InputStreamReader(is, "UTF-8");
char[] buf = new char[512];
StringBuilder str = new StringBuilder();
int i = 0;
while ( (i = isr.read(buf)) != -1 ) str.append(buf, 0 ,i);
return str.toString();
} finally {
if (isr != null) {
isr.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment