List of usage examples for io.netty.buffer ByteBuf array
public abstract byte[] array();
From source file:DescriptorTester.java
License:Open Source License
public void sender(ByteBuf buf) { DatagramSocket socket = null; try {// w ww.jav a2 s . co m socket = new DatagramSocket(); } catch (SocketException e) { e.printStackTrace(); } InetAddress address = null; try { address = InetAddress.getLoopbackAddress(); System.out.println(address); } catch (Exception e) { e.printStackTrace(); } { System.out.printf("Capacity of ByteBuf %d", buf.writableBytes()); System.out.printf("Writer Index %d", buf.writerIndex()); int packet_size = buf.writerIndex(); System.out.printf("packetsize %d", packet_size); byte[] array = buf.array(); DatagramPacket packet = new DatagramPacket(array, packet_size, address, 5246); try { socket.send(packet); System.out.printf("\nSending Capwap Message "); } catch (IOException e) { e.printStackTrace(); } } }
From source file:TestDescriptor.java
License:Open Source License
public void sender(ByteBuf buf) { DatagramSocket socket = null; try {// w w w . jav a 2 s . c o m socket = new DatagramSocket(); } catch (SocketException e) { e.printStackTrace(); } InetAddress address = null; try { address = InetAddress.getLoopbackAddress(); System.out.println(address); } catch (Exception e) { e.printStackTrace(); } { System.out.printf("Capacity of ByteBuf %d", buf.writableBytes()); System.out.printf("Writer Index %d", buf.writerIndex()); int packet_size = buf.writerIndex(); System.out.printf("packetsize %d", packet_size); byte[] array = buf.array(); DatagramPacket packet = new DatagramPacket(array, packet_size, address, 5246); try { socket.send(packet); System.out.printf("\nSending Capwap Message "); } catch (IOException e) { e.printStackTrace(); } } }
From source file:WtpTestClient.java
License:Open Source License
public void sender(ByteBuf buf) { DatagramSocket socket = null; try {//w w w. j a v a 2s . c om socket = new DatagramSocket(); } catch (SocketException e) { e.printStackTrace(); } InetAddress address = null; try { address = InetAddress.getLoopbackAddress(); System.out.println(address); } catch (Exception e) { e.printStackTrace(); } { int packet_size = buf.writerIndex(); byte[] array = buf.array(); int port = 5246; DatagramPacket packet = new DatagramPacket(array, packet_size, address, port); try { socket.send(packet); System.out.printf("\nSending Capwap Message of size->%d to %s:%d ", packet_size, address.toString(), port); } catch (IOException e) { e.printStackTrace(); } } }
From source file:UdpClient.java
License:Open Source License
public static void main(String args[]) { byte[] buf = new byte[256]; DatagramSocket socket = null; try {/*from w ww . j a va2 s. c o m*/ socket = new DatagramSocket(); } catch (SocketException e) { e.printStackTrace(); } InetAddress address = null; try { address = InetAddress.getLoopbackAddress(); System.out.println(address); } catch (Exception e) { e.printStackTrace(); } buf = "hello".getBytes(); ByteBuf nett_buf = Unpooled.buffer(); InetSocketAddress socketAddress = new InetSocketAddress(address, 5246); Scanner sc = new Scanner(System.in); { System.out.println("\nEnter Capwap Message ID"); //int longIn = 4294967294; int longIn = 0XFFFFFFFE; nett_buf.writeInt(longIn); buf = nett_buf.array(); DatagramPacket packet = new DatagramPacket(buf, nett_buf.writerIndex(), address, 5246); try { socket.send(packet); System.out.printf("\nSending Capwap Message %x ", longIn); } catch (IOException e) { e.printStackTrace(); } } }
From source file:CapwapMsgSender.java
License:Open Source License
public static void main(String args[]) { DatagramSocket socket = null; try {//from w ww . j a v a 2 s . co m socket = new DatagramSocket(); } catch (SocketException e) { e.printStackTrace(); } InetAddress address = null; try { address = InetAddress.getLoopbackAddress(); System.out.println(address); } catch (Exception e) { e.printStackTrace(); } //ByteBuf nett_buf = Unpooled.buffer(); ByteBuf buf = null; Scanner sc = new Scanner(System.in); while (true) { System.out.println("\nEnter Capwap Message ID"); int capwapMsg = sc.nextInt(); System.out.printf("Capacity of ByteBuf %d", buf.writableBytes()); System.out.printf("Writer Index %d", buf.writerIndex()); int packet_size = buf.writerIndex(); byte[] array = buf.array(); DatagramPacket packet = new DatagramPacket(array, packet_size, address, 5246); try { socket.send(packet); System.out.printf("\nSending Capwap Message %s ", ODLCapwapConsts.msgTypetoString(capwapMsg)); } catch (IOException e) { e.printStackTrace(); } } }
From source file:appeng.core.sync.packets.PacketJEIRecipe.java
License:Open Source License
public PacketJEIRecipe(final ByteBuf stream) throws IOException { final ByteArrayInputStream bytes = new ByteArrayInputStream(stream.array()); bytes.skip(stream.readerIndex());/*from ww w.ja va 2s. co m*/ final NBTTagCompound comp = CompressedStreamTools.readCompressed(bytes); if (comp != null) { this.recipe = new ItemStack[9][]; for (int x = 0; x < this.recipe.length; x++) { final NBTTagList list = comp.getTagList("#" + x, 10); if (list.tagCount() > 0) { this.recipe[x] = new ItemStack[list.tagCount()]; for (int y = 0; y < list.tagCount(); y++) { this.recipe[x][y] = ItemStack.loadItemStackFromNBT(list.getCompoundTagAt(y)); } } } } }
From source file:appeng.core.sync.packets.PacketMEInventoryUpdate.java
License:Open Source License
public void appendItem(final IAEItemStack is) throws IOException, BufferOverflowException { final ByteBuf tmp = Unpooled.buffer(OPERATION_BYTE_LIMIT); is.writeToPacket(tmp);/*from ww w .j av a2 s. co m*/ this.compressFrame.flush(); if (this.writtenBytes + tmp.readableBytes() > UNCOMPRESSED_PACKET_BYTE_LIMIT) { throw new BufferOverflowException(); } else { this.writtenBytes += tmp.readableBytes(); this.compressFrame.write(tmp.array(), 0, tmp.readableBytes()); this.empty = false; } }
From source file:appeng.core.sync.packets.PacketNEIRecipe.java
License:Open Source License
public PacketNEIRecipe(final ByteBuf stream) throws IOException { final ByteArrayInputStream bytes = new ByteArrayInputStream(stream.array()); bytes.skip(stream.readerIndex());/*from w w w .j a v a2 s . co m*/ final NBTTagCompound comp = CompressedStreamTools.readCompressed(bytes); if (comp != null) { this.recipe = new ItemStack[9][]; for (int x = 0; x < this.recipe.length; x++) { final NBTTagList list = comp.getTagList("#" + x, 10); if (list.tagCount() > 0) { this.recipe[x] = new ItemStack[list.tagCount()]; for (int y = 0; y < list.tagCount(); y++) { this.recipe[x][y] = ItemStack.loadItemStackFromNBT(list.getCompoundTagAt(y)); } } } } }
From source file:appeng.core.sync.packets.PacketValueConfig.java
License:Open Source License
public PacketValueConfig(final ByteBuf stream) throws IOException { final DataInputStream dis = new DataInputStream( new ByteArrayInputStream(stream.array(), stream.readerIndex(), stream.readableBytes())); this.Name = dis.readUTF(); this.Value = dis.readUTF(); // dis.close(); }
From source file:appeng.fmp.CableBusPart.java
License:Open Source License
@Override public void writeDesc(final MCDataOutput packet) { final ByteBuf stream = Unpooled.buffer(); try {//from w w w .jav a2 s. c o m this.getCableBus().writeToStream(stream); packet.writeInt(stream.readableBytes()); stream.capacity(stream.readableBytes()); packet.writeByteArray(stream.array()); } catch (final IOException e) { AELog.error(e); } }