当前位置: 首页>>代码示例>>Java>>正文


Java ByteBuffer.getUnsigned方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:wso2,项目名称:andes,代码行数:26,代码来源:EncodingUtils.java

示例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;
}
 
开发者ID:wso2,项目名称:andes,代码行数:37,代码来源:EncodingUtils.java

示例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);
    }
}
 
开发者ID:wso2,项目名称:andes,代码行数:14,代码来源:AMQShortString.java

示例4: readUnsignedByte

import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
protected short readUnsignedByte(ByteBuffer buffer)
{
    return buffer.getUnsigned();
}
 
开发者ID:wso2,项目名称:andes,代码行数:5,代码来源:AMQMethodBodyImpl.java


注:本文中的org.apache.mina.common.ByteBuffer.getUnsigned方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。