Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/nio/Buffer/Order.java
38813 views
1
/*
2
* Copyright (c) 2001, 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
* @summary Unit test for X-Buffer.order methods
26
*/
27
28
import java.io.*;
29
import java.nio.*;
30
31
32
public class Order {
33
34
static final ByteOrder be = ByteOrder.BIG_ENDIAN;
35
static final ByteOrder le = ByteOrder.LITTLE_ENDIAN;
36
static final ByteOrder nord = ByteOrder.nativeOrder();
37
38
static void ck(ByteOrder ord, ByteOrder expected) {
39
if (ord != expected)
40
throw new RuntimeException("Got " + ord
41
+ ", expected " + expected);
42
}
43
44
static void ckViews(ByteBuffer bb, ByteOrder ord) {
45
ck(bb.asCharBuffer().order(), bb.order());
46
ck(bb.asIntBuffer().order(), bb.order());
47
ck(bb.asLongBuffer().order(), bb.order());
48
ck(bb.asFloatBuffer().order(), bb.order());
49
ck(bb.asDoubleBuffer().order(), bb.order());
50
}
51
52
static void ckByteBuffer(ByteBuffer bb) {
53
ckViews(bb, bb.order());
54
bb.order(be);
55
ckViews(bb, be);
56
bb.order(le);
57
ckViews(bb, le);
58
}
59
60
public static void main(String args[]) throws Exception {
61
62
ck(ByteBuffer.allocate(10).order(), be);
63
ck(ByteBuffer.allocateDirect(10).order(), be);
64
ck(ByteBuffer.allocate(10).order(be).order(), be);
65
ck(ByteBuffer.allocate(10).order(le).order(), le);
66
67
ckByteBuffer(ByteBuffer.allocate(10));
68
ckByteBuffer(ByteBuffer.allocateDirect(10));
69
70
}
71
72
}
73
74