List of usage examples for io.netty.util.internal PlatformDependent getByte
public static byte getByte(byte[] data, int index)
From source file:org.apache.activemq.artemis.utils.AbstractByteBufPool.java
License:Apache License
private static int onHeapHashCode(final byte[] bytes, final int offset, final int length) { final int intCount = length >>> 1; final int byteCount = length & 1; int hashCode = 1; int arrayIndex = offset; for (int i = 0; i < intCount; i++) { hashCode = 31 * hashCode + PlatformDependent.getShort(bytes, arrayIndex); arrayIndex += 2;/*www. j a va 2 s.co m*/ } for (int i = 0; i < byteCount; i++) { hashCode = 31 * hashCode + PlatformDependent.getByte(bytes, arrayIndex++); } return hashCode; }
From source file:org.apache.activemq.artemis.utils.UTF8Util.java
License:Apache License
private static String unsafeOnHeapReadUTF(final byte[] bytes, final int index, final char[] chars, final int size) { int count = index; final int limit = index + size; int byte1, byte2, byte3; int charCount = 0; while (count < limit) { byte1 = PlatformDependent.getByte(bytes, count++); if (byte1 >= 0 && byte1 <= 0x7F) { chars[charCount++] = (char) byte1; } else {// www .j ava2 s . c o m int c = byte1 & 0xff; switch (c >> 4) { case 0xc: case 0xd: byte2 = PlatformDependent.getByte(bytes, count++); chars[charCount++] = (char) ((c & 0x1F) << 6 | byte2 & 0x3F); break; case 0xe: byte2 = PlatformDependent.getByte(bytes, count++); byte3 = PlatformDependent.getByte(bytes, count++); chars[charCount++] = (char) ((c & 0x0F) << 12 | (byte2 & 0x3F) << 6 | (byte3 & 0x3F) << 0); break; default: throw new InternalError("unhandled utf8 byte " + c); } } } return new String(chars, 0, charCount); }