1854 * Modifies this buffer's byte order. 1855 * 1856 * @param bo 1857 * The new byte order, 1858 * either {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN} 1859 * or {@link ByteOrder#LITTLE_ENDIAN LITTLE_ENDIAN} 1860 * 1861 * @return This buffer 1862 */ 1863 public final $Type$Buffer order(ByteOrder bo) { 1864 bigEndian = (bo == ByteOrder.BIG_ENDIAN); 1865 nativeByteOrder = 1866 (bigEndian == (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)); 1867 return this; 1868 } 1869 1870 /** 1871 * Returns the memory address, pointing to the byte at the given index, 1872 * modulo the given unit size. 1873 * 1874 * <p> The return value is non-negative, with {@code 0} indicating that the 1875 * address of the byte at the index is aligned for the unit size, and a 1876 * positive value that the address is misaligned for the unit size. If the 1877 * address of the byte at the index is misaligned, the return value 1878 * represents how much the index should be adjusted to locate a byte at an 1879 * aligned address. Specifically, the index should either be decremented by 1880 * the return value, or incremented by the unit size minus the return value. 1881 * Therefore given 1882 * <blockquote><pre> 1883 * int value = alignmentOffset(index, unitSize)</pre></blockquote> 1884 * then the identities 1885 * <blockquote><pre> 1886 * alignmentOffset(index - value, unitSize) == 0</pre></blockquote> 1887 * and 1888 * <blockquote><pre> 1889 * alignmentOffset(index + (unitSize - value), unitSize) == 0</pre></blockquote> 1890 * must hold. 1891 * 1892 * @apiNote 1893 * This method may be utilized to determine if unit size bytes from an 1894 * index can be accessed atomically, if supported by the native platform. 1895 * 1896 * @implNote 1897 * This implementation throws {@code UnsupportedOperationException} for 1898 * non-direct buffers when the given unit size is greater then {@code 8}. 1899 * 1900 * @param index 1901 * The index to query for alignment offset, must be non-negative, no 1902 * upper bounds check is performed 1903 * 1904 * @param unitSize 1905 * The unit size in bytes, must be a power of {@code 2} 1906 * | 1854 * Modifies this buffer's byte order. 1855 * 1856 * @param bo 1857 * The new byte order, 1858 * either {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN} 1859 * or {@link ByteOrder#LITTLE_ENDIAN LITTLE_ENDIAN} 1860 * 1861 * @return This buffer 1862 */ 1863 public final $Type$Buffer order(ByteOrder bo) { 1864 bigEndian = (bo == ByteOrder.BIG_ENDIAN); 1865 nativeByteOrder = 1866 (bigEndian == (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)); 1867 return this; 1868 } 1869 1870 /** 1871 * Returns the memory address, pointing to the byte at the given index, 1872 * modulo the given unit size. 1873 * 1874 * <p> The return value is non-negative in the range of {@code 0} 1875 * (inclusive) up to {@code unitSize} (exclusive), with zero indicating 1876 * that the address of the byte at the index is aligned for the unit size, 1877 * and a positive value that the address is misaligned for the unit size. 1878 * If the address of the byte at the index is misaligned, the return value 1879 * represents how much the index should be adjusted to locate a byte at an 1880 * aligned address. Specifically, the index should either be decremented by 1881 * the return value if the latter is not greater than {@code index}, or be 1882 * incremented by the unit size minus the return value. Therefore given 1883 * <blockquote><pre> 1884 * int value = alignmentOffset(index, unitSize)</pre></blockquote> 1885 * then the identities 1886 * <blockquote><pre> 1887 * alignmentOffset(index - value, unitSize) == 0, value ≤ index</pre></blockquote> 1888 * and 1889 * <blockquote><pre> 1890 * alignmentOffset(index + (unitSize - value), unitSize) == 0</pre></blockquote> 1891 * must hold. 1892 * 1893 * @apiNote 1894 * This method may be utilized to determine if unit size bytes from an 1895 * index can be accessed atomically, if supported by the native platform. 1896 * 1897 * @implNote 1898 * This implementation throws {@code UnsupportedOperationException} for 1899 * non-direct buffers when the given unit size is greater then {@code 8}. 1900 * 1901 * @param index 1902 * The index to query for alignment offset, must be non-negative, no 1903 * upper bounds check is performed 1904 * 1905 * @param unitSize 1906 * The unit size in bytes, must be a power of {@code 2} 1907 * |