Skip to content

Instantly share code, notes, and snippets.

@korniltsev
Forked from alexfu/StringUtils.java
Last active August 29, 2015 14:23
Show Gist options
  • Save korniltsev/3a971a930baa3c457996 to your computer and use it in GitHub Desktop.
Save korniltsev/3a971a930baa3c457996 to your computer and use it in GitHub Desktop.
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