99 */
100 public int read() throws IOException {
101 synchronized (lock) {
102 ensureOpen();
103 if (pos >= count)
104 return -1;
105 else
106 return buf[pos++];
107 }
108 }
109
110 /**
111 * Reads characters into a portion of an array.
112 * @param b Destination buffer
113 * @param off Offset at which to start storing characters
114 * @param len Maximum number of characters to read
115 * @return The actual number of characters read, or -1 if
116 * the end of the stream has been reached
117 *
118 * @exception IOException If an I/O error occurs
119 */
120 public int read(char b[], int off, int len) throws IOException {
121 synchronized (lock) {
122 ensureOpen();
123 if ((off < 0) || (off > b.length) || (len < 0) ||
124 ((off + len) > b.length) || ((off + len) < 0)) {
125 throw new IndexOutOfBoundsException();
126 } else if (len == 0) {
127 return 0;
128 }
129
130 if (pos >= count) {
131 return -1;
132 }
133 if (pos + len > count) {
134 len = count - pos;
135 }
136 if (len <= 0) {
137 return 0;
138 }
|
99 */
100 public int read() throws IOException {
101 synchronized (lock) {
102 ensureOpen();
103 if (pos >= count)
104 return -1;
105 else
106 return buf[pos++];
107 }
108 }
109
110 /**
111 * Reads characters into a portion of an array.
112 * @param b Destination buffer
113 * @param off Offset at which to start storing characters
114 * @param len Maximum number of characters to read
115 * @return The actual number of characters read, or -1 if
116 * the end of the stream has been reached
117 *
118 * @exception IOException If an I/O error occurs
119 * @exception IndexOutOfBoundsException {@inheritDoc}
120 */
121 public int read(char b[], int off, int len) throws IOException {
122 synchronized (lock) {
123 ensureOpen();
124 if ((off < 0) || (off > b.length) || (len < 0) ||
125 ((off + len) > b.length) || ((off + len) < 0)) {
126 throw new IndexOutOfBoundsException();
127 } else if (len == 0) {
128 return 0;
129 }
130
131 if (pos >= count) {
132 return -1;
133 }
134 if (pos + len > count) {
135 len = count - pos;
136 }
137 if (len <= 0) {
138 return 0;
139 }
|