Created
November 18, 2014 12:12
-
-
Save ognian-/98d07c6654615aaea1bf to your computer and use it in GitHub Desktop.
Convert UTF-8 InputStream to String
This file contains 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
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