/* * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* @test * @bug 4151072 * @summary Ensure that BufferedReader's methods handle the new line character * following the carriage return correctly after a readLine * operation that resulted in reading a line terminated by a * carriage return (\r).
*/ import java.io.*;
publicclass ReadLine {
publicstaticvoid main(String[] args) throws IOException { // Make sure that the reader does not wait for additional characters to // be read after reading a new line.
BufferedReader reader;
String[][] strings = {
{"CR/LF\r\n", "CR/LF"},
{"LF-Only\n", "LF-Only"},
{"CR-Only\r", "CR-Only"},
{"CR/LF line\r\nMore data", "More data"}
};
// test 0 "CR/LF\r\n" // test 1 "LF-Only\n" // test 2 "CR-Only\r" for (int i = 0; i < 3; i++) {
reader = new BufferedReader(new
BoundedReader(strings[i][0]), strings[i][0].length()); if (!reader.readLine().equals(strings[i][1])) thrownew RuntimeException("Read incorrect text");
}
// Now test the mark and reset operations. Consider two cases. // 1. For lines ending with CR only.
markResetTest("Lot of textual data\rMore textual data\n", "More textual data");
// 2. Now for lines ending with CR/LF
markResetTest("Lot of textual data\r\nMore textual data\n", "More textual data");
// 3. Now for lines ending with LF only
markResetTest("Lot of textual data\nMore textual data\n", "More textual data");
// Need to ensure behavior of read() after a readLine() read of a CR/LF // terminated line. // 1. For lines ending with CR/LF only.
// uses "CR/LF line\r\nMore data"
reader = new BufferedReader(new
BoundedReader(strings[3][0]), strings[3][0].length());
reader.readLine(); if (reader.read() != 'M') thrownew RuntimeException("Read() failed");
// Need to ensure that a read(char[], int, int) following a readLine() // read of a CR/LF terminated line behaves correctly.
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.