Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/Reader/Skip.java
41149 views
1
/*
2
* Copyright (c) 1998, 2021, 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 4134311 8247918
26
* @summary Test if skip works correctly
27
* @run testng Skip
28
*/
29
30
import java.io.CharArrayReader;
31
import java.io.File;
32
import java.io.FileReader;
33
import java.io.IOException;
34
import java.io.LineNumberReader;
35
import java.io.PushbackReader;
36
import java.io.RandomAccessFile;
37
import java.io.Reader;
38
import java.io.StringReader;
39
40
import org.testng.Assert;
41
import org.testng.annotations.DataProvider;
42
import org.testng.annotations.Test;
43
44
public class Skip {
45
private static String FILENAME =
46
System.getProperty("test.src", ".") + File.separator + "SkipInput.txt";
47
private static File file = new File(FILENAME);
48
49
@Test
50
public void skip() throws IOException {
51
try (FileReader fr = new FileReader(file)) {
52
long nchars = 8200;
53
long actual = fr.skip(nchars);
54
55
Assert.assertFalse(actual > nchars,
56
"Should skip " + nchars + ", but skipped " +actual+" chars");
57
}
58
}
59
60
@DataProvider(name = "readers")
61
public Object[][] getReaders() throws IOException {
62
return new Object[][] {
63
{new LineNumberReader(new FileReader(file))},
64
{new CharArrayReader(new char[] {27})},
65
{new PushbackReader(new FileReader(file))},
66
{new FileReader(file)},
67
{new StringReader(new String(new byte[] {(byte)42}))}
68
};
69
}
70
71
@Test(dataProvider = "readers")
72
public void eof(Reader r) throws IOException {
73
r.skip(Long.MAX_VALUE);
74
Assert.assertEquals(r.skip(1), 0);
75
Assert.assertEquals(r.read(), -1);
76
}
77
78
@DataProvider(name = "skipIAE")
79
public Object[][] getSkipIAEs() throws IOException {
80
return new Object[][] {
81
{new LineNumberReader(new FileReader(file))},
82
{new PushbackReader(new FileReader(file))},
83
{new FileReader(file)}
84
};
85
}
86
87
@Test(dataProvider = "skipIAE", expectedExceptions = IllegalArgumentException.class)
88
public void testThrowsIAE(Reader r) throws IOException {
89
r.skip(-1);
90
}
91
92
@DataProvider(name = "skipNoIAE")
93
public Object[][] getSkipNoIAEs() throws IOException {
94
return new Object[][] {
95
{new CharArrayReader(new char[] {27})},
96
{new StringReader(new String(new byte[] {(byte)42}))}
97
};
98
}
99
100
@Test(dataProvider = "skipNoIAE")
101
public void testNoIAE(Reader r) throws IOException {
102
r.skip(-1);
103
}
104
}
105
106