/** * 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); } }
/** * 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)); } }
segment.putChar(-1, 'a'); fail("IndexOutOfBoundsException expected"); segment.putChar(pageSize, 'a'); fail("IndexOutOfBoundsException expected"); segment.putChar(Integer.MIN_VALUE, 'a'); fail("IndexOutOfBoundsException expected"); segment.putChar(Integer.MAX_VALUE, 'a'); fail("IndexOutOfBoundsException expected"); segment.putChar(Integer.MAX_VALUE - 1, 'a'); fail("IndexOutOfBoundsException expected"); segment.putChar(i, (char) (random.nextInt(Character.MAX_VALUE))); segment.putChar(pos, (char) (random.nextInt(Character.MAX_VALUE)));
segment.putChar(0, 'a'); fail("Should fail with an exception"); segment.putChar(-1, 'a'); fail("Should fail with an exception"); segment.putChar(1, 'a'); fail("Should fail with an exception"); segment.putChar(segment.size(), 'a'); fail("Should fail with an exception"); segment.putChar(-segment.size(), 'a'); fail("Should fail with an exception"); segment.putChar(Integer.MAX_VALUE, 'a'); fail("Should fail with an exception"); segment.putChar(Integer.MIN_VALUE, 'a'); fail("Should fail with an exception");
segment.putChar(0, 'a'); fail("IndexOutOfBoundsException expected"); segment.putChar(1, 'a'); fail("IndexOutOfBoundsException expected"); segment.putChar(-1, 'a'); fail("IndexOutOfBoundsException expected"); segment.putChar(8, 'a'); fail("IndexOutOfBoundsException expected"); segment.putChar(-8, 'a'); fail("IndexOutOfBoundsException expected"); segment.putChar(Integer.MAX_VALUE, 'a'); fail("IndexOutOfBoundsException expected"); segment.putChar(Integer.MIN_VALUE, 'a'); fail("IndexOutOfBoundsException expected");
/** * 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)); } }
/** * 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); } }
/** * 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); } }
/** * 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)); } }
public static void setChar(MemorySegment[] segments, int offset, char value) { if (segments.length == 1) { segments[0].putChar(offset, value); } else { setCharMultiSeg(segments, offset, value); } }
@Override public void writeChar(int pos, char value) { segment.putChar(getElementOffset(pos, 2), value); }
@Override public void writeChar(int pos, char value) { segment.putChar(getFieldOffset(pos), value); }
private static void setCharMultiSeg(MemorySegment[] segments, int offset, char value) { int segSize = segments[0].size(); int segIndex = offset / segSize; int segOffset = offset - segIndex * segSize; // equal to % if (segOffset < segSize - 3) { segments[segIndex].putChar(segOffset, value); } else { set2ByteSlowly(segments, segSize, segIndex, segOffset, value, value >> 8); } }
@Override public void setChar(int pos, char value) { assertIndexIsValid(pos); setNotNullAt(pos); segment.putChar(getFieldOffset(pos), value); }