List of usage examples for io.netty.buffer Unpooled EMPTY_BUFFER
ByteBuf EMPTY_BUFFER
To view the source code for io.netty.buffer Unpooled EMPTY_BUFFER.
Click Source Link
From source file:org.waarp.openr66.protocol.localhandler.packet.DataPacket.java
License:Open Source License
/** * @param headerLength//from w w w .j a v a2s . c om * @param middleLength * @param endLength * @param buf * @return the new DataPacket from buffer * @throws OpenR66ProtocolPacketException */ public static DataPacket createFromBuffer(int headerLength, int middleLength, int endLength, ByteBuf buf) throws OpenR66ProtocolPacketException { if (headerLength - 1 <= 0) { throw new OpenR66ProtocolPacketException("Not enough data"); } if (middleLength <= 0) { throw new OpenR66ProtocolPacketException("Not enough data"); } int packetRank = buf.readInt(); ByteBuf data = buf.readSlice(middleLength); data.retain(); ByteBuf key; if (endLength > 0) { key = buf.readSlice(endLength); key.retain(); } else { key = Unpooled.EMPTY_BUFFER; } return new DataPacket(packetRank, data, key); }
From source file:org.waarp.openr66.protocol.localhandler.packet.DataPacket.java
License:Open Source License
/** * @param packetRank//from w ww. ja va 2s . c o m * @param data * @param key */ public DataPacket(int packetRank, ByteBuf data, ByteBuf key) { this.packetRank = packetRank; this.data = data; this.key = key == null ? Unpooled.EMPTY_BUFFER : key; lengthPacket = data.readableBytes(); }
From source file:org.waarp.openr66.protocol.localhandler.packet.DataPacket.java
License:Open Source License
/** * //from www .j a v a 2 s. c o m * @return True if the Hashed key is valid (or no key is set) */ public boolean isKeyValid(DigestAlgo algo) { if (key == null || key == Unpooled.EMPTY_BUFFER) { return true; } ByteBuf newbufkey = FileUtils.getHash(data, algo); boolean check = key.equals(newbufkey); newbufkey.release(); return check; }
From source file:org.waarp.openr66.protocol.localhandler.packet.EndRequestPacket.java
License:Open Source License
@Override public void createEnd(LocalChannelReference lcr) { if (optional == null) { end = Unpooled.EMPTY_BUFFER; } else {//w w w . j a v a 2s .c o m end = Unpooled.copiedBuffer(optional, Charset.defaultCharset()); } }
From source file:org.waarp.openr66.protocol.localhandler.packet.EndTransferPacket.java
License:Open Source License
@Override public void createEnd(LocalChannelReference lcr) { if (hashOptional == null) { end = Unpooled.EMPTY_BUFFER; } else {// www .ja va2 s .c o m end = Unpooled.copiedBuffer(hashOptional, Charset.defaultCharset()); } }
From source file:org.waarp.openr66.protocol.localhandler.packet.KeepAlivePacket.java
License:Open Source License
@Override public void createEnd(LocalChannelReference lcr) { end = Unpooled.EMPTY_BUFFER; }
From source file:org.waarp.openr66.protocol.localhandler.packet.KeepAlivePacket.java
License:Open Source License
@Override public void createHeader(LocalChannelReference lcr) { header = Unpooled.EMPTY_BUFFER; }
From source file:org.waarp.openr66.protocol.localhandler.packet.NoOpPacket.java
License:Open Source License
@Override public void createMiddle(LocalChannelReference lcr) { middle = Unpooled.EMPTY_BUFFER; }
From source file:org.waarp.openr66.protocol.localhandler.packet.ShutdownPacket.java
License:Open Source License
@Override public void createMiddle(LocalChannelReference lcr) throws OpenR66ProtocolPacketException { if (restart != 0) { byte[] array = { restart }; middle = Unpooled.wrappedBuffer(array); } else {/*from w ww. j a va2s.co m*/ middle = Unpooled.EMPTY_BUFFER; } }
From source file:org.waarp.openr66.protocol.utils.ChannelUtils.java
License:Open Source License
/** * //from ww w . j av a2 s. c om * @param localChannelReference * @param block * @return the ChannelFuture of this write operation * @throws OpenR66ProtocolPacketException */ public static ChannelFuture writeBackDataBlock(LocalChannelReference localChannelReference, DataBlock block) throws OpenR66ProtocolPacketException { ByteBuf md5 = Unpooled.EMPTY_BUFFER; DbTaskRunner runner = localChannelReference.getSession().getRunner(); if (RequestPacket.isMD5Mode(runner.getMode())) { md5 = FileUtils.getHash(block.getBlock(), Configuration.configuration.getDigest()); } if (runner.getRank() % 100 == 1 || localChannelReference.getSessionState() != R66FiniteDualStates.DATAS) { localChannelReference.sessionNewState(R66FiniteDualStates.DATAS); } DataPacket data = new DataPacket(runner.getRank(), block.getBlock(), md5);// was block.getBlock().copy() ChannelFuture future = writeAbstractLocalPacket(localChannelReference, data, false); runner.incrementRank(); return future; }