jdk/test/java/nio/Buffer/OrderShort.java
author bpb
Wed, 15 Jul 2015 10:43:07 -0700
changeset 31723 2e16a59cc5cb
child 38321 ff5b89346438
permissions -rw-r--r--
8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN Summary: Refine documentation of allocate*(), wrap(), slice(), duplicate(), asReadOnlyBuffer(), and as{Type}Buffer() to explcitly state the byte order of the created buffer. Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31723
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
     1
/*
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
     4
 *
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
     8
 *
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    13
 * accompanied this code).
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    14
 *
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    18
 *
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    21
 * questions.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    22
 */
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    23
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    24
/* Type-specific source code for unit test
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    25
 *
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    26
 * Regenerate the OrderX classes via genOrder.sh whenever this file changes.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    27
 * We check in the generated source files so that the test tree can be used
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    28
 * independently of the rest of the source tree.
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    29
 */
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    30
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    31
// -- This file was mechanically generated: Do not edit! -- //
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    32
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    33
import java.nio.*;
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    34
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    35
public class OrderShort extends Order {
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    36
    private static void ckShortBuffer(ShortBuffer buf, ByteOrder expected) {
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    37
        ck(buf.asReadOnlyBuffer().order(), expected);
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    38
        ck(buf.duplicate().order(), expected);
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    39
        ck(buf.slice().order(), expected);
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    40
    }
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    41
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    42
    static void ckShortBuffer() {
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    43
        short[] array = new short[LENGTH];
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    44
        ShortBuffer buf = ShortBuffer.wrap(array);
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    45
        ck(buf.order(), nord);
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    46
        ckShortBuffer(buf, nord);
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    47
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    48
        buf = ShortBuffer.wrap(array, LENGTH/2, LENGTH/2);
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    49
        ck(buf.order(), nord);
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    50
        ckShortBuffer(buf, nord);
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    51
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    52
        buf = ShortBuffer.allocate(LENGTH);
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    53
        ck(buf.order(), nord);
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    54
        ckShortBuffer(buf, nord);
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    55
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    56
        ckShortBuffer(ByteBuffer.allocate(LENGTH).asShortBuffer(), be);
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    57
        ckShortBuffer(ByteBuffer.allocateDirect(LENGTH).asShortBuffer(), be);
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    58
    }
2e16a59cc5cb 8065570: (bf spec) ByteBuffer.slice() should make it clear that the initial order is BIG_ENDIAN
bpb
parents:
diff changeset
    59
}