List of usage examples for io.netty.buffer ByteBufInputStream ByteBufInputStream
public ByteBufInputStream(ByteBuf buffer)
From source file:me.bigteddy98.mcproxy.protocol.packet.PacketDataWrapper.java
License:Open Source License
public ItemStack readItemStack() { short blockId = this.readShort(); if (blockId == -1) { return null; }/* www . j a v a 2s .c o m*/ ItemStack stack = new ItemStack(blockId, (byte) -1, (short) -1); stack.setAmount(this.readByte()); stack.setDamage(this.readShort()); int index = this.readerIndex(); if (this.readByte() == 0) { return stack; } this.readerIndex(index); try (NBTInputStream nbtInStream = new NBTInputStream( new DataInputStream(new ByteBufInputStream(this.buffer)))) { stack.setCompoundTag((CompoundTag) nbtInStream.readTag()); } catch (Exception e) { e.printStackTrace(); } return stack; }
From source file:me.undergroundminer3.uee4.energy.gui.ContainerEE_BC.java
License:Minecraft Mod Public
public void handleWidgetClientData(final int widgetId, final ByteBuf data) { InputStream input = new ByteBufInputStream(data); DataInputStream stream = new DataInputStream(input); try {/*from w ww.jav a 2 s . c o m*/ widgets.get(widgetId).handleClientPacketData(stream); } catch (IOException e) { e.printStackTrace(); } }
From source file:mod.rankshank.arbitraria.common.network.packet.PacketOccurrence.java
@Override public void fromBytes(ByteBuf buf) { DataInputStream data = new DataInputStream(new ByteBufInputStream(buf)); try {/* w w w. j a v a2 s.c om*/ flavor = data.readByte(); switch (flavor) { case 0: occurrence = CurrentOccurrence.readFromNBT(CompressedStreamTools.read(data)); break; case 1: id = UUID.fromString(data.readUTF()); break; case 2: NBTTagList list = CompressedStreamTools.read(data).getTagList("data", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < list.tagCount(); i++) occurrences.add(CurrentOccurrence.readFromNBT((NBTTagCompound) list.get(i))); break; default: break; } } catch (IOException e) { Arbitraria.error(new Throwable("Issue reading CurrentOccurrence packet"), e); } finally { try { data.close(); //yeah close up you fucking trollop } catch (IOException e) { //ALREADY ERRED YOU TWAT } } }
From source file:mods.railcraft.common.carts.EntityCartTank.java
License:Open Source License
@Override public void readSpawnData(ByteBuf data) { try {//from w ww .ja va2 s .c o m DataInputStream byteSteam = new DataInputStream(new ByteBufInputStream(data)); setFilter(DataTools.readItemStack(byteSteam)); } catch (IOException ex) { } }
From source file:mods.railcraft.common.carts.EntityLocomotive.java
License:Open Source License
@Override public void readSpawnData(ByteBuf data) { try {//ww w .j a v a2 s .co m DataInputStream byteSteam = new DataInputStream(new ByteBufInputStream(data)); String name = byteSteam.readUTF(); if (!name.equals("")) setMinecartName(name); model = byteSteam.readUTF(); } catch (IOException ex) { } }
From source file:net.jselby.pc.network.PacketDecoder.java
License:Open Source License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List<Object> objects) throws Exception { try {//from w w w.j a v a 2 s.c o m byteBuf.markReaderIndex(); StandardInput in = new StandardInput(new DataInputStream(new ByteBufInputStream(byteBuf))); int length = in.readVarInt(); if (byteBuf.readableBytes() < length) { // Not enough data yet! Wait for a while byteBuf.resetReaderIndex(); return; } byte[] packet = in.readBytes(length); // Create a "unread" packet, for the connection handler to process StandardInput packetIn = new StandardInput(new DataInputStream(new ByteArrayInputStream(packet))); UnreadPacket packetContainer = new UnreadPacket(); packetContainer.in = packetIn; packetContainer.length = length; objects.add(packetContainer); } catch (EOFException e) { System.out.println("Client " + ctx.channel().remoteAddress() + " disconnected: End of stream"); UnreadPacket packetContainer = new UnreadPacket(); packetContainer.in = null; packetContainer.length = -1; objects.add(packetContainer); throw e; } catch (Exception e) { throw e; } }
From source file:net.mcsproject.daemon.network.PacketDecoder.java
License:Open Source License
@Override protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception { byte id = byteBuf.readByte(); Packet packet = packetRegistry.getPacketById(id); if (packet != null) { packet.read(new ByteBufInputStream(byteBuf)); list.add(packet);// w w w. j ava 2s. com } }
From source file:net.minecrell.quartz.status.QuartzFavicon.java
License:MIT License
private static BufferedImage decode(String encoded) throws IOException { checkArgument(encoded.startsWith(FAVICON_PREFIX), "Unknown favicon format"); ByteBuf base64 = Unpooled.copiedBuffer(encoded.substring(FAVICON_PREFIX.length()), Charsets.UTF_8); try {// w w w . ja v a 2s . co m ByteBuf buf = Base64.decode(base64); try { BufferedImage result = ImageIO.read(new ByteBufInputStream(buf)); checkState(result.getWidth() == 64, "favicon must be 64 pixels wide"); checkState(result.getHeight() == 64, "favicon must be 64 pixels high"); return result; } finally { buf.release(); } } finally { base64.release(); } }
From source file:net.tridentsdk.data.Slot.java
License:Open Source License
public Slot(ByteBuf buf) { this.id = (short) buf.readByte(); this.mat = Material.fromString(String.valueOf(this.id)); if (this.id == -1) { return;//from w ww . jav a 2 s .com } this.quantity = buf.readByte(); this.damageValue = buf.readShort(); byte b; if ((b = buf.readByte()) != 0) { try { NBTDecoder builder = new NBTDecoder(new ByteBufInputStream(buf)); this.compoundTag = builder.decode(b); } catch (NBTException ignored) { // do something } } }
From source file:net.tridentsdk.server.data.Slot.java
License:Apache License
public Slot(ByteBuf buf) { this.id = buf.readShort(); this.mat = Substance.fromId((byte) this.id); if (this.id == -1) { return;// w w w . j a v a 2 s.co m } this.quantity = buf.readByte(); this.damageValue = buf.readShort(); byte b; if ((b = buf.readByte()) != 0) { try { NBTDecoder builder = new NBTDecoder(new ByteBufInputStream(buf)); this.compoundTag = builder.decode(b); } catch (NBTException ignored) { // do something } } }