Example usage for io.netty.util.internal PlatformDependent putByte

List of usage examples for io.netty.util.internal PlatformDependent putByte

Introduction

In this page you can find the example usage for io.netty.util.internal PlatformDependent putByte.

Prototype

public static void putByte(byte[] data, int index, byte value) 

Source Link

Usage

From source file:org.apache.activemq.artemis.utils.UTF8Util.java

License:Apache License

private static int unsafeOnHeapWriteUTF(final CharSequence str, final byte[] bytes, final int index,
        final int length) {
    int charCount = index;
    for (int i = 0; i < length; i++) {
        char charAtPos = str.charAt(i);
        if (charAtPos <= 0x7f) {
            PlatformDependent.putByte(bytes, charCount++, (byte) charAtPos);
        } else if (charAtPos >= 0x800) {
            PlatformDependent.putByte(bytes, charCount++, (byte) (0xE0 | charAtPos >> 12 & 0x0F));
            PlatformDependent.putByte(bytes, charCount++, (byte) (0x80 | charAtPos >> 6 & 0x3F));
            PlatformDependent.putByte(bytes, charCount++, (byte) (0x80 | charAtPos >> 0 & 0x3F));
        } else {// w ww.j  av  a 2 s  .co m
            PlatformDependent.putByte(bytes, charCount++, (byte) (0xC0 | charAtPos >> 6 & 0x1F));
            PlatformDependent.putByte(bytes, charCount++, (byte) (0x80 | charAtPos >> 0 & 0x3F));
        }
    }

    final int writtenBytes = (charCount - index);
    return writtenBytes;
}