List of utility methods to do InputStream Read
long | getInputStreamLength(InputStream in) Get InputStream bytes count without reading if (in instanceof FileInputStream) { return ((FileInputStream) in).getChannel().size(); return in.available(); |
Reader | getInputStreamReader(InputStream in, String charset) Returns a reader for the specified input stream, using specified encoding. try { return new InputStreamReader(in, charset); } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex); |
InputStreamReader | getInputStreamReaderAsResource(Class> clazz, String fileName) get Input Stream Reader As Resource return new InputStreamReader(getInputStreamAsResource(clazz, fileName)); |
StringBuffer | getInputStreamString(final InputStream in) Populate a StringBuffer with the contents of an InputStream StringBuffer out = null; if (in != null) { final BufferedReader reader = new BufferedReader(new InputStreamReader(in)); try { out = new StringBuffer(); String tmp = ""; while ((tmp = reader.readLine()) != null) { out.append(tmp + "\n"); ... |
byte[] | getInputStreamToBytes(InputStream is) get Input Stream To Bytes int read = 0; byte[] bytes = new byte[1024 * 1024 * 2]; ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { while ((read = is.read(bytes)) != -1) bos.write(bytes, 0, read); } catch (IOException e) { e.printStackTrace(); ... |
void | inputStreamReadBytesUntil(int endInd, InputStream is, byte[] buf, int off) input Stream Read Bytes Until while (off < endInd)
off += is.read(buf, off, endInd - off);
|
List | inputStreamToList(InputStream stream) input Stream To List List<String> list = new ArrayList<>(); try { BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); String line; while ((line = reader.readLine()) != null) { list.add(line); } catch (Exception ex) { ... |