All pastes #245590 Raw Edit

Untitled

public text v1 · immutable
#245590 ·published 2006-11-11 03:53 UTC
rendered paste body
    public static byte[] readAllFromStream(InputStream in) throws IOException {
        int buf = 1024;
        byte[] tmp = new byte[buf];
        byte[] newbuf = new byte[0];
        int read = -1;
        int count = 0;
        while ((read = in.read(tmp)) > -1) {
            count += read;
            byte[] tmp1 = newbuf;
            newbuf = new byte[count];
            if (tmp1.length > 0)
                System.arraycopy(tmp1, 0, newbuf, 0, tmp1.length);
            System.arraycopy(tmp, 0, newbuf, tmp1.length, read);
            tmp = new byte[buf];
        }
        return newbuf;
    }