Example usage for io.netty.buffer ByteBuf writerIndex

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

Introduction

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

Prototype

public abstract int writerIndex();

Source Link

Document

Returns the writerIndex of this buffer.

Usage

From source file:io.nodyn.buffer.Buffer.java

License:Apache License

public static long copy(JSObject src, JSObject target, int targetStart, int sourceStart, int sourceEnd) {

    ByteBuf srcBuf = extract(src);/*from  ww w.ja va2 s.  c om*/
    ByteBuf targetBuf = extract(target);

    int origWriter = targetBuf.writerIndex();

    targetBuf.writerIndex(targetStart);

    int len = sourceEnd - sourceStart;

    len = Math.min(len, bufLen(target) - targetStart);

    targetBuf.writeBytes(srcBuf, sourceStart, len);
    targetBuf.writerIndex(Math.max(targetBuf.writerIndex(), origWriter));

    return len;
}

From source file:io.nodyn.buffer.Buffer.java

License:Apache License

public static long[] utf8Write(JSObject object, String str, int offset, int len) {
    ByteBuf b = extract(object);
    int origWriter = b.writerIndex();
    byte[] bytes = str.getBytes(UTF8);
    b.writerIndex(offset);//  w  w  w .j  ava  2 s.  c o m
    len = Math.min(bytes.length, Math.min(len, bufLen(object) - offset));
    b.writeBytes(bytes, 0, len);
    b.writerIndex(Math.max(b.writerIndex(), origWriter));
    return new long[] { str.length(), len };
}

From source file:io.nodyn.buffer.Buffer.java

License:Apache License

public static long asciiWrite(JSObject object, String str, int offset, int len) {
    ByteBuf b = extract(object);
    int origWriter = b.writerIndex();
    byte[] bytes = str.getBytes(ASCII);
    len = Math.min(bytes.length, Math.min(len, b.writableBytes()));
    b.writeBytes(bytes, 0, len);//w  w  w  .ja  v  a  2  s. com
    b.writerIndex(Math.max(b.writerIndex(), origWriter));
    return len;
}

From source file:io.nodyn.buffer.Buffer.java

License:Apache License

public static long ucs2Write(JSObject object, String str, int offset, int len) {
    ByteBuf b = extract(object);
    int origWriter = b.writerIndex();
    byte[] bytes = str.getBytes(UCS2);
    len = Math.min(bytes.length, Math.min(len, b.writableBytes()));
    b.writeBytes(bytes, 0, len);// w ww.j av  a2 s.  c  o m
    b.writerIndex(Math.max(b.writerIndex(), origWriter));
    return len;
}

From source file:io.nodyn.buffer.Buffer.java

License:Apache License

public static long hexWrite(JSObject object, String str, int offset, int len) {
    ByteBuf b = extract(object);
    int origWriter = b.writerIndex();
    byte[] bytes = Hex.decode(str);
    b.writerIndex(offset);// w w w.j a v  a 2  s .c o m
    len = Math.min(bytes.length, Math.min(len, b.writableBytes()));
    b.writeBytes(bytes, 0, len);
    b.writerIndex(Math.max(b.writerIndex(), origWriter));
    return len;
}

From source file:io.nodyn.buffer.Buffer.java

License:Apache License

public static long base64Write(JSObject object, String str, int offset, int len) {
    ByteBuf b = extract(object);
    int origWriter = b.writerIndex();
    byte[] bytes = Base64.decode(str);
    b.writerIndex(offset);//from ww  w .j a  v a 2s. c o m
    len = Math.min(bytes.length, Math.min(len, b.writableBytes()));
    b.writeBytes(bytes, 0, len);
    b.writerIndex(Math.max(b.writerIndex(), origWriter));
    return len;
}

From source file:io.nodyn.buffer.Buffer.java

License:Apache License

public static long binaryWrite(JSObject object, String str, int offset, int len) {
    ByteBuf b = extract(object);
    int origWriter = b.writerIndex();
    byte[] bytes = str.getBytes(BINARY);
    len = Math.min(bytes.length, Math.min(len, b.writableBytes()));
    b.writeBytes(bytes, 0, len);/*w w w. ja v a  2  s  . c om*/
    b.writerIndex(Math.max(b.writerIndex(), origWriter));
    return len;
}

From source file:io.pravega.shared.protocol.netty.CommandEncoder.java

License:Open Source License

@SneakyThrows(IOException.class)
private void writeMessage(AppendBlock block, ByteBuf out) {
    int startIdx = out.writerIndex();
    ByteBufOutputStream bout = new ByteBufOutputStream(out);
    bout.writeInt(block.getType().getCode());
    bout.write(LENGTH_PLACEHOLDER);/*from w  w  w.j a  v a 2 s  . c o m*/
    block.writeFields(bout);
    bout.flush();
    bout.close();
    int endIdx = out.writerIndex();
    int fieldsSize = endIdx - startIdx - TYPE_PLUS_LENGTH_SIZE;
    out.setInt(startIdx + TYPE_SIZE, fieldsSize + currentBlockSize);
}

From source file:io.pravega.shared.protocol.netty.CommandEncoder.java

License:Open Source License

@SneakyThrows(IOException.class)
private int writeMessage(WireCommand msg, ByteBuf out) {
    int startIdx = out.writerIndex();
    ByteBufOutputStream bout = new ByteBufOutputStream(out);
    bout.writeInt(msg.getType().getCode());
    bout.write(LENGTH_PLACEHOLDER);// w ww  .  j  a v  a2s .  co m
    msg.writeFields(bout);
    bout.flush();
    bout.close();
    int endIdx = out.writerIndex();
    int fieldsSize = endIdx - startIdx - TYPE_PLUS_LENGTH_SIZE;
    out.setInt(startIdx + TYPE_SIZE, fieldsSize);
    return endIdx - startIdx;
}

From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java

License:Apache License

public static void encodeText(DataType id, Object value, ByteBuf buff) {
    int index = buff.writerIndex();
    buff.writeInt(0);/*  w  w w  .  jav  a  2s  .  c  o  m*/
    textEncode(id, value, buff);
    buff.setInt(index, buff.writerIndex() - index - 4);
}