本文整理汇总了Java中io.netty.buffer.Unpooled.buffer方法的典型用法代码示例。如果您正苦于以下问题:Java Unpooled.buffer方法的具体用法?Java Unpooled.buffer怎么用?Java Unpooled.buffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.buffer.Unpooled
的用法示例。
在下文中一共展示了Unpooled.buffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUpdate
import io.netty.buffer.Unpooled; //导入方法依赖的package包/类
@Test
public void testUpdate() throws Exception {
serverDenseFloatRow = new ServerDenseFloatRow(rowId, startCol, endCol);
ByteBuf buf = Unpooled.buffer(16);
buf.writeFloat((float) 0.00);
buf.writeFloat((float) 1.00);
buf.writeFloat((float) -1.00);
float newValue0 = buf.getFloat(0) + serverDenseFloatRow.getData().get(0);
float newValue1 = buf.getFloat(4) + serverDenseFloatRow.getData().get(1);
serverDenseFloatRow.update(RowType.T_FLOAT_DENSE, buf, 3);
assertEquals(serverDenseFloatRow.getData().get(0), newValue0, 0.000);
assertEquals(serverDenseFloatRow.getData().get(1), newValue1, 0.000);
assertEquals(serverDenseFloatRow.getData().get(2), -1, 0.000);
serverDenseFloatRow = new ServerDenseFloatRow(rowId, startCol, endCol);
buf = Unpooled.buffer(0);
buf.writeInt(0);
buf.writeFloat((float) 1.00);
buf.writeInt(2);
buf.writeFloat((float) -2.00);
serverDenseFloatRow.update(RowType.T_FLOAT_SPARSE, buf, 2);
assertEquals(serverDenseFloatRow.getData().get(0), 1, 0.000);
assertEquals(serverDenseFloatRow.getData().get(1), 0, 0.000);
assertEquals(serverDenseFloatRow.getData().get(2), -2, 0.000);
}
示例2: testReadFrom
import io.netty.buffer.Unpooled; //导入方法依赖的package包/类
@Test
public void testReadFrom() throws Exception {
ByteBuf buf = Unpooled.buffer(16);
buf.writeFloat((float) 10.00);
buf.writeFloat((float) 11.00);
buf.writeFloat((float) 12.00);
serverDenseFloatRow.update(RowType.T_FLOAT_DENSE, buf, 3);
DataOutputStream out = new DataOutputStream(new FileOutputStream("data"));
serverDenseFloatRow.writeTo(out);
out.close();
DataInputStream in = new DataInputStream(new FileInputStream("data"));
ServerDenseFloatRow newServerDenseFloatRow = new ServerDenseFloatRow(rowId, startCol, endCol);
newServerDenseFloatRow.readFrom(in);
assertEquals(newServerDenseFloatRow.getData().get(0), serverDenseFloatRow.getData().get(0),
0.00);
assertEquals(newServerDenseFloatRow.getData().get(1), serverDenseFloatRow.getData().get(1),
0.00);
assertEquals(newServerDenseFloatRow.getData().get(2), serverDenseFloatRow.getData().get(2),
0.00);
}
示例3: testReadFrom
import io.netty.buffer.Unpooled; //导入方法依赖的package包/类
@Test
public void testReadFrom() throws Exception {
ByteBuf buf = Unpooled.buffer(16);
buf.writeDouble(10.00);
buf.writeDouble(11.00);
buf.writeDouble(12.00);
serverDenseDoubleRow.update(RowType.T_DOUBLE_DENSE, buf, 3);
DataOutputStream out = new DataOutputStream(new FileOutputStream("data"));
serverDenseDoubleRow.writeTo(out);
out.close();
DataInputStream in = new DataInputStream(new FileInputStream("data"));
ServerDenseDoubleRow newServerDenseDoubleRow =
new ServerDenseDoubleRow(rowId, startCol, endCol);
newServerDenseDoubleRow.readFrom(in);
in.close();
assertEquals(newServerDenseDoubleRow.getData().get(0), serverDenseDoubleRow.getData().get(0),
0.00);
assertEquals(newServerDenseDoubleRow.getData().get(1), serverDenseDoubleRow.getData().get(1),
0.00);
assertEquals(newServerDenseDoubleRow.getData().get(2), serverDenseDoubleRow.getData().get(2),
0.00);
}
示例4: encodeConnectionRequest
import io.netty.buffer.Unpooled; //导入方法依赖的package包/类
@Test
@Tag("fast")
public void encodeConnectionRequest() throws Exception {
ChannelHandlerContext ctx = new MockChannelHandlerContext();
ByteBuf buf = Unpooled.buffer();
ConnectionRequestTpdu tpdu = new ConnectionRequestTpdu((short)0x1, (short)(0x2), ProtocolClass.CLASS_0, Collections.emptyList(), buf);
ArrayList<Object> out = new ArrayList<>();
isoTPProtocol.encode(ctx, tpdu, out);
assertTrue(out.size() == 1, "Message not decoded");
ByteBuf userData = ((IsoOnTcpMessage)out.get(0)).getUserData();
assertTrue(userData.writerIndex() == 7, "Incorrect message length");
assertTrue(userData.readByte() == (byte)0x6, "Incorrect header length");
assertTrue(userData.readByte() == TpduCode.CONNECTION_REQUEST.getCode(), "Incorrect Tpdu code");
assertTrue(userData.readShort() == (short)0x1, "Incorrect destination reference code");
assertTrue(userData.readShort() == (short)0x2, "Incorrect source reference code");
assertTrue(userData.readByte() == ProtocolClass.CLASS_0.getCode(), "Incorrect protocol class");
}
示例5: testSerialize
import io.netty.buffer.Unpooled; //导入方法依赖的package包/类
@Test
public void testSerialize() throws Exception {
ByteBuf buf = Unpooled.buffer(16);
serverSparseDoubleRow.setClock(8);
buf.writeDouble(0.00);
buf.writeDouble(1.00);
buf.writeDouble(-1.00);
serverSparseDoubleRow.update(RowType.T_DOUBLE_DENSE, buf, 3);
serverSparseDoubleRow.serialize(buf);
assertEquals(serverSparseDoubleRow.getRowId(), buf.readInt());
assertEquals(serverSparseDoubleRow.getClock(), buf.readInt());
assertEquals(serverSparseDoubleRow.getStartCol(), buf.readLong());
assertEquals(serverSparseDoubleRow.getEndCol(), buf.readLong());
assertEquals(serverSparseDoubleRow.getRowVersion(), buf.readInt());
assertEquals(3, buf.readInt());
}
示例6: displayVillagerTradeGui
import io.netty.buffer.Unpooled; //导入方法依赖的package包/类
public void displayVillagerTradeGui(IMerchant villager)
{
this.getNextWindowId();
this.openContainer = new ContainerMerchant(this.inventory, villager, this.worldObj);
this.openContainer.windowId = this.currentWindowId;
this.openContainer.onCraftGuiOpened(this);
IInventory iinventory = ((ContainerMerchant)this.openContainer).getMerchantInventory();
IChatComponent ichatcomponent = villager.getDisplayName();
this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, "minecraft:villager", ichatcomponent, iinventory.getSizeInventory()));
MerchantRecipeList merchantrecipelist = villager.getRecipes(this);
if (merchantrecipelist != null)
{
PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
packetbuffer.writeInt(this.currentWindowId);
merchantrecipelist.writeToBuf(packetbuffer);
this.playerNetServerHandler.sendPacket(new S3FPacketCustomPayload("MC|TrList", packetbuffer));
}
}
示例7: testEncodeDecodeWithFalseFlags
import io.netty.buffer.Unpooled; //导入方法依赖的package包/类
@Test
public void testEncodeDecodeWithFalseFlags() throws Exception {
BasicCancel testFrame = new BasicCancel(1,
ShortString.parseString("1"),
false);
ByteBuf buf = Unpooled.buffer((int) testFrame.getMethodBodySize());
testFrame.writeMethod(buf);
BasicCancel decodedFrame = (BasicCancel) BasicCancel.getFactory()
.newInstance(buf, 1, testFrame.getMethodBodySize());
Assert.assertEquals(decodedFrame.getChannel(), testFrame.getChannel(), "Decoded frame's channel should match"
+ " the original frame's channel");
Assert.assertEquals(decodedFrame.getConsumerTag(), testFrame.getConsumerTag(), "Decoded frame's consumer-tag "
+ "should match the original frame's consumer-tag");
Assert.assertEquals(decodedFrame.isNoWait(), testFrame.isNoWait(), "Decoded frame's no-wait bit "
+ "should match the original frame's no-wait bit");
}
示例8: addFaviconToStatusResponse
import io.netty.buffer.Unpooled; //导入方法依赖的package包/类
private void addFaviconToStatusResponse(ServerStatusResponse response)
{
File file1 = this.getFile("server-icon.png");
if (file1.isFile())
{
ByteBuf bytebuf = Unpooled.buffer();
try
{
BufferedImage bufferedimage = ImageIO.read(file1);
Validate.validState(bufferedimage.getWidth() == 64, "Must be 64 pixels wide", new Object[0]);
Validate.validState(bufferedimage.getHeight() == 64, "Must be 64 pixels high", new Object[0]);
ImageIO.write(bufferedimage, "PNG", (OutputStream)(new ByteBufOutputStream(bytebuf)));
ByteBuf bytebuf1 = Base64.encode(bytebuf);
response.setFavicon("data:image/png;base64," + bytebuf1.toString(Charsets.UTF_8));
}
catch (Exception exception)
{
logger.error((String)"Couldn\'t load server icon", (Throwable)exception);
}
finally
{
bytebuf.release();
}
}
}
示例9: openBook
import io.netty.buffer.Unpooled; //导入方法依赖的package包/类
public void openBook(ItemStack stack, EnumHand hand)
{
Item item = stack.getItem();
if (item == Items.WRITTEN_BOOK)
{
PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
packetbuffer.writeEnumValue(hand);
this.connection.sendPacket(new SPacketCustomPayload("MC|BOpen", packetbuffer));
}
}
示例10: EchoClientHandler
import io.netty.buffer.Unpooled; //导入方法依赖的package包/类
/**
* Creates a client-side handler.
*/
public EchoClientHandler() {
firstMessage = Unpooled.buffer(EchoClient.SIZE);
// for (int i = 0; i < firstMessage.capacity(); i ++) {
// firstMessage.writeByte("4".getBytes()[0]);
// }
firstMessage.writeByte("qwe".getBytes()[0]);
}
示例11: encode
import io.netty.buffer.Unpooled; //导入方法依赖的package包/类
public ByteBuf encode(Connection connection) {
ByteBuf serializer = Unpooled.buffer();
VarNumberSerializer.writeVarInt(serializer, getPacketId());
serializer.writeByte(0);
serializer.writeByte(0);
toData(connection, serializer);
return serializer;
}
示例12: sendRpcMessage
import io.netty.buffer.Unpooled; //导入方法依赖的package包/类
public void sendRpcMessage(Socket socket, NrpcMeta requestMessage) throws IOException {
readBuffer.reset(); //清空应答的读缓冲
byte[] bytes = requestMessage.toByteArray();
int totalSize = Constants.HEADER_SIZE + bytes.length;
ByteBuf buffer = Unpooled.buffer(totalSize);
buffer.writeBytes(new byte[]{'N', 'R', 'P', 'C'});
buffer.writeInt(totalSize);
buffer.writeBytes(new byte[]{0, 0, 0, 0});
buffer.writeBytes(bytes);
DataOutputStream dOut = new DataOutputStream(socket.getOutputStream());
dOut.write(buffer.array());
dOut.flush();
}
示例13: testEncodeDecode
import io.netty.buffer.Unpooled; //导入方法依赖的package包/类
@Test
public void testEncodeDecode() throws Exception {
BasicConsume testFrame = new BasicConsume(1,
ShortString.parseString("queue"),
ShortString.parseString("1"),
true,
true,
true,
true,
FieldTable.EMPTY_TABLE);
ByteBuf buf = Unpooled.buffer((int) testFrame.getMethodBodySize());
testFrame.writeMethod(buf);
BasicConsume decodedFrame = (BasicConsume) BasicConsume.getFactory()
.newInstance(buf, 1, testFrame.getMethodBodySize());
Assert.assertEquals(decodedFrame.getChannel(), testFrame.getChannel(), "Decoded frame's channel should match"
+ " the original frame's channel");
Assert.assertEquals(decodedFrame.getQueue(), testFrame.getQueue(), "Decoded frame's queue should match"
+ " the original frame's queue");
Assert.assertEquals(decodedFrame.getConsumerTag(), testFrame.getConsumerTag(), "Decoded frame's consumer-tag "
+ "should match the original frame's consumer-tag");
Assert.assertEquals(decodedFrame.isNoLocal(), testFrame.isNoLocal(), "Decoded frame's no-local bit should "
+ "match the original frame's no-local bit");
Assert.assertEquals(decodedFrame.isNoAck(), testFrame.isNoAck(), "Decoded frame's no-ack bit should match"
+ " the original frame's no-ack bit");
Assert.assertEquals(decodedFrame.isExclusive(), testFrame.isExclusive(), "Decoded frame's exclusive bit "
+ "should match the original frame's exclusive bit");
Assert.assertEquals(decodedFrame.isNoWait(), testFrame.isNoWait(), "Decoded frame's no-wait bit "
+ "should match the original frame's no-wait bit");
Assert.assertEquals(decodedFrame.getArguments(), testFrame.getArguments(), "Decoded frame's arguments "
+ "should match the original frame's arguments");
}
示例14: mirrorUnknown
import io.netty.buffer.Unpooled; //导入方法依赖的package包/类
private ByteBuf mirrorUnknown ( final ByteBuf data, final byte typeId, final InformationStructure informationStructure, final byte size, final ASDUHeader header, final Cause newCause )
{
logger.debug ( "Mirror unknown message -> {}", newCause );
final ByteBuf reply = Unpooled.buffer ();
EncodeHelper.encodeHeader ( typeId, informationStructure, this.options, (int)size, header.clone ( newCause ), reply );
reply.writeBytes ( data ); // copy data
return reply;
}
示例15: testBufferLen
import io.netty.buffer.Unpooled; //导入方法依赖的package包/类
@Test
public void testBufferLen() throws Exception {
ByteBuf buf = Unpooled.buffer(16);
serverSparseDoubleRow.setClock(8);
buf.writeDouble(0.00);
buf.writeDouble(1.00);
buf.writeDouble(-1.00);
serverSparseDoubleRow.update(RowType.T_DOUBLE_DENSE, buf, 3);
assertEquals(serverSparseDoubleRow.bufferLen(), 20 + 4 + 3 * 12);
}