Example usage for io.netty.util AsciiString isEntireArrayUsed

List of usage examples for io.netty.util AsciiString isEntireArrayUsed

Introduction

In this page you can find the example usage for io.netty.util AsciiString isEntireArrayUsed.

Prototype

public boolean isEntireArrayUsed() 

Source Link

Document

Determine if the storage represented by #array() is entirely used.

Usage

From source file:com.linecorp.armeria.server.grpc.GrpcService.java

License:Apache License

private byte[][] convertHeadersToArray(HttpHeaders headers) {
    // The Netty AsciiString class is really just a wrapper around a byte[] and supports
    // arbitrary binary data, not just ASCII.
    byte[][] headerValues = new byte[headers.size() * 2][];
    int i = 0;//w w w  .java  2  s. com
    for (Map.Entry<AsciiString, String> entry : headers) {
        AsciiString key = entry.getKey();
        headerValues[i++] = key.isEntireArrayUsed() ? key.array() : key.toByteArray();
        headerValues[i++] = entry.getValue().getBytes(StandardCharsets.US_ASCII);
    }
    return TransportFrameUtil.toRawSerializedHeaders(headerValues);
}

From source file:io.grpc.netty.Utils.java

License:Apache License

private static byte[] bytes(CharSequence seq) {
    if (seq instanceof AsciiString) {
        // Fast path - sometimes copy.
        AsciiString str = (AsciiString) seq;
        return str.isEntireArrayUsed() ? str.array() : str.toByteArray();
    }//from   w  w  w  .  jav  a  2  s.c om
    // Slow path - copy.
    return seq.toString().getBytes(UTF_8);
}