Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/LineNumberReader/MarkSplitCRLF.java
41149 views
1
/*
2
* Copyright (c) 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.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/* @test
25
* @bug 8218280
26
* @summary Make sure marking a line feed within a CRLF sequence works correctly
27
* @run testng MarkSplitCRLF
28
*/
29
30
import java.io.IOException;
31
import java.io.LineNumberReader;
32
import java.io.Reader;
33
import java.io.StringReader;
34
35
import org.testng.annotations.Test;
36
37
import static org.testng.Assert.*;
38
39
public class MarkSplitCRLF {
40
@Test
41
public static void testSpecifiedBufferSize() throws IOException {
42
final String string = "foo\r\nbar";
43
try (Reader reader =
44
new LineNumberReader(new StringReader(string), 5)) {
45
reader.read(); // 'f'
46
reader.read(); // 'o'
47
reader.read(); // 'o'
48
reader.read(); // '\r' -> '\n'
49
reader.mark(1); // mark position of '\n'
50
reader.read(); // 'b'
51
reader.reset(); // reset to '\n' position
52
assertEquals(reader.read(), 'b');
53
assertEquals(reader.read(), 'a');
54
assertEquals(reader.read(), 'r');
55
}
56
}
57
58
@Test
59
public static void testCRNotFollowedByLF() throws IOException {
60
final String string = "foo\rbar";
61
try (Reader reader =
62
new LineNumberReader(new StringReader(string), 5)) {
63
reader.read(); // 'f'
64
reader.read(); // 'o'
65
reader.read(); // 'o'
66
reader.read(); // '\r'
67
reader.mark(1); // mark position of next character
68
reader.read(); // 'b'
69
reader.reset(); // reset to position after '\r'
70
assertEquals(reader.read(), 'b');
71
assertEquals(reader.read(), 'a');
72
assertEquals(reader.read(), 'r');
73
}
74
}
75
76
@Test
77
public static void testDefaultBufferSize() throws IOException {
78
StringBuilder sb = new StringBuilder(8195);
79
for (int i = 0; i < 8190; i++) {
80
char c = (char)i;
81
sb.append(c);
82
}
83
sb.append('\r');
84
sb.append('\n');
85
sb.append('X');
86
sb.append('Y');
87
sb.append('Z');
88
final String string = sb.toString();
89
try (Reader reader = new LineNumberReader(new StringReader(string))) {
90
for (int i = 0; i < 8191; i++) reader.read();
91
reader.mark(1);
92
reader.read();
93
reader.reset();
94
assertEquals(reader.read(), 'X');
95
assertEquals(reader.read(), 'Y');
96
assertEquals(reader.read(), 'Z');
97
}
98
}
99
}
100
101