1 /*
2 * Copyright (c) 1996, 2013, 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
280 if ((off < 0) || (off > cbuf.length) || (len < 0) ||
281 ((off + len) > cbuf.length) || ((off + len) < 0)) {
282 throw new IndexOutOfBoundsException();
283 } else if (len == 0) {
284 return 0;
285 }
286
287 int n = read1(cbuf, off, len);
288 if (n <= 0) return n;
289 while ((n < len) && in.ready()) {
290 int n1 = read1(cbuf, off + n, len - n);
291 if (n1 <= 0) break;
292 n += n1;
293 }
294 return n;
295 }
296 }
297
298 /**
299 * Reads a line of text. A line is considered to be terminated by any one
300 * of a line feed ('\n'), a carriage return ('\r'), or a carriage return
301 * followed immediately by a linefeed.
302 *
303 * @param ignoreLF If true, the next '\n' will be skipped
304 *
305 * @return A String containing the contents of the line, not including
306 * any line-termination characters, or null if the end of the
307 * stream has been reached
308 *
309 * @see java.io.LineNumberReader#readLine()
310 *
311 * @exception IOException If an I/O error occurs
312 */
313 String readLine(boolean ignoreLF) throws IOException {
314 StringBuffer s = null;
315 int startChar;
316
317 synchronized (lock) {
318 ensureOpen();
319 boolean omitLF = ignoreLF || skipLF;
320
321 bufferLoop:
322 for (;;) {
323
324 if (nextChar >= nChars)
325 fill();
326 if (nextChar >= nChars) { /* EOF */
327 if (s != null && s.length() > 0)
|
1 /*
2 * Copyright (c) 1996, 2017, 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
280 if ((off < 0) || (off > cbuf.length) || (len < 0) ||
281 ((off + len) > cbuf.length) || ((off + len) < 0)) {
282 throw new IndexOutOfBoundsException();
283 } else if (len == 0) {
284 return 0;
285 }
286
287 int n = read1(cbuf, off, len);
288 if (n <= 0) return n;
289 while ((n < len) && in.ready()) {
290 int n1 = read1(cbuf, off + n, len - n);
291 if (n1 <= 0) break;
292 n += n1;
293 }
294 return n;
295 }
296 }
297
298 /**
299 * Reads a line of text. A line is considered to be terminated by any one
300 * of a line feed ('\n'), a carriage return ('\r'), a carriage return
301 * followed immediately by a line feed, or by reaching the end-of-file
302 * (EOF).
303 *
304 * @param ignoreLF If true, the next '\n' will be skipped
305 *
306 * @return A String containing the contents of the line, not including
307 * any line-termination characters, or null if the end of the
308 * stream has been reached without reading any characters
309 *
310 * @see java.io.LineNumberReader#readLine()
311 *
312 * @exception IOException If an I/O error occurs
313 */
314 String readLine(boolean ignoreLF) throws IOException {
315 StringBuffer s = null;
316 int startChar;
317
318 synchronized (lock) {
319 ensureOpen();
320 boolean omitLF = ignoreLF || skipLF;
321
322 bufferLoop:
323 for (;;) {
324
325 if (nextChar >= nChars)
326 fill();
327 if (nextChar >= nChars) { /* EOF */
328 if (s != null && s.length() > 0)
|