@Override public int read() throws IOException { if (noMoreCharacters()) return -1; avail--; readBytes++; return buffer[pos++] & 0xFF; }
@Override public int read(final byte b[], final int offset, final int length) throws IOException { if (length <= avail) { System.arraycopy(buffer, pos, b, offset, length); pos += length; avail -= length; readBytes += length; return length; } final int head = avail; System.arraycopy(buffer, pos, b, offset, head); pos = avail = 0; readBytes += head; if (length > buffer.length) { // We read directly into the destination final int result = is.read(b, offset + head, length - head); if (result > 0) readBytes += result; return result < 0 ? (head == 0 ? -1 : head) : result + head; } if (noMoreCharacters()) return head == 0 ? -1 : head; final int toRead = Math.min(length - head, avail); readBytes += toRead; System.arraycopy(buffer, 0, b, offset + head, toRead); pos = toRead; avail -= toRead; // Note that head >= 0, and necessarily toRead > 0 return toRead + head; }
ByteArrays.ensureOffsetLength(array ,off, len); if (len == 0) return 0; // 0-length reads always return 0 if (noMoreCharacters()) return -1; int i, k = 0, remaining = len, read = 0; // The number of bytes still to be read for(;;) { if (noMoreCharacters()) { else if (noMoreCharacters()) { readBytes += read; return read;