org.zodiac.netty.http.headers.HeaderNamesHeader Maven / Gradle / Ivy
package org.zodiac.netty.http.headers;
import org.zodiac.sdk.toolkit.util.lang.StrUtil;
class HeaderNamesHeader extends AbstractHeader[]> {
@SuppressWarnings(value = "unchecked")
HeaderNamesHeader(CharSequence name) {
super((Class) HeaderValueType[].class, name);
}
@Override
public String toString(HeaderValueType[] value) {
StringBuilder sb = new StringBuilder();
for (HeaderValueType t : value) {
if (sb.length() > 0) {
sb.append(',');
}
sb.append(t.name());
}
return sb.toString();
}
@Override
public HeaderValueType>[] toValue(CharSequence value) {
if (value == null || value.length() == 0) {
return new HeaderValueType>[0];
}
CharSequence[] items = StrUtil.splitToArray(value, ',');
HeaderValueType>[] result = new HeaderValueType>[items.length];
for (int i = 0; i < items.length; i++) {
result[i] = Headers.header(items[i]);
}
return result;
}
}