Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/nio/Buffer/Order.java
38813 views
/*1* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @summary Unit test for X-Buffer.order methods25*/2627import java.io.*;28import java.nio.*;293031public class Order {3233static final ByteOrder be = ByteOrder.BIG_ENDIAN;34static final ByteOrder le = ByteOrder.LITTLE_ENDIAN;35static final ByteOrder nord = ByteOrder.nativeOrder();3637static void ck(ByteOrder ord, ByteOrder expected) {38if (ord != expected)39throw new RuntimeException("Got " + ord40+ ", expected " + expected);41}4243static void ckViews(ByteBuffer bb, ByteOrder ord) {44ck(bb.asCharBuffer().order(), bb.order());45ck(bb.asIntBuffer().order(), bb.order());46ck(bb.asLongBuffer().order(), bb.order());47ck(bb.asFloatBuffer().order(), bb.order());48ck(bb.asDoubleBuffer().order(), bb.order());49}5051static void ckByteBuffer(ByteBuffer bb) {52ckViews(bb, bb.order());53bb.order(be);54ckViews(bb, be);55bb.order(le);56ckViews(bb, le);57}5859public static void main(String args[]) throws Exception {6061ck(ByteBuffer.allocate(10).order(), be);62ck(ByteBuffer.allocateDirect(10).order(), be);63ck(ByteBuffer.allocate(10).order(be).order(), be);64ck(ByteBuffer.allocate(10).order(le).order(), le);6566ckByteBuffer(ByteBuffer.allocate(10));67ckByteBuffer(ByteBuffer.allocateDirect(10));6869}7071}727374