/** @see InputStream#read() * @throws EOFException if EOF is reached. */ @Override public int read() throws IOException { return getBuffer().get() & 0xff; }
/** @see InputStream#read() * @throws EOFException if EOF is reached. */ @Override public int read() throws IOException { return getBuffer().get() & 0xff; }
/** @see InputStream#read(byte[], int, int) * @throws EOFException if EOF is reached before reading all the bytes. */ @Override public int read(byte[] b, int off, int len) throws IOException { if (len == 0) return 0; ByteBuffer buffer = getBuffer(); int remaining = buffer.remaining(); if (len > remaining) { buffer.get(b, off, remaining); return remaining; } else { buffer.get(b, off, len); return len; } }
/** @see InputStream#read(byte[], int, int) * @throws EOFException if EOF is reached before reading all the bytes. */ @Override public int read(byte[] b, int off, int len) throws IOException { if (len == 0) return 0; ByteBuffer buffer = getBuffer(); int remaining = buffer.remaining(); if (len > remaining) { buffer.get(b, off, remaining); return remaining; } else { buffer.get(b, off, len); return len; } }
/** Read a buffer from the input without copying, if possible. * @throws EOFException if EOF is reached before reading all the bytes. */ public ByteBuffer readBuffer(int length) throws IOException { if (length == 0) return ByteBuffer.allocate(0); ByteBuffer buffer = getBuffer(); if (buffer.remaining() == length) { // can return current as-is? current++; return buffer; // return w/o copying } // punt: allocate a new buffer & copy into it ByteBuffer result = ByteBuffer.allocate(length); int start = 0; while (start < length) start += read(result.array(), start, length-start); return result; }
/** Read a buffer from the input without copying, if possible. * @throws EOFException if EOF is reached before reading all the bytes. */ public ByteBuffer readBuffer(int length) throws IOException { if (length == 0) return ByteBuffer.allocate(0); ByteBuffer buffer = getBuffer(); if (buffer.remaining() == length) { // can return current as-is? current++; return buffer; // return w/o copying } // punt: allocate a new buffer & copy into it ByteBuffer result = ByteBuffer.allocate(length); int start = 0; while (start < length) start += read(result.array(), start, length-start); return result; }
/** @see InputStream#read() * @throws EOFException if EOF is reached. */ @Override public int read() throws IOException { return getBuffer().get() & 0xff; }
/** @see InputStream#read() * @throws EOFException if EOF is reached. */ @Override public int read() throws IOException { return getBuffer().get() & 0xff; }
/** @see InputStream#read(byte[], int, int) * @throws EOFException if EOF is reached before reading all the bytes. */ @Override public int read(byte[] b, int off, int len) throws IOException { if (len == 0) return 0; ByteBuffer buffer = getBuffer(); int remaining = buffer.remaining(); if (len > remaining) { buffer.get(b, off, remaining); return remaining; } else { buffer.get(b, off, len); return len; } }
/** @see InputStream#read(byte[], int, int) * @throws EOFException if EOF is reached before reading all the bytes. */ @Override public int read(byte[] b, int off, int len) throws IOException { if (len == 0) return 0; ByteBuffer buffer = getBuffer(); int remaining = buffer.remaining(); if (len > remaining) { buffer.get(b, off, remaining); return remaining; } else { buffer.get(b, off, len); return len; } }
/** Read a buffer from the input without copying, if possible. * @throws EOFException if EOF is reached before reading all the bytes. */ public ByteBuffer readBuffer(int length) throws IOException { if (length == 0) return ByteBuffer.allocate(0); ByteBuffer buffer = getBuffer(); if (buffer.remaining() == length) { // can return current as-is? current++; return buffer; // return w/o copying } // punt: allocate a new buffer & copy into it ByteBuffer result = ByteBuffer.allocate(length); int start = 0; while (start < length) start += read(result.array(), start, length-start); return result; }
/** Read a buffer from the input without copying, if possible. * @throws EOFException if EOF is reached before reading all the bytes. */ public ByteBuffer readBuffer(int length) throws IOException { if (length == 0) return ByteBuffer.allocate(0); ByteBuffer buffer = getBuffer(); if (buffer.remaining() == length) { // can return current as-is? current++; return buffer; // return w/o copying } // punt: allocate a new buffer & copy into it ByteBuffer result = ByteBuffer.allocate(length); int start = 0; while (start < length) start += read(result.array(), start, length-start); return result; }