01: /* Licensed to the Apache Software Foundation (ASF) under one or more
02: * contributor license agreements. See the NOTICE file distributed with
03: * this work for additional information regarding copyright ownership.
04: * The ASF licenses this file to You under the Apache License, Version 2.0
05: * (the "License"); you may not use this file except in compliance with
06: * the License. You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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:
17: package java.nio;
18:
19: import org.apache.harmony.luni.platform.Platform;
20:
21: /**
22: * Holds byte order constants.
23: *
24: */
25: public final class ByteOrder {
26:
27: /**
28: * This constant represents big endian.
29: */
30: public static final ByteOrder BIG_ENDIAN = new ByteOrder(
31: "BIG_ENDIAN"); //$NON-NLS-1$
32:
33: /**
34: * This constant represents little endian.
35: */
36: public static final ByteOrder LITTLE_ENDIAN = new ByteOrder(
37: "LITTLE_ENDIAN"); //$NON-NLS-1$
38:
39: private static final ByteOrder NATIVE_ORDER;
40:
41: static {
42: if (Platform.getMemorySystem().isLittleEndian()) {
43: NATIVE_ORDER = LITTLE_ENDIAN;
44: } else {
45: NATIVE_ORDER = BIG_ENDIAN;
46: }
47: }
48:
49: /**
50: * Answers the current platform byte order.
51: *
52: * @return the byte order object, which is either identical to LITTLE_ENDIAN
53: * or BIG_ENDIAN.
54: */
55: public static ByteOrder nativeOrder() {
56: return NATIVE_ORDER;
57: }
58:
59: private final String name;
60:
61: private ByteOrder(String name) {
62: super ();
63: this .name = name;
64: }
65:
66: /*
67: * (non-Javadoc)
68: *
69: * @see java.lang.Object#toString()
70: */
71: @Override
72: public String toString() {
73: return name;
74: }
75: }
|