List of usage examples for io.netty.util.internal InternalThreadLocalMap get
public static InternalThreadLocalMap get()
From source file:com.chiorichan.http.CookieDecoder.java
License:Mozilla Public License
/** * Decodes the specified Set-Cookie HTTP header value into a {@link Cookie}. * * @return the decoded {@link Cookie}/*w w w .j a v a 2s. c o m*/ */ public static Set<Cookie> decode(String header) { if (header == null) throw new NullPointerException("header"); final int headerLen = header.length(); if (headerLen == 0) return Collections.emptySet(); Set<Cookie> cookies = new TreeSet<Cookie>(); int i = 0; boolean rfc2965Style = false; if (header.regionMatches(true, 0, "$Version", 0, 8)) { // RFC 2965 style cookie, move to after version value i = header.indexOf(';') + 1; rfc2965Style = true; } loop: for (;;) { // Skip spaces and separators. for (;;) { if (i == headerLen) break loop; char c = header.charAt(i); if (c == '\t' || c == '\n' || c == 0x0b || c == '\f' || c == '\r' || c == ' ' || c == ',' || c == ';') { i++; continue; } break; } int newNameStart = i; int newNameEnd = i; String value; if (i == headerLen) value = null; else keyValLoop: for (;;) { char curChar = header.charAt(i); if (curChar == ';') { // NAME; (no value till ';') newNameEnd = i; value = null; break keyValLoop; } else if (curChar == '=') { // NAME=VALUE newNameEnd = i; i++; if (i == headerLen) { // NAME= (empty value, i.e. nothing after '=') value = ""; break keyValLoop; } int newValueStart = i; char c = header.charAt(i); if (c == '"') { // NAME="VALUE" StringBuilder newValueBuf = InternalThreadLocalMap.get().stringBuilder(); final char q = c; boolean hadBackslash = false; i++; for (;;) { if (i == headerLen) { value = newValueBuf.toString(); break keyValLoop; } if (hadBackslash) { hadBackslash = false; c = header.charAt(i++); if (c == '\\' || c == '"') // Escape last backslash. newValueBuf.setCharAt(newValueBuf.length() - 1, c); else // Do not escape last backslash. newValueBuf.append(c); } else { c = header.charAt(i++); if (c == q) { value = newValueBuf.toString(); break keyValLoop; } newValueBuf.append(c); if (c == '\\') hadBackslash = true; } } } else { // NAME=VALUE; int semiPos = header.indexOf(';', i); if (semiPos > 0) { value = header.substring(newValueStart, semiPos); i = semiPos; } else { value = header.substring(newValueStart); i = headerLen; } } break keyValLoop; } else i++; if (i == headerLen) { // NAME (no value till the end of string) newNameEnd = headerLen; value = null; break; } } if (!rfc2965Style || (!header.regionMatches(newNameStart, "$Path", 0, "$Path".length()) && !header.regionMatches(newNameStart, "$Domain", 0, "$Domain".length()) && !header.regionMatches(newNameStart, "$Port", 0, "$Port".length()))) { // skip obsolete RFC2965 fields String name = header.substring(newNameStart, newNameEnd); cookies.add(new DefaultCookie(name, value)); } } return cookies; }
From source file:com.linecorp.armeria.common.RequestContextThreadLocal.java
License:Apache License
@SuppressWarnings("unchecked") static <T extends RequestContext> T getAndSet(RequestContext ctx) { final InternalThreadLocalMap map = InternalThreadLocalMap.get(); final RequestContext oldCtx = context.get(map); context.set(map, ctx);/*from ww w . j a va 2 s . c o m*/ return (T) oldCtx; }
From source file:com.zhucode.longio.transport.netty.AbstractNettyHandler.java
License:Open Source License
/** * code from netty//from www . j av a2s . c o m * * @return */ public boolean isSharable() { Class<?> clazz = getClass(); Map<Class<?>, Boolean> cache = InternalThreadLocalMap.get().handlerSharableCache(); Boolean sharable = cache.get(clazz); if (sharable == null) { sharable = clazz.isAnnotationPresent(Sharable.class); cache.put(clazz, sharable); } return sharable; }
From source file:io.vertx.core.dns.impl.fix.DnsNameResolverBuilder.java
License:Apache License
/** * Sets the list of the protocol families of the address resolved. * Usually, both {@link InternetProtocolFamily#IPv4} and {@link InternetProtocolFamily#IPv6} are specified in * the order of preference. To enforce the resolve to retrieve the address of a specific protocol family, * specify only a single {@link InternetProtocolFamily}. * * @param resolvedAddressTypes the address types * @return {@code this}/*from w ww . ja va 2 s . co m*/ */ public DnsNameResolverBuilder resolvedAddressTypes(InternetProtocolFamily... resolvedAddressTypes) { checkNotNull(resolvedAddressTypes, "resolvedAddressTypes"); final List<InternetProtocolFamily> list = InternalThreadLocalMap.get() .arrayList(InternetProtocolFamily.values().length); for (InternetProtocolFamily f : resolvedAddressTypes) { if (f == null) { break; } // Avoid duplicate entries. if (list.contains(f)) { continue; } list.add(f); } if (list.isEmpty()) { throw new IllegalArgumentException("no protocol family specified"); } this.resolvedAddressTypes = list.toArray(new InternetProtocolFamily[list.size()]); return this; }
From source file:io.vertx.core.dns.impl.fix.DnsNameResolverBuilder.java
License:Apache License
/** * Sets the list of the protocol families of the address resolved. * Usually, both {@link InternetProtocolFamily#IPv4} and {@link InternetProtocolFamily#IPv6} are specified in * the order of preference. To enforce the resolve to retrieve the address of a specific protocol family, * specify only a single {@link InternetProtocolFamily}. * * @param resolvedAddressTypes the address types * @return {@code this}//w w w . j av a 2 s.c o m */ public DnsNameResolverBuilder resolvedAddressTypes(Iterable<InternetProtocolFamily> resolvedAddressTypes) { checkNotNull(resolvedAddressTypes, "resolveAddressTypes"); final List<InternetProtocolFamily> list = InternalThreadLocalMap.get() .arrayList(InternetProtocolFamily.values().length); for (InternetProtocolFamily f : resolvedAddressTypes) { if (f == null) { break; } // Avoid duplicate entries. if (list.contains(f)) { continue; } list.add(f); } if (list.isEmpty()) { throw new IllegalArgumentException("no protocol family specified"); } this.resolvedAddressTypes = list.toArray(new InternetProtocolFamily[list.size()]); return this; }