Example usage for io.netty.util AsciiString forEachByte

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

Introduction

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

Prototype

public int forEachByte(ByteProcessor visitor) throws Exception 

Source Link

Document

Iterates over the readable bytes of this buffer with the specified processor in ascending order.

Usage

From source file:com.linecorp.armeria.internal.ArmeriaHttpUtil.java

License:Apache License

private static CharSequenceMap toLowercaseMap(Iterator<? extends CharSequence> valuesIter, int arraySizeHint) {
    final CharSequenceMap result = new CharSequenceMap(arraySizeHint);

    while (valuesIter.hasNext()) {
        final AsciiString lowerCased = AsciiString.of(valuesIter.next()).toLowerCase();
        try {//from   ww w  . j a va2  s.  co  m
            int index = lowerCased.forEachByte(FIND_COMMA);
            if (index != -1) {
                int start = 0;
                do {
                    result.add(lowerCased.subSequence(start, index, false).trim(), EMPTY_STRING);
                    start = index + 1;
                } while (start < lowerCased.length() && (index = lowerCased.forEachByte(start,
                        lowerCased.length() - start, FIND_COMMA)) != -1);
                result.add(lowerCased.subSequence(start, lowerCased.length(), false).trim(), EMPTY_STRING);
            } else {
                result.add(lowerCased.trim(), EMPTY_STRING);
            }
        } catch (Exception e) {
            // This is not expect to happen because FIND_COMMA never throws but must be caught
            // because of the ByteProcessor interface.
            throw new IllegalStateException(e);
        }
    }
    return result;
}