本文整理汇总了Java中org.apache.mina.common.ByteBuffer.getUnsigned方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.getUnsigned方法的具体用法?Java ByteBuffer.getUnsigned怎么用?Java ByteBuffer.getUnsigned使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.common.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.getUnsigned方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readShortString
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public static String readShortString(ByteBuffer buffer)
{
short length = buffer.getUnsigned();
if (length == 0)
{
return null;
}
else
{
// this may seem rather odd to declare two array but testing has shown
// that constructing a string from a byte array is 5 (five) times slower
// than constructing one from a char array.
// this approach here is valid since we know that all the chars are
// ASCII (0-127)
byte[] stringBytes = new byte[length];
buffer.get(stringBytes, 0, length);
char[] stringChars = new char[length];
for (int i = 0; i < stringChars.length; i++)
{
stringChars[i] = (char) stringBytes[i];
}
return new String(stringChars);
}
}
示例2: readLongAsShortString
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public static long readLongAsShortString(ByteBuffer buffer)
{
short length = buffer.getUnsigned();
short pos = 0;
if (length == 0)
{
return 0L;
}
byte digit = buffer.get();
boolean isNegative;
long result = 0;
if (digit == (byte) '-')
{
isNegative = true;
pos++;
digit = buffer.get();
}
else
{
isNegative = false;
}
result = digit - (byte) '0';
pos++;
while (pos < length)
{
pos++;
digit = buffer.get();
result = (result << 3) + (result << 1);
result += digit - (byte) '0';
}
return result;
}
示例3: readFromBuffer
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public static AMQShortString readFromBuffer(ByteBuffer buffer)
{
final short length = buffer.getUnsigned();
if (length == 0)
{
return null;
}
else
{
return new AMQShortString(buffer, length);
}
}
示例4: readUnsignedByte
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
protected short readUnsignedByte(ByteBuffer buffer)
{
return buffer.getUnsigned();
}