Example usage for io.netty.buffer ByteBuf writeCharSequence

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

Introduction

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

Prototype

public abstract int writeCharSequence(CharSequence sequence, Charset charset);

Source Link

Document

Writes the specified CharSequence at the current writerIndex and increases the writerIndex by the written bytes.

Usage

From source file:org.traccar.protocol.WristbandProtocolDecoder.java

License:Apache License

private void sendResponse(Channel channel, String imei, String version, int type, String data) {

    if (channel != null) {
        String sentence = String.format("YX%s|%s|0|{F%02d#%s}\r\n", imei, version, type, data);
        ByteBuf response = Unpooled.buffer();
        if (type != 91) {
            response.writeBytes(new byte[] { 0x00, 0x01, 0x02 });
            response.writeShort(sentence.length());
        }/*from   ww w.  java2 s.c om*/
        response.writeCharSequence(sentence, StandardCharsets.US_ASCII);
        if (type != 91) {
            response.writeBytes(new byte[] { (byte) 0xFF, (byte) 0xFE, (byte) 0xFC });
        }
        channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress()));
    }
}