Java ByteArrayOutputStream Write readAll(InputStream s)

Here you can find the source of readAll(InputStream s)

Description

read All

License

Open Source License

Declaration

static public byte[] readAll(InputStream s) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    static public byte[] readAll(InputStream s) {
        byte[] temp = new byte[1024];
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        try {/*from   ww w .  j  a va  2 s.  c  om*/
            while (true) {
                int read = s.read(temp, 0, temp.length);
                if (read <= 0)
                    break;
                os.write(temp, 0, read);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return os.toByteArray();
    }
}

Related

  1. readAll(InputStream in)
  2. readAll(InputStream in)
  3. readAll(InputStream in)
  4. readAll(InputStream inputStream)
  5. readAll(InputStream is)
  6. readAll(InputStream stream)
  7. readAllAndClose(InputStream is)
  8. readAllAndKeepOpen(InputStream bytes, int bufferSize)
  9. readAllBinary(InputStream stream)