本文整理了Java中java.lang.Character.reverseBytes()
方法的一些代码示例,展示了Character.reverseBytes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Character.reverseBytes()
方法的具体详情如下:
包路径:java.lang.Character
类名称:Character
方法名:reverseBytes
[英]Reverses the order of the first and second byte in the specified character.
[中]反转指定字符中第一个字节和第二个字节的顺序。
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public char[] readCharArray(int cnt) {
char[] res = super.readCharArray(cnt);
for (int i = 0; i < cnt; i++)
res[i] = Character.reverseBytes(res[i]);
return res;
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public char readChar() {
return Character.reverseBytes(super.readChar());
}
代码示例来源:origin: apache/incubator-pinot
@Override
public void putChar(int offset, char value) {
_buffer.putChar(offset, Character.reverseBytes(value));
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public void writeChar(char val) {
super.writeChar(Character.reverseBytes(val));
}
代码示例来源:origin: atomix/atomix
@Override
public Bytes writeChar(int offset, char c) {
bytes.writeChar(offset, Character.reverseBytes(c));
return this;
}
代码示例来源:origin: apache/incubator-pinot
@Override
public char getChar(int offset) {
return Character.reverseBytes(_buffer.getChar(offset));
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public void unsafeWriteChar(char val) {
super.unsafeWriteChar(Character.reverseBytes(val));
}
代码示例来源:origin: apache/ignite
/**
* @param ptr Pointer.
* @param off Offset.
* @return Value.
*/
public static char[] readCharArray(long ptr, int off, int len) {
char[] arr0 = new char[len];
GridUnsafe.copyOffheapHeap(ptr + off, arr0, GridUnsafe.CHAR_ARR_OFF, len << 1);
if (BIG_ENDIAN) {
for (int i = 0; i < len; i++)
arr0[i] = Character.reverseBytes(arr0[i]);
}
return arr0;
}
代码示例来源:origin: apache/incubator-pinot
@Override
public char getChar(long offset) {
return Character.reverseBytes(_buffer.getChar(offset));
}
代码示例来源:origin: apache/incubator-pinot
@Override
public void putChar(long offset, char value) {
_buffer.putChar(offset, Character.reverseBytes(value));
}
代码示例来源:origin: apache/ignite
/**
* Gets char value from given address assuming that value stored in little-endian byte order and native byte order
* is big-endian. Alignment aware.
*
* @param addr Address.
* @return Char value from given address.
*/
public static char getCharLE(long addr) {
return UNALIGNED ? Character.reverseBytes(UNSAFE.getChar(addr)) : getCharByByte(addr, false);
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public char[] readCharArray(int cnt) {
int len = cnt << 1;
ensureEnoughData(len);
char[] res = new char[cnt];
copyAndShift(res, GridUnsafe.CHAR_ARR_OFF, len);
if (BIG_ENDIAN) {
for (int i = 0; i < res.length; i++)
res[i] = Character.reverseBytes(res[i]);
}
return res;
}
代码示例来源:origin: apache/flink
/**
* Writes the given character (16 bit, 2 bytes) to the given position in big-endian
* byte order. This method's speed depends on the system's native byte order, and it
* is possibly slower than {@link #putChar(int, char)}. For most cases (such as
* transient storage in memory or serialization for I/O and network),
* it suffices to know that the byte order in which the value is written is the same as the
* one in which it is read, and {@link #putChar(int, char)} is the preferable choice.
*
* @param index The position at which the value will be written.
* @param value The char value to be written.
*
* @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment size minus 2.
*/
public final void putCharBigEndian(int index, char value) {
if (LITTLE_ENDIAN) {
putChar(index, Character.reverseBytes(value));
} else {
putChar(index, value);
}
}
代码示例来源:origin: apache/flink
/**
* Reads a character value (16 bit, 2 bytes) from the given position, in little-endian byte order.
* This method's speed depends on the system's native byte order, and it
* is possibly slower than {@link #getChar(int)}. For most cases (such as
* transient storage in memory or serialization for I/O and network),
* it suffices to know that the byte order in which the value is written is the same as the
* one in which it is read, and {@link #getChar(int)} is the preferable choice.
*
* @param index The position from which the value will be read.
* @return The character value at the given position.
*
* @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment size minus 2.
*/
public final char getCharLittleEndian(int index) {
if (LITTLE_ENDIAN) {
return getChar(index);
} else {
return Character.reverseBytes(getChar(index));
}
}
代码示例来源:origin: apache/flink
/**
* Writes the given character (16 bit, 2 bytes) to the given position in little-endian
* byte order. This method's speed depends on the system's native byte order, and it
* is possibly slower than {@link #putChar(int, char)}. For most cases (such as
* transient storage in memory or serialization for I/O and network),
* it suffices to know that the byte order in which the value is written is the same as the
* one in which it is read, and {@link #putChar(int, char)} is the preferable choice.
*
* @param index The position at which the value will be written.
* @param value The char value to be written.
*
* @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment size minus 2.
*/
public final void putCharLittleEndian(int index, char value) {
if (LITTLE_ENDIAN) {
putChar(index, value);
} else {
putChar(index, Character.reverseBytes(value));
}
}
代码示例来源:origin: apache/ignite
/**
* Gets char value from byte array assuming that value stored in little-endian byte order and native byte order
* is big-endian. Alignment aware.
*
* @param arr Byte array.
* @param off Offset.
* @return Char value from byte array.
*/
public static char getCharLE(byte[] arr, long off) {
return UNALIGNED ? Character.reverseBytes(UNSAFE.getChar(arr, off)) : getCharByByte(arr, off, false);
}
代码示例来源:origin: apache/flink
/**
* Reads a character value (16 bit, 2 bytes) from the given position, in big-endian byte order.
* This method's speed depends on the system's native byte order, and it
* is possibly slower than {@link #getChar(int)}. For most cases (such as
* transient storage in memory or serialization for I/O and network),
* it suffices to know that the byte order in which the value is written is the same as the
* one in which it is read, and {@link #getChar(int)} is the preferable choice.
*
* @param index The position from which the value will be read.
* @return The character value at the given position.
*
* @throws IndexOutOfBoundsException Thrown, if the index is negative, or larger then the segment size minus 2.
*/
public final char getCharBigEndian(int index) {
if (LITTLE_ENDIAN) {
return Character.reverseBytes(getChar(index));
} else {
return getChar(index);
}
}
代码示例来源:origin: apache/ignite
/**
* Stores given char value assuming that value should be stored in little-endian byte order and native byte order
* is big-endian. Alignment aware.
*
* @param addr Address.
* @param val Value.
*/
public static void putCharLE(long addr, char val) {
if (UNALIGNED)
UNSAFE.putChar(addr, Character.reverseBytes(val));
else
putCharByByte(addr, val, false);
}
代码示例来源:origin: apache/ignite
/**
* Stores char value into byte array assuming that value should be stored in little-endian byte order and native
* byte order is big-endian. Alignment aware.
*
* @param arr Byte array.
* @param off Offset.
* @param val Value.
*/
public static void putCharLE(byte[] arr, long off, char val) {
if (UNALIGNED)
UNSAFE.putChar(arr, off, Character.reverseBytes(val));
else
putCharByByte(arr, off, val, false);
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public void writeCharArray(char[] val) {
int cnt = val.length << 1;
ensureCapacity(pos + cnt);
long startPos = data + pos;
for (char item : val) {
GridUnsafe.putChar(startPos, Character.reverseBytes(item));
startPos += 2;
}
shift(cnt);
}
内容来源于网络,如有侵权,请联系作者删除!