1 /*
2 * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
133 * @param len the maximum number of bytes read.
134 * @return the total number of bytes read into the buffer, or
135 * <code>-1</code> if there is no more data because the end
136 * of the stream has been reached.
137 * @exception NullPointerException If <code>b</code> is <code>null</code>.
138 * @exception IndexOutOfBoundsException If <code>off</code> is negative,
139 * <code>len</code> is negative, or <code>len</code> is greater than
140 * <code>b.length - off</code>
141 * @exception IOException if the first byte cannot be read for any reason
142 * other than end of file, the stream has been closed and the underlying
143 * input stream does not support reading after close, or another I/O
144 * error occurs.
145 * @see java.io.FilterInputStream#in
146 * @see java.io.InputStream#read(byte[], int, int)
147 */
148 public final int read(byte b[], int off, int len) throws IOException {
149 return in.read(b, off, len);
150 }
151
152 /**
153 * See the general contract of the <code>readFully</code>
154 * method of <code>DataInput</code>.
155 * <p>
156 * Bytes
157 * for this operation are read from the contained
158 * input stream.
159 *
160 * @param b the buffer into which the data is read.
161 * @exception EOFException if this input stream reaches the end before
162 * reading all the bytes.
163 * @exception IOException the stream has been closed and the contained
164 * input stream does not support reading after close, or
165 * another I/O error occurs.
166 * @see java.io.FilterInputStream#in
167 */
168 public final void readFully(byte b[]) throws IOException {
169 readFully(b, 0, b.length);
170 }
171
172 /**
173 * See the general contract of the <code>readFully</code>
174 * method of <code>DataInput</code>.
175 * <p>
176 * Bytes
177 * for this operation are read from the contained
178 * input stream.
179 *
180 * @param b the buffer into which the data is read.
181 * @param off the start offset of the data.
182 * @param len the number of bytes to read.
183 * @exception EOFException if this input stream reaches the end before
184 * reading all the bytes.
185 * @exception IOException the stream has been closed and the contained
186 * input stream does not support reading after close, or
187 * another I/O error occurs.
188 * @see java.io.FilterInputStream#in
189 */
190 public final void readFully(byte b[], int off, int len) throws IOException {
191 if (len < 0)
192 throw new IndexOutOfBoundsException();
193 int n = 0;
194 while (n < len) {
195 int count = in.read(b, off + n, len - n);
196 if (count < 0)
197 throw new EOFException();
198 n += count;
199 }
200 }
201
202 /**
|
1 /*
2 * Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
133 * @param len the maximum number of bytes read.
134 * @return the total number of bytes read into the buffer, or
135 * <code>-1</code> if there is no more data because the end
136 * of the stream has been reached.
137 * @exception NullPointerException If <code>b</code> is <code>null</code>.
138 * @exception IndexOutOfBoundsException If <code>off</code> is negative,
139 * <code>len</code> is negative, or <code>len</code> is greater than
140 * <code>b.length - off</code>
141 * @exception IOException if the first byte cannot be read for any reason
142 * other than end of file, the stream has been closed and the underlying
143 * input stream does not support reading after close, or another I/O
144 * error occurs.
145 * @see java.io.FilterInputStream#in
146 * @see java.io.InputStream#read(byte[], int, int)
147 */
148 public final int read(byte b[], int off, int len) throws IOException {
149 return in.read(b, off, len);
150 }
151
152 /**
153 * See the general contract of the {@code readFully}
154 * method of {@code DataInput}.
155 * <p>
156 * Bytes
157 * for this operation are read from the contained
158 * input stream.
159 *
160 * @param b the buffer into which the data is read.
161 * @throws NullPointerException if {@code b} is {@code null}.
162 * @throws EOFException if this input stream reaches the end before
163 * reading all the bytes.
164 * @throws IOException the stream has been closed and the contained
165 * input stream does not support reading after close, or
166 * another I/O error occurs.
167 * @see java.io.FilterInputStream#in
168 */
169 public final void readFully(byte b[]) throws IOException {
170 readFully(b, 0, b.length);
171 }
172
173 /**
174 * See the general contract of the {@code readFully}
175 * method of {@code DataInput}.
176 * <p>
177 * Bytes
178 * for this operation are read from the contained
179 * input stream.
180 *
181 * @param b the buffer into which the data is read.
182 * @param off the start offset in the data array {@code b}.
183 * @param len the number of bytes to read.
184 * @exception NullPointerException if {@code b} is {@code null}.
185 * @exception IndexOutOfBoundsException if {@code off} is negative,
186 * {@code len} is negative, or {@code len} is greater than
187 * {@code b.length - off}.
188 * @exception EOFException if this input stream reaches the end before
189 * reading all the bytes.
190 * @exception IOException the stream has been closed and the contained
191 * input stream does not support reading after close, or
192 * another I/O error occurs.
193 * @see java.io.FilterInputStream#in
194 */
195 public final void readFully(byte b[], int off, int len) throws IOException {
196 if (len < 0)
197 throw new IndexOutOfBoundsException();
198 int n = 0;
199 while (n < len) {
200 int count = in.read(b, off + n, len - n);
201 if (count < 0)
202 throw new EOFException();
203 n += count;
204 }
205 }
206
207 /**
|