/* * Indicates whether this reader is ready to be read without blocking. If * the result is {@code true}, the next {@code read()} will not block. If * the result is {@code false}, this reader may or may not block when * {@code read()} is sent. * * @return {@code true} if this reader will not block when {@code read()} * is called, {@code false} if unknown or blocking will occur. * @throws IOException * if the reader is closed or some other I/O error occurs. */ public override bool ready() //throws IOException { lock (lockJ) { return(inJ.ready()); } }
/* * Reads at most {@code length} characters from this reader and stores them * at {@code offset} in the character array {@code buffer}. Returns the * number of characters actually read or -1 if the end of the source reader * has been reached. If all the buffered characters have been used, a mark * has not been set and the requested number of characters is larger than * this readers buffer size, BufferedReader bypasses the buffer and simply * places the results directly into {@code buffer}. * * @param buffer * the character array to store the characters read. * @param offset * the initial position in {@code buffer} to store the bytes read * from this reader. * @param length * the maximum number of characters to read, must be * non-negative. * @return number of characters read or -1 if the end of the source reader * has been reached. * @throws IndexOutOfBoundsException * if {@code offset < 0} or {@code length < 0}, or if * {@code offset + length} is greater than the size of * {@code buffer}. * @throws IOException * if this reader is closed or some other I/O error occurs. */ public override int read(char[] buffer, int offset, int length) //throws IOException { lock (lockJ) { if (isClosed()) { throw new IOException(MESSAGE_READER_IS_CLOSED); //$NON-NLS-1$ } if (offset < 0 || offset > buffer.Length - length || length < 0) { throw new java.lang.IndexOutOfBoundsException(); } int outstanding = length; while (outstanding > 0) { /* * If there are bytes in the buffer, grab those first. */ int available = end - pos; if (available > 0) { int count = available >= outstanding ? outstanding : available; java.lang.SystemJ.arraycopy(buf, pos, buffer, offset, count); pos += count; offset += count; outstanding -= count; } /* * Before attempting to read from the underlying stream, make * sure we really, really want to. We won't bother if we're * done, or if we've already got some bytes and reading from the * underlying stream would block. */ if (outstanding == 0 || (outstanding < length && !inJ.ready())) { break; } // assert(pos == end); /* * If we're unmarked and the requested size is greater than our * buffer, read the bytes directly into the caller's buffer. We * don't read into smaller buffers because that could result in * a many reads. */ if ((markJ == -1 || (pos - markJ >= markLimit)) && outstanding >= buf.Length) { int count = inJ.read(buffer, offset, outstanding); if (count > 0) { offset += count; outstanding -= count; markJ = -1; } break; // assume the source stream gave us all that it could } if (fillBuf() == -1) { break; // source is exhausted } } int count2 = length - outstanding; return((count2 > 0 || count2 == length) ? count2 : -1); } }