/** {@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; }
/** {@inheritDoc} */ @Override public char readChar() { return Character.reverseBytes(super.readChar()); }
@Override public void putChar(int offset, char value) { _buffer.putChar(offset, Character.reverseBytes(value)); }
/** {@inheritDoc} */ @Override public void writeChar(char val) { super.writeChar(Character.reverseBytes(val)); }
@Override public Bytes writeChar(int offset, char c) { bytes.writeChar(offset, Character.reverseBytes(c)); return this; }
@Override public char getChar(int offset) { return Character.reverseBytes(_buffer.getChar(offset)); }
/** {@inheritDoc} */ @Override public void unsafeWriteChar(char val) { super.unsafeWriteChar(Character.reverseBytes(val)); }
/** * @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; }
@Override public char getChar(long offset) { return Character.reverseBytes(_buffer.getChar(offset)); }
@Override public void putChar(long offset, char value) { _buffer.putChar(offset, Character.reverseBytes(value)); }
/** * 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); }
/** {@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; }
/** * 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); } }
/** * 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)); } }
/** * 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)); } }
/** * 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); }
/** * 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); } }
/** * 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); }
/** * 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); }
/** {@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); }