Example usage for io.netty.buffer ByteBuf readBytes

List of usage examples for io.netty.buffer ByteBuf readBytes

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf readBytes.

Prototype

public abstract ByteBuf readBytes(ByteBuffer dst);

Source Link

Document

Transfers this buffer's data to the specified destination starting at the current readerIndex until the destination's position reaches its limit, and increases the readerIndex by the number of the transferred bytes.

Usage

From source file:eu.matejkormuth.rpgdavid.starving.remote.netty.packets.DisconnectPacket.java

License:Open Source License

@Override
public void readFrom(ByteBuf fromBuffer) {
    short length = fromBuffer.readShort();
    byte[] array = new byte[length];
    fromBuffer.readBytes(array);
    this.reason = new String(array, PROTOCOL_ENCODING);
}

From source file:eu.matejkormuth.rpgdavid.starving.remote.netty.packets.HandshakePacket.java

License:Open Source License

@Override
public void readFrom(ByteBuf fromBuffer) {
    byte[] nickname = new byte[fromBuffer.readByte()];
    fromBuffer.readBytes(nickname);
    byte[] accesskey = new byte[fromBuffer.readByte()];
    fromBuffer.readBytes(accesskey);/*  w w  w .jav  a 2  s  .c om*/
    this.nickname = new String(nickname, PROTOCOL_ENCODING);
    this.accesskey = new String(accesskey, PROTOCOL_ENCODING);
}

From source file:eu.matejkormuth.rpgdavid.starving.remote.netty.packets.WGFiltersPacket.java

License:Open Source License

@Override
public void readFrom(ByteBuf fromBuffer) {
    byte filterCount = fromBuffer.readByte();
    FilterRepresentation[] filters = new FilterRepresentation[filterCount];
    for (int i = 0; i < filterCount; i++) {
        filters[i] = new FilterRepresentation();
        byte nameLength = fromBuffer.readByte();
        byte[] nameBuffer = new byte[nameLength];
        fromBuffer.readBytes(nameBuffer);
        filters[i].name = new String(nameBuffer, PROTOCOL_ENCODING);
        byte propertiesCount = fromBuffer.readByte();
        filters[i].properties = new FilterPropertyRepresentaion[propertiesCount];
        for (int p = 0; p < propertiesCount; p++) {
            byte propertyNameLength = fromBuffer.readByte();
            byte[] propertyNameBuffer = new byte[propertyNameLength];
            fromBuffer.readBytes(propertyNameBuffer);
            filters[i].properties[p] = new FilterPropertyRepresentaion();
            filters[i].properties[p].name = new String(propertyNameBuffer, PROTOCOL_ENCODING);
            filters[i].properties[p].type = fromBuffer.readByte();
        }/*from  www. jav a2s . co  m*/
    }
}

From source file:eu.stratosphere.runtime.io.network.netty.InboundEnvelopeDecoder.java

License:Apache License

/**
 * Copies min(from.readableBytes(), to.remaining() bytes from Nettys ByteBuf to the Java NIO ByteBuffer.
 */// w w  w .  ja va  2  s . c  om
private void copy(ByteBuf src, ByteBuffer dst) {
    // This branch is necessary, because an Exception is thrown if the
    // destination buffer has more remaining (writable) bytes than
    // currently readable from the Netty ByteBuf source.
    if (src.isReadable()) {
        if (src.readableBytes() < dst.remaining()) {
            int oldLimit = dst.limit();

            dst.limit(dst.position() + src.readableBytes());
            src.readBytes(dst);
            dst.limit(oldLimit);
        } else {
            src.readBytes(dst);
        }
    }
}

From source file:eu.stratosphere.runtime.io.network.netty.InboundEnvelopeDecoder.java

License:Apache License

/**
 * Skips over min(in.readableBytes(), toSkip) bytes in the Netty ByteBuf and returns how many bytes remain to be
 * skipped./*from w ww .j  av  a  2s . c  om*/
 *
 * @return remaining bytes to be skipped
 */
private int skipBytes(ByteBuf in, int toSkip) {
    if (toSkip <= in.readableBytes()) {
        in.readBytes(toSkip);
        return 0;
    }

    int remainingToSkip = toSkip - in.readableBytes();
    in.readerIndex(in.readerIndex() + in.readableBytes());

    return remainingToSkip;
}

From source file:eu.xworlds.util.raknet.protocol.BaseMessage.java

License:Open Source License

/**
 * Reads string from byte buf with usigned short length and utf8 encoding.
 * /*from  w  ww .j  a  va  2s  .c  o  m*/
 * @param src source byte buffer
 * @return string
 */
protected String readStringUtf8UShort(ByteBuf src) {
    final int length = src.readUnsignedShort();
    return new String(src.readBytes(length).array(), StandardCharsets.UTF_8);
}

From source file:eu.xworlds.util.raknet.protocol.ConnectionRequest.java

License:Open Source License

@Override
protected void parseMessage(ByteBuf buf) {
    this.clientGuid = readGuid(buf);
    this.time = readTime(buf);
    this.doSecurity = buf.readBoolean();
    if (this.doSecurity) {
        this.proof = new byte[32]; // TODO have a constant value of the size
        buf.readBytes(this.proof);
        this.doIdentity = buf.readBoolean();
        if (this.doIdentity) {
            this.identity = new byte[EASYHANDSHAKE_IDENTITY_BYTES];
            buf.readBytes(this.identity);
        }/*from  w w w. j a v a 2 s  .  c o  m*/
    }
}

From source file:eu.xworlds.util.raknet.protocol.InvalidRaknetMessage.java

License:Open Source License

@Override
protected void parseMessage(ByteBuf buf) {
    this.payload = buf.readBytes(Math.min(1500, buf.readableBytes())).array();
}

From source file:eu.xworlds.util.raknet.protocol.OpenConnectionReply1.java

License:Open Source License

@Override
protected void parseMessage(ByteBuf buf) {
    this.magic = new byte[MAGIC_BYTES];
    buf.readBytes(this.magic);
    this.serverGuid = readGuid(buf);
    this.hasSecurity = buf.readBoolean();
    if (this.hasSecurity) {
        this.securityCookie = buf.readInt();
        this.publicKey = new byte[EASYHANDSHAKE_PUBLIC_KEY_BYTES];
        buf.readBytes(this.publicKey);
    }//from   ww w.j  a va 2  s  .  c  o m
    this.mtuSize = buf.readUnsignedShort();
}

From source file:eu.xworlds.util.raknet.protocol.OpenConnectionReply2.java

License:Open Source License

@Override
protected void parseMessage(ByteBuf buf) {
    this.magic = new byte[MAGIC_BYTES];
    buf.readBytes(this.magic);
    this.serverGuid = readGuid(buf);
    this.port = buf.readUnsignedShort();
    this.mtuSize = buf.readUnsignedShort();
    this.doSecurity = buf.readBoolean();
    if (this.doSecurity) {
        this.securityAnswer = new byte[EASYHANDSHAKE_ANSWER_BYTES];
        buf.readBytes(this.securityAnswer);
    }/*from ww  w  .  j a v a  2  s  .  c  o m*/
}