List of usage examples for io.netty.buffer ByteBufInputStream close
@Override public void close() throws IOException
From source file:cn.scujcc.bug.bitcoinplatformandroid.util.socket.websocket.WebSocketClientHandler.java
License:Apache License
public String decodeByteBuff(ByteBuf buf) throws IOException, DataFormatException { byte[] temp = new byte[buf.readableBytes()]; ByteBufInputStream bis = new ByteBufInputStream(buf); bis.read(temp);/*from w w w . ja v a2s.c o m*/ bis.close(); Inflater decompresser = new Inflater(true); decompresser.setInput(temp, 0, temp.length); StringBuilder sb = new StringBuilder(); byte[] result = new byte[1024]; while (!decompresser.finished()) { int resultLength = decompresser.inflate(result); sb.append(new String(result, 0, resultLength, "UTF-8")); } decompresser.end(); return sb.toString(); }
From source file:com.kanbekotori.keycraft.network.RewriteNetwork.java
License:Open Source License
/** */ @SubscribeEvent//from ww w . j av a 2 s . c o m public void onServerPacket(ServerCustomPacketEvent event) { EntityPlayerMP player = ((NetHandlerPlayServer) event.handler).playerEntity; ByteBufInputStream stream = new ByteBufInputStream(event.packet.payload()); try { switch (stream.readInt()) { case LEARN_SKILL_CODE: RewriteHelper.learnSkill(player, stream.readInt()); break; case USE_SKILL_CODE: RewriteHelper.useSkill(player); break; } stream.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.kanbekotori.keycraft.network.RewriteNetwork.java
License:Open Source License
/** */ @SubscribeEvent/*from ww w .ja v a 2 s .com*/ public void onClientPacket(ClientCustomPacketEvent event) { EntityPlayer player = MainHelper.getPlayerCl(); ByteBufInputStream stream = new ByteBufInputStream(event.packet.payload()); try { switch (stream.readInt()) { case SYNC_AURORA_POINT_CODE: RewriteHelper.setAuroraPoint(player, stream.readInt()); break; case SYNC_SKILL_CODE: for (int i = 0; i < RewriteHelper.SKILLS.length; i++) { RewriteHelper.learnSkill(player, RewriteHelper.SKILLS[i].id, stream.readBoolean()); } break; } stream.close(); } catch (IOException e) { e.printStackTrace(); } }