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.