Home / Class/ HeadersUtils Class — netty Architecture

HeadersUtils Class — netty Architecture

Architecture documentation for the HeadersUtils class in HeadersUtils.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  6975a9bb_10b8_b213_236f_12884e1d939d["HeadersUtils"]
  1d9d6b5f_e8d8_6f84_a021_34a64a5c3683["HeadersUtils.java"]
  6975a9bb_10b8_b213_236f_12884e1d939d -->|defined in| 1d9d6b5f_e8d8_6f84_a021_34a64a5c3683
  5b488a2d_68da_0495_7b17_01de388ef803["HeadersUtils()"]
  6975a9bb_10b8_b213_236f_12884e1d939d -->|method| 5b488a2d_68da_0495_7b17_01de388ef803
  7cfd3f58_5bc7_c03d_0bb6_47d3e95ccdc8["getAllAsString()"]
  6975a9bb_10b8_b213_236f_12884e1d939d -->|method| 7cfd3f58_5bc7_c03d_0bb6_47d3e95ccdc8
  7b29e6f9_3144_b373_3f07_f86ba5b370e4["String()"]
  6975a9bb_10b8_b213_236f_12884e1d939d -->|method| 7b29e6f9_3144_b373_3f07_f86ba5b370e4
  c9e52cfa_30ae_9154_440b_8b21836523be["iteratorAsString()"]
  6975a9bb_10b8_b213_236f_12884e1d939d -->|method| c9e52cfa_30ae_9154_440b_8b21836523be
  dc85eb5c_bcd3_d4ba_9063_3909c770ae5f["namesAsString()"]
  6975a9bb_10b8_b213_236f_12884e1d939d -->|method| dc85eb5c_bcd3_d4ba_9063_3909c770ae5f

Relationship Graph

Source Code

codec-base/src/main/java/io/netty/handler/codec/HeadersUtils.java lines 30–221

public final class HeadersUtils {

    private HeadersUtils() {
    }

    /**
     * {@link Headers#get(Object)} and convert each element of {@link List} to a {@link String}.
     * @param name the name of the header to retrieve
     * @return a {@link List} of header values or an empty {@link List} if no values are found.
     */
    public static <K, V> List<String> getAllAsString(Headers<K, V, ?> headers, K name) {
        final List<V> allNames = headers.getAll(name);
        return new AbstractList<String>() {
            @Override
            public String get(int index) {
                V value = allNames.get(index);
                return value != null ? value.toString() : null;
            }

            @Override
            public int size() {
                return allNames.size();
            }
        };
    }

    /**
     * {@link Headers#get(Object)} and convert the result to a {@link String}.
     * @param headers the headers to get the {@code name} from
     * @param name the name of the header to retrieve
     * @return the first header value if the header is found. {@code null} if there's no such entry.
     */
    public static <K, V> String getAsString(Headers<K, V, ?> headers, K name) {
        V orig = headers.get(name);
        return orig != null ? orig.toString() : null;
    }

    /**
     * {@link Headers#iterator()} which converts each {@link Entry}'s key and value to a {@link String}.
     */
    public static Iterator<Entry<String, String>> iteratorAsString(
            Iterable<Entry<CharSequence, CharSequence>> headers) {
        return new StringEntryIterator(headers.iterator());
    }

    /**
     * Helper for implementing toString for {@link DefaultHeaders} and wrappers such as DefaultHttpHeaders.
     * @param headersClass the class of headers
     * @param headersIt the iterator on the actual headers
     * @param size the size of the iterator
     * @return a String representation of the headers
     */
    public static <K, V> String toString(Class<?> headersClass, Iterator<Entry<K, V>> headersIt, int size) {
        String simpleName = headersClass.getSimpleName();
        if (size == 0) {
            return simpleName + "[]";
        } else {
            // original capacity assumes 20 chars per headers
            StringBuilder sb = new StringBuilder(simpleName.length() + 2 + size * 20)
                    .append(simpleName)
                    .append('[');
            while (headersIt.hasNext()) {
                Entry<?, ?> header = headersIt.next();
                sb.append(header.getKey()).append(": ").append(header.getValue()).append(", ");
            }
            sb.setLength(sb.length() - 2);
            return sb.append(']').toString();
        }
    }

    /**
     * {@link Headers#names()} and convert each element of {@link Set} to a {@link String}.
     * @param headers the headers to get the names from
     * @return a {@link Set} of header values or an empty {@link Set} if no values are found.
     */
    public static Set<String> namesAsString(Headers<CharSequence, CharSequence, ?> headers) {
        return new DelegatingNameSet(headers);
    }

    private static final class StringEntryIterator implements Iterator<Entry<String, String>> {
        private final Iterator<Entry<CharSequence, CharSequence>> iter;

Frequently Asked Questions

What is the HeadersUtils class?
HeadersUtils is a class in the netty codebase, defined in codec-base/src/main/java/io/netty/handler/codec/HeadersUtils.java.
Where is HeadersUtils defined?
HeadersUtils is defined in codec-base/src/main/java/io/netty/handler/codec/HeadersUtils.java at line 30.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free