Example usage for io.netty.buffer Unpooled buffer

List of usage examples for io.netty.buffer Unpooled buffer

Introduction

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

Prototype

public static ByteBuf buffer(int initialCapacity) 

Source Link

Document

Creates a new big-endian Java heap buffer with the specified capacity , which expands its capacity boundlessly on demand.

Usage

From source file:com.tesora.dve.mysqlapi.repl.messages.MyLogDeleteRowsPayload.java

License:Open Source License

@Override
public void unmarshallMessage(ByteBuf cb) throws PEException {
    this.heapBuffer = Unpooled.buffer(cb.readableBytes());
    this.heapBuffer.writeBytes(cb);
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyQueryLogEvent.java

License:Open Source License

@Override
public void unmarshallMessage(ByteBuf cb) throws PEException {

    // read event header
    slaveProxyId = cb.readUnsignedInt();
    execTime = cb.readUnsignedInt();/*  w  ww.  ja v  a 2  s .  c o m*/
    dbNameLen = cb.readByte();
    errorCode = cb.readUnsignedShort();
    statusVarsLen = cb.readUnsignedShort();

    statusVars.parseStatusVariables(cb, statusVarsLen);

    dbName = MysqlAPIUtils.readBytesAsString(cb, dbNameLen, CharsetUtil.UTF_8);
    cb.skipBytes(1); //for trailing 0
    query = Unpooled.buffer(cb.readableBytes());
    query.writeBytes(cb);
    origQuery = query.toString(CharsetUtil.UTF_8);
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyTableMapLogEvent.java

License:Open Source License

@Override
public void unmarshallMessage(ByteBuf cb) {
    tableId = cb.readInt();//ww  w.jav a 2s. com
    reserved = cb.readShort();
    // TODO: need to parse out the variable part of the data
    variableData = Unpooled.buffer(cb.readableBytes());
    variableData.writeBytes(cb);
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyUserVarLogEvent.java

License:Open Source License

String processVariableValue(ByteBuf cb) throws PEException {
    String value = StringUtils.EMPTY;

    valueType = MyItemResultCode.fromByte(cb.readByte());
    valueCharSet = cb.readInt();/*from   www  .j  a v  a2  s  .  c  om*/
    valueLen = cb.readInt();
    valueBytes = Unpooled.buffer(cb.readableBytes()).order(ByteOrder.LITTLE_ENDIAN);
    valueBytes.writeBytes(cb);

    switch (valueType) {
    case DECIMAL_RESULT:
        value = processDecimalValue(valueBytes, valueLen);
        break;
    case INT_RESULT:
        value = processIntValue(valueBytes, valueLen);
        break;
    case REAL_RESULT:
        value = Double.toString(valueBytes.readDouble());
        break;
    case STRING_RESULT:
        value = "'" + StringUtils.replace(
                MysqlAPIUtils.readBytesAsString(valueBytes, valueLen, CharsetUtil.UTF_8), "'", "''") + "'";
        break;
    case ROW_RESULT:
    default:
        throw new PEException(
                "Unsupported variable type '" + valueType + "' for variable '" + variableName + "'");
    }
    return value;
}

From source file:com.tesora.dve.server.connectionmanager.loaddata.LoadDataBlockExecutor.java

License:Open Source License

static void buildInsertStatement(MyLoadDataInfileContext loadDataInfileContext, List<byte[]> cols,
        List<Object> params) throws PEException {
    if (logger.isDebugEnabled()) {
        logger.debug("Processing datablock: col length = " + cols.size() + ", projection length = "
                + loadDataInfileContext.getProjection().size());
    }//www .  j av a 2  s .c  om

    if (cols.size() < loadDataInfileContext.getProjection().size()) {
        // pad out the remaining columns with empty values
        for (int i = 0; i < loadDataInfileContext.getProjection().size() - cols.size(); i++) {
            cols.add(Unpooled.buffer(0).array());
        }
    }

    if (cols.size() > loadDataInfileContext.getProjection().size()) {
        // mysql lops off the excess columns
        for (int i = cols.size(); i > loadDataInfileContext.getProjection().size(); i--) {
            cols.remove(i - 1);
        }
    }

    if (cols.size() != loadDataInfileContext.getProjection().size()) {
        // should never happen...
        List<String> colData = new ArrayList<String>();
        for (byte[] data : cols) {
            colData.add(new String(data));
        }
        throw new PEException(
                "Expected " + loadDataInfileContext.getProjection().size() + " columns but parsed "
                        + cols.size() + " columns for row data '" + StringUtils.join(colData, ",") + "'");
    }

    ValueConverter converter = ValueConverter.INSTANCE;
    for (int i = 0; i < loadDataInfileContext.getProjection().size(); i++) {
        Object value = null;
        if (cols.get(i).length > 0) {
            value = converter.convert(PECharsetUtils.getString(cols.get(i), loadDataInfileContext.getCharset()),
                    loadDataInfileContext.getProjection().get(i).getType());
            String v = DBTypeBasedUtils.getMysqlTypeFunc(MyFieldType.mapFromNativeType(
                    loadDataInfileContext.getProjection().get(i).getType().getMysqlType().getMysqlType()))
                    .getParamReplacement(value, false);
            if (loadDataInfileContext.getProjection().get(i).getType().isStringType()) {
                v = "'" + StringUtils.replace(PEStringUtils.dequote(v), "'", "\\'") + "'";
            }
            params.add(v);
        } else {
            if (loadDataInfileContext.getProjection().get(i).getType().isStringType()) {
                params.add("''");
            }
        }
    }
}

From source file:com.test.comm.handler.ClientHandler.java

License:Apache License

/**
 * Creates a client-side handler.//from w  w  w  .  j a v  a  2s.c  om
 */
public ClientHandler() {
    firstMessage = Unpooled.buffer(1024);
    for (int i = 0; i < firstMessage.capacity(); i++) {
        firstMessage.writeByte((byte) i);
    }
}

From source file:com.test.zp.netty.EchoClientHandler.java

License:Apache License

/**
 * Creates a client-side handler./*from  w w w.j  a v a  2s . c o m*/
 */
public EchoClientHandler() {
    firstMessage = Unpooled.buffer(EchoClient.SIZE);
    //        for (int i = 0; i < firstMessage.capacity(); i ++) {
    //            firstMessage.writeByte((byte) i);
    //        }
    firstMessage.writeBytes("hello world".getBytes());
}

From source file:com.thomas.netty4.SimpleEchoClientProducerHandler.java

License:Apache License

public ByteBuf genMessage() {
    firstMessage = Unpooled.buffer(SimpleEchoClient.SIZE);
    for (int i = 0; i < firstMessage.capacity(); i++) {
        firstMessage.writeByte((byte) i);
    }//from  ww w  .  j av a  2 s  .c o m
    return firstMessage;
}

From source file:com.topsec.bdc.platform.api.test.echo.EchoClientHandler.java

License:Apache License

/**
 * Creates a client-side handler./*from w w  w .  j a  v a2s.  c o  m*/
 */
public EchoClientHandler() {

    firstMessage = Unpooled.buffer(EchoClient.SIZE);
    for (int i = 0; i < firstMessage.capacity(); i++) {
        firstMessage.writeByte((byte) i);
    }
}

From source file:com.trinity.engine.protocol.MessageLookupService.java

License:Apache License

/**
 * Encodes a message into a stream//from  w w  w.  j a  va  2s . co m
 *
 * @param message the message to encode to the buffer
 * @return a wrapped buffer that contains the header and the body of the message
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public <T extends Message> ByteBuf encode(T message) throws IOException {
    final MessageCodec<Message> codec = (MessageCodec<Message>) getCodec(message.getClass());
    if (codec == null) {
        throw new IOException("Unknown operation class: " + message.getClass());
    }
    final ByteBuf body = codec.encode(message);
    final ByteBuf header = Unpooled.buffer(3).writeByte(codec.getOpcode()).writeShort(body.capacity());
    return Unpooled.wrappedBuffer(header, body);
}