List of utility methods to do InputStream Read by Charset
String | streamToString(final InputStream is, final Charset charset) stream To String ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) != -1) { bos.write(buffer, 0, length); return bos.toString(charset.name()); |
String | streamToString(InputStream inputStream, Charset encoding) stream To String final int bufferSize = 1024; final char[] buffer = new char[bufferSize]; final StringBuilder out = new StringBuilder(); Reader in = new InputStreamReader(inputStream, encoding); for (;;) { int rsz = in.read(buffer, 0, buffer.length); if (rsz < 0) break; ... |
String | stringFromStream(InputStream in, Charset cs) string From Stream char[] buf = new char[256]; StringBuffer result = new StringBuffer(); Reader cis = new InputStreamReader(in); int read = 0; while ((read = cis.read(buf, 0, buf.length)) > 0) { result.append(buf, 0, read); in.close(); ... |
InputStream | toInputStream(final String string, final Charset charset) Build an input stream from the specified string in the encoding specified. return new ByteArrayInputStream(string.getBytes(charset)); |
InputStream | toInputStream(String input, Charset charset) Convert the given string as an input stream that contains the string using the specified charset. return (input != null && charset != null) ? new ByteArrayInputStream(input.getBytes(charset)) : null; |
InputStream | toInputStream(String input, Charset cs) to Input Stream return new ByteArrayInputStream(input.getBytes(cs)); |
String | toString(final InputStream input, final Charset encoding) to String return toString(new InputStreamReader(input, encoding)); |
String | toString(InputStream in, Charset charset) to String return toString(new InputStreamReader(in, charset)); |
String | toString(InputStream in, Charset charset) to String ByteArrayOutputStream bais = new ByteArrayOutputStream(DEFAULT_BUFFER_SIZE); copy(in, bais, charset); return new String(bais.toByteArray()); |
String | toString(InputStream in, Charset charset) to String StringBuilder sb = new StringBuilder(); BufferedReader br = new BufferedReader(new InputStreamReader(in, charset)); try { String str = null; while (null != (str = br.readLine())) { sb.append(str).append(System.getProperty("line.separator")); } catch (IOException e) { ... |