Example usage for io.netty.buffer ByteBuf readInt

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

Introduction

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

Prototype

public abstract int readInt();

Source Link

Document

Gets a 32-bit integer at the current readerIndex and increases the readerIndex by 4 in this buffer.

Usage

From source file:com.hazelcast.simulator.protocol.core.SimulatorMessageCodec.java

License:Open Source License

public static SimulatorMessage decodeSimulatorMessage(ByteBuf buffer) {
    int frameLength = buffer.readInt();
    int dataLength = frameLength - HEADER_SIZE;

    if (buffer.readInt() != MAGIC_BYTES) {
        throw new IllegalArgumentException("Invalid magic bytes for SimulatorMessage");
    }//  ww  w  .j a v a2  s.  c  om

    SimulatorAddress destination = decodeSimulatorAddress(buffer);
    SimulatorAddress source = decodeSimulatorAddress(buffer);

    long messageId = buffer.readLong();
    OperationType operationType = OperationType.fromInt(buffer.readInt());

    String operationData = buffer.readSlice(dataLength).toString(UTF_8);

    return new SimulatorMessage(destination, source, messageId, operationType, operationData);
}

From source file:com.heliosapm.ohcrs.core.AbstractDriverCodec.java

License:Apache License

/**
 * {@inheritDoc}/*  www .j av  a2s.  c  om*/
 * @see com.heliosapm.ohcrs.core.DriverCodec#readInt(io.netty.buffer.ByteBuf)
 */
@Override
public Integer readInt(final ByteBuf b) throws SQLException {
    if (checkNull(b))
        return null;
    return b.readInt();
}

From source file:com.heliosapm.ohcrs.core.AbstractDriverCodec.java

License:Apache License

/**
 * {@inheritDoc}/*from  w w w . jav a  2  s  . c o m*/
 * @see com.heliosapm.ohcrs.core.DriverCodec#readint(io.netty.buffer.ByteBuf)
 */
@Override
public int readint(final ByteBuf b) throws SQLException {
    if (checkNull(b))
        return 0;
    return b.readInt();
}

From source file:com.heliosapm.ohcrs.impls.oracle.OracleDriverCodec.java

License:Apache License

@Override
public Datum read(final DBType d, final ByteBuf b) throws SQLException {
    final short typeCode = b.readShort();
    if (checkNull(b))
        return null;
    final int size = b.readInt();
    final byte[] bytes = new byte[size];
    b.readBytes(bytes);//from ww w.  j  av  a2 s. c o  m
    final DBType dbType = DBType.forCode(typeCode);
    switch (dbType) {
    case BIT:
    case BIGINT:
    case DECIMAL:
    case DOUBLE:
    case FLOAT:
    case INTEGER:
    case NUMERIC:
    case TINYINT:
    case SMALLINT:
        return new NUMBER(bytes);
    case DATE:
    case TIME:
        return new oracle.sql.DATE(bytes);
    case TIMESTAMP:
        return new oracle.sql.TIMESTAMP(bytes);
    case ROWID:
        return new oracle.sql.ROWID(bytes);
    case CHAR:
    case NCHAR:
    case VARCHAR:
    case LONGVARCHAR:
    case LONGNVARCHAR:
    case NVARCHAR:
        final int charsetCode = b.readInt();
        final CharacterSet cs = CharacterSet.make(charsetCode);
        return new oracle.sql.CHAR(bytes, cs);
    default:
        throw new UnsupportedOperationException(dbType.name());
        //         case STRUCT:
        //         case BINARY:
        //         case BIT:
        //         case BLOB:
        //         case BOOLEAN:
        //         case CLOB:
        //         case DATALINK:
        //         case DISTINCT:
        //         case JAVA_OBJECT:
        //         case LONGVARBINARY:
        //         case NCLOB:
        //         case NULL:
        //         case OTHER:
        //         case REAL:
        //         case REF:
        //         case SQLXML:
        //         case VARBINARY:
    }
}

From source file:com.hiido.eagle.hes.transfer.FileTransferServer.java

License:Apache License

