Example usage for io.netty.buffer Unpooled wrappedBuffer

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

Introduction

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

Prototype

public static ByteBuf wrappedBuffer(ByteBuffer... buffers) 

Source Link

Document

Creates a new big-endian composite buffer which wraps the slices of the specified NIO buffers without copying them.

Usage

From source file:io.jsql.mysql.handler.MysqlAuthHander.java

License:Open Source License

protected void success(AuthPacket auth) {
    source.authenticated = true;//from   w ww.  j a  v a 2 s .c o  m
    source.user = auth.user;
    source.schema = auth.database;
    source.charsetIndex = (auth.charsetIndex);
    source.charset = CharsetUtil.getCharset(source.charsetIndex);

    if (LOGGER.isInfoEnabled()) {
        StringBuilder s = new StringBuilder();
        s.append(source).append('\'').append(auth.user).append("' login success");
        byte[] extra = auth.extra;
        if (extra != null && extra.length > 0) {
            s.append(",extra:").append(new String(extra));
        }
        LOGGER.info(s.toString());
    }

    //        ByteBuffer buffer = source.allocate();
    //        source.write(source.writeToBuffer(AUTH_OK, buffer));
    source.write(Unpooled.wrappedBuffer(AUTH_OK));
    //        boolean clientCompress = Capabilities.CLIENT_COMPRESS==(Capabilities.CLIENT_COMPRESS & auth.clientFlags);
    //        boolean usingCompress = false;
    //        if(clientCompress&&usingCompress)
    //        {
    ////            source.setSupportCompress(true);
    //        }
}

From source file:io.jsql.mysql.mysql.ErrorPacket.java

License:Open Source License

@Override
public void write(Channel channel) {
    channel.writeAndFlush(Unpooled.wrappedBuffer(writeToBytes2()));
}

From source file:io.jsql.orientserver.handler.tx_and_lock.BeginHandler.java

License:Open Source License

public static void handle(String stmt, OConnection c) {
    if (c.autocommit) {
        c.autocommit = (false);// w  w w .jav  a 2s. c  o m
        c.write(Unpooled.wrappedBuffer(AC_OFF));
    } else {
        c.writeok();
    }
}

From source file:io.jsql.orientserver.handler.tx_and_lock.StartHandler.java

License:Open Source License

public static void handle(String stmt, OConnection c, int offset) {

    if (c.autocommit) {
        c.autocommit = (false);//from   ww w.j  a v  a  2 s  .com
        c.write(Unpooled.wrappedBuffer(AC_OFF));
    } else {
        //                    c.getSession2().commit();
        c.writeok();
    }

}

From source file:io.jsql.orientserver.OConnection.java

License:Open Source License

public void close(String reason) {
    //        super.close(reason);
    //        if (getLoadDataInfileHandler() != null) {
    //            getLoadDataInfileHandler().clear();
    //        }//from   www. ja  v a  2 s .c om
    if (channelHandlerContext.channel().isActive()) {
        write(Unpooled.wrappedBuffer(reason.getBytes()));

    }
    channelHandlerContext.close();
}

From source file:io.jsql.orientserver.OConnection.java

License:Open Source License

public void writeok() {
    write(Unpooled.wrappedBuffer(OkPacket.OK));
}

From source file:io.lettuce.core.protocol.CommandHandlerTest.java

License:Apache License

@Test
public void shouldRecordCorrectFirstResponseLatency() throws Exception {

    ChannelPromise channelPromise = new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE);
    channelPromise.setSuccess();//from www .  j a v a  2s  .  com

    sut.channelRegistered(context);
    sut.channelActive(context);

    LatencyMeteredCommand<String, String, String> wrapped = new LatencyMeteredCommand<>(command);

    sut.write(context, wrapped, channelPromise);
    Thread.sleep(10);

    sut.channelRead(context, Unpooled.wrappedBuffer("*1\r\n+OK\r\n".getBytes()));

    verify(latencyCollector).recordCommandLatency(any(), any(), eq(CommandType.APPEND), gt(0L), gt(0L));

    sut.channelUnregistered(context);
}

From source file:io.lettuce.core.pubsub.PubSubCommandHandlerTest.java

License:Apache License

@Test
public void shouldCompleteCommandExceptionallyOnOutputFailure() throws Exception {

    sut.channelRegistered(context);// w  w w.j  a  va  2 s. com
    sut.channelActive(context);
    stack.add(command);

    sut.channelRead(context, Unpooled.wrappedBuffer(":1000\r\n".getBytes()));

    assertThat(ReflectionTestUtils.getField(command, "exception")).isInstanceOf(IllegalStateException.class);
}

From source file:io.lettuce.core.pubsub.PubSubCommandHandlerTest.java

License:Apache License

@Test
public void shouldDecodeRegularCommand() throws Exception {

    sut.channelRegistered(context);// w  ww  .  j a v  a  2s  .co  m
    sut.channelActive(context);
    stack.add(command);

    sut.channelRead(context, Unpooled.wrappedBuffer("+OK\r\n".getBytes()));

    assertThat(command.get()).isEqualTo("OK");
}

From source file:io.lettuce.core.pubsub.PubSubCommandHandlerTest.java

License:Apache License

@Test
public void shouldDecodeTwoCommands() throws Exception {

    Command<String, String, String> command1 = new Command<>(CommandType.APPEND,
            new StatusOutput<>(new Utf8StringCodec()), null);
    Command<String, String, String> command2 = new Command<>(CommandType.APPEND,
            new StatusOutput<>(new Utf8StringCodec()), null);

    sut.channelRegistered(context);//from w  w  w  .  j a  va2 s. co  m
    sut.channelActive(context);
    stack.add(command1);
    stack.add(command2);

    sut.channelRead(context, Unpooled.wrappedBuffer("+OK\r\n+YEAH\r\n".getBytes()));

    assertThat(command1.get()).isEqualTo("OK");
    assertThat(command2.get()).isEqualTo("YEAH");
}