85 synchronized (lock) {
86 ensureOpen();
87 if (pos < buf.length)
88 return buf[pos++];
89 else
90 return super.read();
91 }
92 }
93
94 /**
95 * Reads characters into a portion of an array.
96 *
97 * @param cbuf Destination buffer
98 * @param off Offset at which to start writing characters
99 * @param len Maximum number of characters to read
100 *
101 * @return The number of characters read, or -1 if the end of the
102 * stream has been reached
103 *
104 * @exception IOException If an I/O error occurs
105 */
106 public int read(char cbuf[], int off, int len) throws IOException {
107 synchronized (lock) {
108 ensureOpen();
109 try {
110 if (len <= 0) {
111 if (len < 0) {
112 throw new IndexOutOfBoundsException();
113 } else if ((off < 0) || (off > cbuf.length)) {
114 throw new IndexOutOfBoundsException();
115 }
116 return 0;
117 }
118 int avail = buf.length - pos;
119 if (avail > 0) {
120 if (len < avail)
121 avail = len;
122 System.arraycopy(buf, pos, cbuf, off, avail);
123 pos += avail;
124 off += avail;
|
85 synchronized (lock) {
86 ensureOpen();
87 if (pos < buf.length)
88 return buf[pos++];
89 else
90 return super.read();
91 }
92 }
93
94 /**
95 * Reads characters into a portion of an array.
96 *
97 * @param cbuf Destination buffer
98 * @param off Offset at which to start writing characters
99 * @param len Maximum number of characters to read
100 *
101 * @return The number of characters read, or -1 if the end of the
102 * stream has been reached
103 *
104 * @exception IOException If an I/O error occurs
105 * @exception IndexOutOfBoundsException {@inheritDoc}
106 */
107 public int read(char cbuf[], int off, int len) throws IOException {
108 synchronized (lock) {
109 ensureOpen();
110 try {
111 if (len <= 0) {
112 if (len < 0) {
113 throw new IndexOutOfBoundsException();
114 } else if ((off < 0) || (off > cbuf.length)) {
115 throw new IndexOutOfBoundsException();
116 }
117 return 0;
118 }
119 int avail = buf.length - pos;
120 if (avail > 0) {
121 if (len < avail)
122 avail = len;
123 System.arraycopy(buf, pos, cbuf, off, avail);
124 pos += avail;
125 off += avail;
|