protected FileStoreInfo createAndStoreFile(ChannelHandlerContext ctx, Object msg) throws Exception {
    ByteBuf in = (ByteBuf) msg;
    int filePathSize = in.readInt();
    String fileName = new String(in.readBytes(filePathSize).array());
    long fileSize = in.readLong();

    String localPath = TransferServerConfig.class.getResource("/").getPath() + fileName;
    logger.info("Start to handler the file [{}] with size [{}b] which be writen to local disk [{}]", fileName,
            fileSize, localPath);/*from   ww w  . ja v a  2s. c om*/

    long currFileSize = in.readableBytes();
    ByteBuffer buf = ByteBuffer.allocate((int) currFileSize);
    in.readBytes(buf);

    RandomAccessFile accessfile = new RandomAccessFile(localPath, "rw");
    FileChannel fileChannel = accessfile.getChannel();
    fileChannel.write(buf);
    return new FileStoreInfo(accessfile, fileChannel, fileName, fileSize, currFileSize);
}

From source file:com.ibm.crail.datanode.netty.rpc.RdmaMsgHeader.java

License:Apache License

public void decodeHeader(ByteBuf src) {
    this.address = src.readLong();
    this.opLength = src.readInt();
    this.stag = src.readInt();
    this.type = src.readInt();
    this.status = src.readInt();
    this.cookie = src.readLong();
}

From source file:com.jadarstudios.rankcapes.forge.network.packet.C1PacketCapePack.java

License:MIT License

@Override
public void read(ByteBuf data) throws IndexOutOfBoundsException {
    this.packSize = data.readInt();
    int length = data.readInt();
    this.packBytes = data.readBytes(length).array();
}

From source file:com.jadarstudios.rankcapes.forge.network.packet.PacketBase.java

License:MIT License

/**
 * Reads a string from a {@link ByteBuf}.
 *
 * @param data the buffer to read from// w  w w. j  a v  a2  s . c  o m
 *
 * @throws IndexOutOfBoundsException thrown if the buffer does not have enough bytes from which to read
 */
public String readString(ByteBuf data) throws IndexOutOfBoundsException {
    int length = data.readInt();
    byte[] stringBytes = new byte[length];
    data.readBytes(stringBytes);

    return new String(stringBytes);
}

From source file:com.jayqqaa12.jbase.tcp.netty.code.DreamJSONDecoder.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    while (true) {

        if (in.readableBytes() <= 4) {
            break;
        }//  w w  w .java 2  s  . c  om
        in.markReaderIndex();
        int length = in.readInt();
        if (length <= 0) {
            throw new Exception("a negative length occurd while decode!");
        }
        if (in.readableBytes() < length) {
            in.resetReaderIndex();
            break;
        }
        byte[] msg = new byte[length];
        in.readBytes(msg);
        out.add(new String(msg, "UTF-8"));
    }

}

From source file:com.kaijin.AdvPowerMan.ClientPacketHandler.java

License:Open Source License

@SubscribeEvent
public void onClientPacket(ClientCustomPacketEvent event) {
    ByteBuf stream = event.packet.payload();
    // DataInputStream stream = new DataInputStream(new
    // ByteArrayInputStream(packet.data));

    // Determine packet type and coordinates of affected tile entity
    int packetType = -1;
    int x = 0;//from  ww  w  .  ja  v a 2s.co m
    int y = 0;
    int z = 0;

    packetType = stream.readInt();
    x = stream.readInt();
    y = stream.readInt();
    z = stream.readInt();

    if (packetType == 0) {
        World world = FMLClientHandler.instance().getClient().theWorld;
        TileEntity tile = world.getTileEntity(x, y, z);

        Exception e;
        try {
            ((TECommon) tile).receiveDescriptionData(packetType, stream);
            return;
        } catch (ClassCastException ex) {
            e = ex;
        } catch (NullPointerException ex) {
            e = ex;
        }
        FMLLog.getLogger()
                .info("[AdvancedPowerManagement] " + "Client received description packet for " + x + ", " + y
                        + ", " + z + " but couldn't deliver to tile entity. (Details: " + e.toString() + ")");
        return;
    }
}