Java Utililty Methods InputStream Read

List of utility methods to do InputStream Read

Description

The list of methods to do InputStream Read are organized into topic(s).

Method

longgetInputStreamLength(InputStream in)
Get InputStream bytes count without reading
if (in instanceof FileInputStream) {
    return ((FileInputStream) in).getChannel().size();
return in.available();
ReadergetInputStreamReader(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); 
InputStreamReadergetInputStreamReaderAsResource(Class clazz, String fileName)
get Input Stream Reader As Resource
return new InputStreamReader(getInputStreamAsResource(clazz, fileName));
StringBuffergetInputStreamString(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();
...
voidinputStreamReadBytesUntil(int endInd, InputStream is, byte[] buf, int off)
input Stream Read Bytes Until
while (off < endInd)
    off += is.read(buf, off, endInd - off);
ListinputStreamToList(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) {
...