Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/InputStreamReader/ReadCharBuffer.java
41149 views
1
/*
2
* Copyright (c) 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
/*
25
* @test
26
* @bug 4926314
27
* @summary Test for InputStreamReader#read(CharBuffer).
28
* @run testng ReadCharBuffer
29
*/
30
31
import org.testng.annotations.DataProvider;
32
import org.testng.annotations.Test;
33
34
35
import java.io.ByteArrayInputStream;
36
import java.io.IOException;
37
import java.io.InputStreamReader;
38
import java.io.Reader;
39
import java.nio.ByteBuffer;
40
import java.nio.CharBuffer;
41
import java.util.Arrays;
42
43
import static java.nio.charset.StandardCharsets.US_ASCII;
44
import static org.testng.Assert.assertEquals;
45
46
public class ReadCharBuffer {
47
48
private static final int BUFFER_SIZE = 24;
49
50
@DataProvider(name = "buffers")
51
public Object[][] createBuffers() {
52
// test both on-heap and off-heap buffers as they make use different code paths
53
return new Object[][]{
54
new Object[]{CharBuffer.allocate(BUFFER_SIZE)},
55
new Object[]{ByteBuffer.allocateDirect(BUFFER_SIZE * 2).asCharBuffer()}
56
};
57
}
58
59
@Test(dataProvider = "buffers")
60
public void read(CharBuffer buffer) throws IOException {
61
fillBuffer(buffer);
62
63
try (Reader reader = new InputStreamReader(new ByteArrayInputStream("ABCDEFGHIJKLMNOPQRTUVWXYZ".getBytes(US_ASCII)), US_ASCII)) {
64
buffer.limit(7);
65
buffer.position(1);
66
assertEquals(reader.read(buffer), 6);
67
assertEquals(buffer.position(), 7);
68
assertEquals(buffer.limit(), 7);
69
70
buffer.limit(16);
71
buffer.position(8);
72
assertEquals(reader.read(buffer), 8);
73
assertEquals(buffer.position(), 16);
74
assertEquals(buffer.limit(), 16);
75
}
76
77
buffer.clear();
78
assertEquals(buffer.toString(), "xABCDEFxGHIJKLMNxxxxxxxx");
79
}
80
81
private void fillBuffer(CharBuffer buffer) {
82
char[] filler = new char[BUFFER_SIZE];
83
Arrays.fill(filler, 'x');
84
buffer.put(filler);
85
buffer.clear();
86
}
87
88
}
89
90