/** * Nonblocking read. Reads bytes into specified buffer * * @param b * buffer to read into * * @return number of bytes read, 0 if the buffer is empty */ public int read(byte[] b) { int count = 0; while (count < b.length) { int res = read(); if (res >= 0) b[count++] = (byte) res; else break; } return count; }