Example usage for io.netty.buffer ByteBufUtil getBytes

List of usage examples for io.netty.buffer ByteBufUtil getBytes

Introduction

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

Prototype

public static byte[] getBytes(ByteBuf buf, int start, int length) 

Source Link

Document

Create a copy of the underlying storage from buf into a byte array.

Usage

From source file:com.heliosapm.streams.metrics.StreamedMetric.java

License:Open Source License

/**
 * Returns a byte array containing the serialized streammetric
 * @return a byte array /*from ww  w.jav  a  2 s.co  m*/
 */
public byte[] toByteArray() {
    final ByteBuf buff = BufferManager.getInstance().directBuffer(byteSize);
    try {
        buff.writeByte(TYPE_CODE);
        writeByteArray(buff);
        return ByteBufUtil.getBytes(buff, 0, buff.readableBytes());

    } finally {
        try {
            buff.release();
        } catch (Exception x) {
            /* No Op */}
    }
}

From source file:com.heliosapm.streams.metrics.StreamedMetricValue.java

License:Apache License

/**
 * Returns a byte array containing the serialized streammetric
 * @return a byte array /*from w ww  .  j  a  v  a2 s. c o m*/
 */
@Override
public byte[] toByteArray() {
    final ByteBuf buff = BufferManager.getInstance().directBuffer(byteSize);
    try {
        buff.writeByte(TYPE_CODE);
        writeByteArray(buff);
        if (isDoubleValue) {
            buff.writeByte(0);
            buff.writeDouble(doubleValue);
        } else {
            buff.writeByte(1);
            buff.writeLong(longValue);
        }
        return ByteBufUtil.getBytes(buff, 0, buff.readableBytes());
    } finally {
        try {
            buff.release();
        } catch (Exception x) {
            /* No Op */}
    }
}