-
-
Save korniltsev/3a971a930baa3c457996 to your computer and use it in GitHub Desktop.
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
import java.io.ByteArrayOutputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
public class StringUtils { | |
private StringUtils() { /* No op */ } | |
public static String from(InputStream is) { | |
byte[] buffer = new byte[1024]; | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
try { | |
for (int count = is.read(buffer); count != -1; count = is.read(buffer)) { | |
baos.write(buffer, 0, count); | |
} | |
baos.close(); | |
return new String(baos.toByteArray()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment