本文整理汇总了Java中io.netty.util.AsciiString.of方法的典型用法代码示例。如果您正苦于以下问题:Java AsciiString.of方法的具体用法?Java AsciiString.of怎么用?Java AsciiString.of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.util.AsciiString
的用法示例。
在下文中一共展示了AsciiString.of方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toArmeria
import io.netty.util.AsciiString; //导入方法依赖的package包/类
/**
* Converts the specified Netty HTTP/2 into Armeria HTTP/2 headers.
*/
public static HttpHeaders toArmeria(Http2Headers headers) {
final HttpHeaders converted = new DefaultHttpHeaders(false, headers.size());
StringJoiner cookieJoiner = null;
for (Entry<CharSequence, CharSequence> e : headers) {
final AsciiString name = AsciiString.of(e.getKey());
final CharSequence value = e.getValue();
// Cookies must be concatenated into a single octet string.
// https://tools.ietf.org/html/rfc7540#section-8.1.2.5
if (name.equals(HttpHeaderNames.COOKIE)) {
if (cookieJoiner == null) {
cookieJoiner = new StringJoiner(COOKIE_SEPARATOR);
}
COOKIE_SPLITTER.split(value).forEach(cookieJoiner::add);
} else {
converted.add(name, value.toString());
}
}
if (cookieJoiner != null && cookieJoiner.length() != 0) {
converted.add(HttpHeaderNames.COOKIE, cookieJoiner.toString());
}
return converted;
}
示例2: leLengthString
import io.netty.util.AsciiString; //导入方法依赖的package包/类
@Test
public void leLengthString() throws Exception {
ByteBuf dest = Unpooled.buffer();
AsciiString string = AsciiString.of("test");
McpeUtil.writeLELengthAsciiString(dest, string);
assertEquals(string, McpeUtil.readLELengthAsciiString(dest));
dest.release();
}
示例3: newAccessLogComponent
import io.netty.util.AsciiString; //导入方法依赖的package包/类
private static AccessLogComponent newAccessLogComponent(char token,
@Nullable String variable,
@Nullable Condition.Builder condBuilder) {
final AccessLogType type = AccessLogType.find(token).orElseThrow(
() -> new IllegalArgumentException("Unexpected token character: '" + token + '\''));
if (type.isVariableRequired()) {
checkArgument(variable != null,
"Token " + type.token() + " requires a variable.");
}
if (type.isConditionAvailable()) {
if (condBuilder != null) {
checkArgument(!condBuilder.isEmpty(),
"Token " + type.token() + " has an invalid condition.");
}
} else {
checkArgument(condBuilder == null,
"Token " + type.token() + " does not support a condition.");
}
if (TextComponent.isSupported(type)) {
return ofText(variable);
}
// Do not add quotes when parsing a user-provided custom format.
final boolean addQuote = false;
final Function<HttpHeaders, Boolean> condition = condBuilder != null ? condBuilder.build() : null;
if (CommonComponent.isSupported(type)) {
return new CommonComponent(type, addQuote, condition);
}
if (RequestHeaderComponent.isSupported(type)) {
return new RequestHeaderComponent(AsciiString.of(variable), addQuote, condition);
}
if (AttributeComponent.isSupported(type)) {
final Function<Object, String> stringifier;
final String[] components = variable.split(":");
if (components.length == 2) {
stringifier = newStringifier(components[0], components[1]);
} else {
stringifier = Object::toString;
}
return new AttributeComponent(components[0], stringifier, addQuote, condition);
}
// Should not reach here.
throw new Error("Unexpected access log type: " + type.name());
}