本文整理匯總了Java中io.netty.buffer.ByteBuf.isReadable方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteBuf.isReadable方法的具體用法?Java ByteBuf.isReadable怎麽用?Java ByteBuf.isReadable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.buffer.ByteBuf
的用法示例。
在下文中一共展示了ByteBuf.isReadable方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: deserialize
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void deserialize(ByteBuf buf) {
super.deserialize(buf);
if (buf.isReadable()) {
int size = buf.readInt();
byte[] data = new byte[size];
buf.readBytes(data);
String partResultClassName = new String(data);
try {
partResult = (PartitionGetResult) Class.forName(partResultClassName).newInstance();
partResult.deserialize(buf);
} catch (Exception e) {
LOG.fatal("deserialize PartitionAggrResult falied, ", e);
}
}
}
示例2: readEIP8Packet
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private byte[] readEIP8Packet(ByteBuf buffer, byte[] plainPacket) {
int size = bigEndianToShort(plainPacket);
if (size < plainPacket.length)
throw new IllegalArgumentException("AuthResponse packet size is too low");
int bytesLeft = size - plainPacket.length + 2;
byte[] restBytes = new byte[bytesLeft];
if (!buffer.isReadable(restBytes.length))
return null;
buffer.readBytes(restBytes);
byte[] fullResponse = new byte[size + 2];
System.arraycopy(plainPacket, 0, fullResponse, 0, plainPacket.length);
System.arraycopy(restBytes, 0, fullResponse, plainPacket.length, restBytes.length);
return fullResponse;
}
示例3: decodeProcess
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private String[] decodeProcess ( final ByteBuf msg )
{
// split by colon
final int spaceIndex = msg.bytesBefore ( COLON );
if ( spaceIndex < 0 )
{
throw new CodecException ( "Unable to find process name" );
}
final String process = msg.readSlice ( spaceIndex ).toString ( StandardCharsets.US_ASCII );
msg.skipBytes ( 1 ); // COLON
if ( msg.isReadable () )
{
msg.skipBytes ( 1 ); // SPACE
}
final Matcher m = PROCESS_PATTERN.matcher ( process );
if ( m.matches () )
{
return new String[] { m.group ( 1 ), m.group ( 2 ) };
}
return new String[] { process };
}
示例4: readEIP8Packet
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private byte[] readEIP8Packet(ByteBuf buffer, byte[] plainPacket) {
int size = bigEndianToShort(plainPacket);
if (size < plainPacket.length) {
throw new IllegalArgumentException("AuthResponse packet size is too low");
}
int bytesLeft = size - plainPacket.length + 2;
byte[] restBytes = new byte[bytesLeft];
if (!buffer.isReadable(restBytes.length)) {
return null;
}
buffer.readBytes(restBytes);
byte[] fullResponse = new byte[size + 2];
System.arraycopy(plainPacket, 0, fullResponse, 0, plainPacket.length);
System.arraycopy(restBytes, 0, fullResponse, plainPacket.length, restBytes.length);
return fullResponse;
}
示例5: decrypt
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void decrypt(ByteBuf buf)
{
if (!_isEnabled)
{
onPacketReceive(buf);
return;
}
int a = 0;
while (buf.isReadable())
{
final int b = buf.readByte() & 0xFF;
buf.setByte(buf.readerIndex() - 1, b ^ _inKey[(buf.readerIndex() - 1) & 15] ^ a);
a = b;
}
shiftKey(_inKey, buf.writerIndex());
onPacketReceive(buf);
}
示例6: deserialize
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void deserialize(ByteBuf buf) {
matrixId = buf.readInt();
if (buf.isReadable()) {
if (partKey == null) {
partKey = new PartitionKey();
}
partKey.deserialize(buf);
}
}
示例7: channelRead
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void channelRead(ChannelHandlerContext channelHandlerContext, Object msg) throws Exception {
if (!(msg instanceof ByteBuf)) {
throw new RuntimeException("Object is not a *ByteBuf");
}
ByteBuf data = (ByteBuf) msg;
PacketSerializer serializer = new PacketSerializer(data);
while (data.isReadable()) {
packetCounter.incrementAndGet();
int length = PacketSerializer.readVarInt(data);
int packetID = serializer.readVarInt();
Supplier<? extends Packet> packetSupplier = protocol.getServerboundPacketSupplier(packetID);
if (packetSupplier == null) {
UnknownPandaServer.getLogger().info("------ new Packet ------");
UnknownPandaServer.getLogger().info("PacketCnt: " + packetCounter.get());
UnknownPandaServer.getLogger().info("PacketID: 0x" + Integer.toHexString(packetID) + " w/ numeric: " + packetID);
UnknownPandaServer.getLogger().info("Length: " + length);
UnknownPandaServer.getLogger().info("Supplier: Unknown");
serializer.clear();
return;
}
Packet packet = packetSupplier.get();
packet.packetId = packetID;
packet.receive(serializer);
super.channelRead(channelHandlerContext, packet);
}
data.release();
}
示例8: decode
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void decode( ChannelHandlerContext channelHandlerContext, ByteBuf input, List<Object> output ) throws Exception {
input.markReaderIndex();
byte[] bytes = new byte[3];
for ( int i = 0; i < bytes.length; i++ ) {
if ( !input.isReadable() ) {
input.resetReaderIndex();
return;
}
bytes[i] = input.readByte();
if ( bytes[i] >= 0 ) {
ByteBuf buf = Unpooled.wrappedBuffer( bytes );
try {
int j = Message.readVarInt( buf );
if ( input.readableBytes() < j ) {
input.resetReaderIndex();
return;
}
output.add( input.readBytes( j ) );
return;
} finally {
buf.release();
}
}
}
throw new CorruptedFrameException( "length wider than 21-bit" );
}
示例9: readJagString
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
* Converts data from a {@link ByteBuf} into a readable jag string.
*
* @param buffer The {@link ByteBuf}.
* @return The string.
*/
public static String readJagString(ByteBuf buffer) {
StringBuilder bldr = new StringBuilder();
byte b;
buffer.readByte();
while (buffer.isReadable() && (b = buffer.readByte()) != STRING_TERMINATOR) {
bldr.append((char) b);
}
return bldr.toString();
}
示例10: decode
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (!in.isReadable() || in.readableBytes() < 4) {
return;
}
out.add(new HandshakeRequest(this, in.readInt()));// version
}
示例11: encode
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out)
{
// Check if there are any data to encrypt.
if (!msg.isReadable())
{
return;
}
msg.resetReaderIndex();
_crypt.encrypt(msg);
msg.resetReaderIndex();
out.writeBytes(msg);
}
示例12: fromBytes
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void fromBytes(ByteBuf buffer)
{
this.hasMore = buffer.readBoolean();
this.name = new ResourceLocation(ByteBufUtils.readUTF8String(buffer));
int length = ByteBufUtils.readVarInt(buffer, 3);
ids = Maps.newHashMap();
for (int i = 0; i < length; i++)
{
ids.put(new ResourceLocation(ByteBufUtils.readUTF8String(buffer)), ByteBufUtils.readVarInt(buffer, 3));
}
length = ByteBufUtils.readVarInt(buffer, 3);
substitutions = Sets.newHashSet();
for (int i = 0; i < length; i++)
{
substitutions.add(new ResourceLocation(ByteBufUtils.readUTF8String(buffer)));
}
dummied = Sets.newHashSet();
// if the dummied list isn't present - probably an older server
if (!buffer.isReadable()) return;
length = ByteBufUtils.readVarInt(buffer, 3);
for (int i = 0; i < length; i++)
{
dummied.add(new ResourceLocation(ByteBufUtils.readUTF8String(buffer)));
}
//if (!buffer.isReadable()) return; // In case we expand
}
示例13: decode
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void decode(ChannelHandlerContext ctx, ByteBuf buf,
List<Object> out) throws Exception {
if (buf.readableBytes() < 2) {
return;
}
buf.markReaderIndex();
buf.readByte(); // read away header
int msgLength = 0;
int multiplier = 1;
int digit;
int lengthSize = 0;
do {
lengthSize++;
digit = buf.readByte();
msgLength += (digit & 0x7f) * multiplier;
multiplier *= 128;
if ((digit & 0x80) > 0 && !buf.isReadable()) {
buf.resetReaderIndex();
return;
}
} while ((digit & 0x80) > 0);
if (buf.readableBytes() < msgLength) {
buf.resetReaderIndex();
return;
}
byte[] data = new byte[1 + lengthSize + msgLength];
buf.resetReaderIndex();
buf.readBytes(data);
MessageInputStream mis = new MessageInputStream(
new ByteArrayInputStream(data));
Message msg = mis.readMessage();
mis.close();
out.add(msg);
}
示例14: decode
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (!in.isReadable() || !player.getChannel().isRegistered()) {
return;
}
int opcode = in.readUnsignedByte();
Optional<PacketDecoderIdentifier> data = PacketDecoderIdentifier.getPacket(opcode);
if (data.isPresent()) {
PacketDecoderIdentifier packet = data.get();
int size = packet.getSize();
if (packet.getType() == PacketType.VARIABLE_BYTE) {
if (in.readableBytes() < 1) {
return;
}
size = in.readUnsignedByte();
} else if (packet.getType() == PacketType.VARIABLE_SHORT) {
if (in.readableBytes() < 2) {
return;
}
size = in.readUnsignedShort();
}
if (in.readableBytes() >= size) {
if (size < 0) {
return;
}
byte[] bytes = new byte[size];
in.readBytes(bytes, 0, size);
out.add(new GamePacketRequest(this, player, packet.getId(), new GamePacketReader(Unpooled.wrappedBuffer(bytes))));
}
} else {
System.out.println("No data present for incoming packet: " + opcode + ".");
in.readBytes(new byte[in.readableBytes()]);
}
}
示例15: readLine
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private String readLine(ByteBuf in) {
while (in.isReadable()) {
byte b = in.readByte();
byteBuf.writeByte(b);
lineBuf.append((char) b);
int len = lineBuf.length();
if (len >= 2 && lineBuf.substring(len - 2).equals("\r\n")) {
String line = lineBuf.substring(0, len - 2);
lineBuf.delete(0, len);
return line;
}
}
return null;
}