1/* Licensed to the Apache Software Foundation (ASF) under one or more 2 * contributor license agreements. See the NOTICE file distributed with 3 * this work for additional information regarding copyright ownership. 4 * The ASF licenses this file to You under the Apache License, Version 2.0 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package java.nio; 18 19import org.apache.harmony.luni.platform.Platform; 20 21/** 22 * Defines byte order constants. 23 */ 24public final class ByteOrder { 25 26 /** 27 * This constant represents big endian. 28 */ 29 public static final ByteOrder BIG_ENDIAN = new ByteOrder("BIG_ENDIAN"); //$NON-NLS-1$ 30 31 /** 32 * This constant represents little endian. 33 */ 34 public static final ByteOrder LITTLE_ENDIAN = new ByteOrder("LITTLE_ENDIAN"); //$NON-NLS-1$ 35 36 private static final ByteOrder NATIVE_ORDER; 37 38 static { 39 if (Platform.getMemorySystem().isLittleEndian()) { 40 NATIVE_ORDER = LITTLE_ENDIAN; 41 } else { 42 NATIVE_ORDER = BIG_ENDIAN; 43 } 44 } 45 46 /** 47 * Returns the current platform byte order. 48 * 49 * @return the byte order object, which is either LITTLE_ENDIAN or 50 * BIG_ENDIAN. 51 */ 52 public static ByteOrder nativeOrder() { 53 return NATIVE_ORDER; 54 } 55 56 private final String name; 57 58 private ByteOrder(String name) { 59 super(); 60 this.name = name; 61 } 62 63 /** 64 * Returns a string that describes this object. 65 * 66 * @return "BIG_ENDIAN" for {@link #BIG_ENDIAN ByteOrder.BIG_ENDIAN} 67 * objects, "LITTLE_ENDIAN" for 68 * {@link #LITTLE_ENDIAN ByteOrder.LITTLE_ENDIAN} objects. 69 */ 70 @Override 71 public String toString() { 72 return name; 73 } 74} 75