Path: blob/master/src/java.base/share/classes/java/nio/ByteOrder.java
41152 views
/*1* Copyright (c) 2000, 2013, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.nio;2627import jdk.internal.misc.Unsafe;2829/**30* A typesafe enumeration for byte orders.31*32* @author Mark Reinhold33* @author JSR-51 Expert Group34* @since 1.435*/3637public final class ByteOrder {3839private String name;4041private ByteOrder(String name) {42this.name = name;43}4445/**46* Constant denoting big-endian byte order. In this order, the bytes of a47* multibyte value are ordered from most significant to least significant.48*/49public static final ByteOrder BIG_ENDIAN50= new ByteOrder("BIG_ENDIAN");5152/**53* Constant denoting little-endian byte order. In this order, the bytes of54* a multibyte value are ordered from least significant to most55* significant.56*/57public static final ByteOrder LITTLE_ENDIAN58= new ByteOrder("LITTLE_ENDIAN");5960// Retrieve the native byte order. It's used early during bootstrap, and61// must be initialized after BIG_ENDIAN and LITTLE_ENDIAN.62private static final ByteOrder NATIVE_ORDER63= Unsafe.getUnsafe().isBigEndian()64? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;6566/**67* Retrieves the native byte order of the underlying platform.68*69* <p> This method is defined so that performance-sensitive Java code can70* allocate direct buffers with the same byte order as the hardware.71* Native code libraries are often more efficient when such buffers are72* used. </p>73*74* @return The native byte order of the hardware upon which this Java75* virtual machine is running76*/77public static ByteOrder nativeOrder() {78return NATIVE_ORDER;79}8081/**82* Constructs a string describing this object.83*84* <p> This method returns the string85* {@code "BIG_ENDIAN"} for {@link #BIG_ENDIAN} and86* {@code "LITTLE_ENDIAN"} for {@link #LITTLE_ENDIAN}.87*88* @return The specified string89*/90public String toString() {91return name;92}9394}959697