List of utility methods to do InputStream Read Bytes
byte[] | readBytes(InputStream in) Reads all bytes from the supplied input stream and returns them as a byte array. ByteArrayOutputStream out = new ByteArrayOutputStream(4096); transfer(in, out); return out.toByteArray(); |
byte[] | readBytes(InputStream in, boolean forceClose) read Bytes InputStream is = new BufferedInputStream(in, BUFFER_SIZE); ByteArrayOutputStream baos = new ByteArrayOutputStream(BUFFER_SIZE); BufferedOutputStream bos = new BufferedOutputStream(baos, BUFFER_SIZE); try { byte[] buffer = new byte[BUFFER_SIZE]; for (;;) { int len = is.read(buffer); if (len < 0) ... |
int | readBytes(InputStream in, byte[] b) Fill array from stream int l = b.length; int pos = 0; int n; do { n = in.read(b, pos, l); if (n > 0) { pos += n; l -= n; ... |
byte[] | readBytes(InputStream in, byte[] buf, int length) read Bytes if (in.read(buf, 0, length) != length) { throw new EOFException(); return buf; |
byte[] | readBytes(InputStream in, byte[] buffer) read Bytes ByteArrayOutputStream out = new ByteArrayOutputStream(); int read; while (0 <= (read = in.read(buffer))) { out.write(buffer, 0, read); return out.toByteArray(); |
void | readBytes(InputStream in, byte[] buffer, int maxBytesAtOnce) Read a number of bytes from an InputStream into the given byte array. if (buffer == null) { throw new NullPointerException("The byte buffer for reading from InputStream must not be null!"); int pos = 0; while (pos < buffer.length) { int diff = in.read(buffer, pos, Math.min(buffer.length - pos, Math.max(1, maxBytesAtOnce))); if (diff < 0) { throw new IOException( ... |
int | readBytes(InputStream in, byte[] data, int offset, int length) read Bytes if (length < 0) throw new IOException( "This method just for reading bytes of a expected length from stream.The param length must >=0"); if (length == 0) return 0; if (offset + length > data.length) { throw new IOException("the container byte[] does not enough for the expected length."); int left = length; int off = offset; while (left > 0) { int n; n = in.read(data, off, left); if (n == -1) break; left -= n; off += n; return off - offset; |
byte[] | readBytes(InputStream in, int bufferSize, boolean forceClose) read Bytes ByteArrayOutputStream baos = new ByteArrayOutputStream(bufferSize); copyInToOut(in, baos, bufferSize, forceClose); return baos.toByteArray(); |
void | readBytes(InputStream in, int bytesToRead, byte[] buffer, int bufferOffset) Reads bytesToRead bytes from the stream. int bytesRead = 0; int read; do { read = in.read(buffer, bufferOffset + bytesRead, bytesToRead); bytesRead += read; bytesToRead -= read; } while ((bytesToRead > 0) && (read > 0)); |
byte[] | readBytes(InputStream in, int expectedBytes, long timeoutMs) Read expectedBytes from an input stream and time out if no change on the input stream for more than timeoutMs. Bytes are read from the input stream as they become available. byte[] bytes = new byte[expectedBytes]; int pos = 0; long lastTimeAvailable = System.currentTimeMillis(); do { int avail = in.available(); if (avail > 0) { int btsRead = in.read(bytes, pos, Math.min(avail, expectedBytes - pos)); pos += btsRead; ... |