1 /*
2 * Copyright (c) 1996, 2011, 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
244 }
245 return n - r;
246 }
247 }
248
249 /**
250 * Mark the present position in the stream. Subsequent calls to reset()
251 * will attempt to reposition the stream to this point, and will also reset
252 * the line number appropriately.
253 *
254 * @param readAheadLimit
255 * Limit on the number of characters that may be read while still
256 * preserving the mark. After reading this many characters,
257 * attempting to reset the stream may fail.
258 *
259 * @throws IOException
260 * If an I/O error occurs
261 */
262 public void mark(int readAheadLimit) throws IOException {
263 synchronized (lock) {
264 super.mark(readAheadLimit);
265 markedLineNumber = lineNumber;
266 markedSkipLF = skipLF;
267 }
268 }
269
270 /**
271 * Reset the stream to the most recent mark.
272 *
273 * @throws IOException
274 * If the stream has not been marked, or if the mark has been
275 * invalidated
276 */
277 public void reset() throws IOException {
278 synchronized (lock) {
279 super.reset();
280 lineNumber = markedLineNumber;
281 skipLF = markedSkipLF;
282 }
283 }
|
1 /*
2 * Copyright (c) 1996, 2019, 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
244 }
245 return n - r;
246 }
247 }
248
249 /**
250 * Mark the present position in the stream. Subsequent calls to reset()
251 * will attempt to reposition the stream to this point, and will also reset
252 * the line number appropriately.
253 *
254 * @param readAheadLimit
255 * Limit on the number of characters that may be read while still
256 * preserving the mark. After reading this many characters,
257 * attempting to reset the stream may fail.
258 *
259 * @throws IOException
260 * If an I/O error occurs
261 */
262 public void mark(int readAheadLimit) throws IOException {
263 synchronized (lock) {
264 // If the most recently read character is '\r', then increment the
265 // read ahead limit as in this case if the next character is '\n',
266 // two characters would actually be read by the next read().
267 if (skipLF)
268 readAheadLimit++;
269 super.mark(readAheadLimit);
270 markedLineNumber = lineNumber;
271 markedSkipLF = skipLF;
272 }
273 }
274
275 /**
276 * Reset the stream to the most recent mark.
277 *
278 * @throws IOException
279 * If the stream has not been marked, or if the mark has been
280 * invalidated
281 */
282 public void reset() throws IOException {
283 synchronized (lock) {
284 super.reset();
285 lineNumber = markedLineNumber;
286 skipLF = markedSkipLF;
287 }
288 }
|