1. /*
  2. * @(#)ByteOrder.java 1.12 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.nio;
  8. /**
  9. * A typesafe enumeration for byte orders.
  10. *
  11. * @author Mark Reinhold
  12. * @author JSR-51 Expert Group
  13. * @version 1.12, 03/01/23
  14. * @since 1.4
  15. */
  16. public final class ByteOrder {
  17. private String name;
  18. private ByteOrder(String name) {
  19. this.name = name;
  20. }
  21. /**
  22. * Constant denoting big-endian byte order. In this order, the bytes of a
  23. * multibyte value are ordered from most significant to least significant.
  24. * </p>
  25. */
  26. public static final ByteOrder BIG_ENDIAN
  27. = new ByteOrder("BIG_ENDIAN");
  28. /**
  29. * Constant denoting little-endian byte order. In this order, the bytes of
  30. * a multibyte value are ordered from least significant to most
  31. * significant. </p>
  32. */
  33. public static final ByteOrder LITTLE_ENDIAN
  34. = new ByteOrder("LITTLE_ENDIAN");
  35. /**
  36. * Retrieves the native byte order of the underlying platform.
  37. *
  38. * <p> This method is defined so that performance-sensitive Java code can
  39. * allocate direct buffers with the same byte order as the hardware.
  40. * Native code libraries are often more efficient when such buffers are
  41. * used. </p>
  42. *
  43. * @return The native byte order of the hardware upon which this Java
  44. * virtual machine is running
  45. */
  46. public static ByteOrder nativeOrder() {
  47. return Bits.byteOrder();
  48. }
  49. /**
  50. * Constructs a string describing this object.
  51. *
  52. * <p> This method returns the string <tt>"BIG_ENDIAN"</tt> for {@link
  53. * #BIG_ENDIAN} and <tt>"LITTLE_ENDIAN"</tt> for {@link #LITTLE_ENDIAN}.
  54. * </p>
  55. *
  56. * @return The specified string
  57. */
  58. public String toString() {
  59. return name;
  60. }
  61. }