本文整理汇总了Java中org.apache.mina.common.ByteBuffer.getUnsignedInt方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.getUnsignedInt方法的具体用法?Java ByteBuffer.getUnsignedInt怎么用?Java ByteBuffer.getUnsignedInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.common.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.getUnsignedInt方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readLongString
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public static String readLongString(ByteBuffer buffer)
{
long length = buffer.getUnsignedInt();
if (length == 0)
{
return "";
}
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[(int) length];
buffer.get(stringBytes, 0, (int) length);
char[] stringChars = new char[(int) length];
for (int i = 0; i < stringChars.length; i++)
{
stringChars[i] = (char) stringBytes[i];
}
return new String(stringChars);
}
}
示例2: readFieldTable
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public static FieldTable readFieldTable(ByteBuffer buffer) throws AMQFrameDecodingException
{
long length = buffer.getUnsignedInt();
if (length == 0)
{
return null;
}
else
{
return FieldTableFactory.newFieldTable(buffer, length);
}
}
示例3: readLongstr
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public static byte[] readLongstr(ByteBuffer buffer)
{
long length = buffer.getUnsignedInt();
if (length == 0)
{
return null;
}
else
{
byte[] result = new byte[(int) length];
buffer.get(result);
return result;
}
}
示例4: readBytes
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public static byte[] readBytes(ByteBuffer buffer)
{
long length = buffer.getUnsignedInt();
if (length == 0)
{
return null;
}
else
{
byte[] dataBytes = new byte[(int)length];
buffer.get(dataBytes, 0, (int)length);
return dataBytes;
}
}
示例5: testwriteBuffer
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public void testwriteBuffer()
{
byte[] bytes = { 99, 98, 97, 96, 95 };
FieldTable table = new FieldTable();
table.setBoolean("bool", true);
table.setByte("byte", Byte.MAX_VALUE);
table.setBytes("bytes", bytes);
table.setChar("char", 'c');
table.setDouble("double", Double.MAX_VALUE);
table.setFloat("float", Float.MAX_VALUE);
table.setInteger("int", Integer.MAX_VALUE);
table.setLong("long", Long.MAX_VALUE);
table.setShort("short", Short.MAX_VALUE);
table.setString("string", "hello");
table.setString("null-string", null);
final ByteBuffer buffer = ByteBuffer.allocate((int) table.getEncodedSize() + 4); // FIXME XXX: Is cast a problem?
table.writeToBuffer(buffer);
buffer.flip();
long length = buffer.getUnsignedInt();
FieldTable table2 = new FieldTable(buffer, length);
Assert.assertEquals((Boolean) true, table2.getBoolean("bool"));
Assert.assertEquals((Byte) Byte.MAX_VALUE, table2.getByte("byte"));
assertBytesEqual(bytes, table2.getBytes("bytes"));
Assert.assertEquals((Character) 'c', table2.getCharacter("char"));
Assert.assertEquals(Double.MAX_VALUE, table2.getDouble("double"));
Assert.assertEquals(Float.MAX_VALUE, table2.getFloat("float"));
Assert.assertEquals((Integer) Integer.MAX_VALUE, table2.getInteger("int"));
Assert.assertEquals((Long) Long.MAX_VALUE, table2.getLong("long"));
Assert.assertEquals((Short) Short.MAX_VALUE, table2.getShort("short"));
Assert.assertEquals("hello", table2.getString("string"));
Assert.assertEquals(null, table2.getString("null-string"));
}
示例6: readUnsignedInteger
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
protected long readUnsignedInteger(ByteBuffer buffer)
{
return buffer.getUnsignedInt();
}
示例7: createAndPopulateFrame
import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public AMQFrame createAndPopulateFrame(AMQMethodBodyFactory methodBodyFactory, ByteBuffer in)
throws AMQFrameDecodingException, AMQProtocolVersionException
{
final byte type = in.get();
BodyFactory bodyFactory;
if (type == AMQMethodBody.TYPE)
{
bodyFactory = methodBodyFactory;
}
else
{
bodyFactory = _bodiesSupported[type];
}
if (bodyFactory == null)
{
throw new AMQFrameDecodingException(null, "Unsupported frame type: " + type, null);
}
final int channel = in.getUnsignedShort();
final long bodySize = in.getUnsignedInt();
// bodySize can be zero
if ((channel < 0) || (bodySize < 0))
{
throw new AMQFrameDecodingException(null, "Undecodable frame: type = " + type + " channel = " + channel
+ " bodySize = " + bodySize, null);
}
AMQFrame frame = new AMQFrame(in, channel, bodySize, bodyFactory);
byte marker = in.get();
if ((marker & 0xFF) != 0xCE)
{
throw new AMQFrameDecodingException(null, "End of frame marker not found. Read " + marker + " length=" + bodySize
+ " type=" + type, null);
}
return frame;
}