Home / Function/ parse() — netty Function Reference

parse() — netty Function Reference

Architecture documentation for the parse() function in UnixResolverDnsServerAddressStreamProvider.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  faf5b73b_bdcd_428b_dee7_2e0fd8338002["parse()"]
  8efad33e_883b_062a_b123_d462f61c3350["UnixResolverDnsServerAddressStreamProvider"]
  faf5b73b_bdcd_428b_dee7_2e0fd8338002 -->|defined in| 8efad33e_883b_062a_b123_d462f61c3350
  b1d25819_2d2d_59c8_c410_aa8a0ba1f8a5["UnixResolverDnsServerAddressStreamProvider()"]
  b1d25819_2d2d_59c8_c410_aa8a0ba1f8a5 -->|calls| faf5b73b_bdcd_428b_dee7_2e0fd8338002
  9cdf8e90_d3af_1682_4628_58c4abdc22df["putIfAbsent()"]
  faf5b73b_bdcd_428b_dee7_2e0fd8338002 -->|calls| 9cdf8e90_d3af_1682_4628_58c4abdc22df
  style faf5b73b_bdcd_428b_dee7_2e0fd8338002 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

resolver-dns/src/main/java/io/netty/resolver/dns/UnixResolverDnsServerAddressStreamProvider.java lines 158–259

    private static Map<String, DnsServerAddresses> parse(File... etcResolverFiles) throws IOException {
        Map<String, DnsServerAddresses> domainToNameServerStreamMap =
                new HashMap<String, DnsServerAddresses>(etcResolverFiles.length << 1);
        boolean rotateGlobal = RES_OPTIONS != null && RES_OPTIONS.contains(OPTIONS_ROTATE_FLAG);
        for (File etcResolverFile : etcResolverFiles) {
            if (!etcResolverFile.isFile()) {
                continue;
            }
            FileReader fr = new FileReader(etcResolverFile);
            BufferedReader br = null;
            try {
                br = new BufferedReader(fr);
                List<InetSocketAddress> addresses = new ArrayList<InetSocketAddress>(2);
                String domainName = etcResolverFile.getName();
                boolean rotate = rotateGlobal;
                int port = DNS_PORT;
                String line;
                while ((line = br.readLine()) != null) {
                    line = line.trim();
                    try {
                        char c;
                        if (line.isEmpty() || (c = line.charAt(0)) == '#' || c == ';') {
                            continue;
                        }
                        if (!rotate && line.startsWith(OPTIONS_ROW_LABEL)) {
                            rotate = line.contains(OPTIONS_ROTATE_FLAG);
                        } else if (line.startsWith(NAMESERVER_ROW_LABEL)) {
                            int i = indexOfNonWhiteSpace(line, NAMESERVER_ROW_LABEL.length());
                            if (i < 0) {
                                throw new IllegalArgumentException("error parsing label " + NAMESERVER_ROW_LABEL +
                                        " in file " + etcResolverFile + ". value: " + line);
                            }
                            String maybeIP;
                            int x = indexOfWhiteSpace(line, i);
                            if (x == -1) {
                                maybeIP = line.substring(i);
                            } else {
                                // ignore comments
                                int idx = indexOfNonWhiteSpace(line, x);
                                if (idx == -1 || line.charAt(idx) != '#') {
                                    throw new IllegalArgumentException("error parsing label " + NAMESERVER_ROW_LABEL +
                                            " in file " + etcResolverFile + ". value: " + line);
                                }
                                maybeIP = line.substring(i, x);
                            }

                            // There may be a port appended onto the IP address so we attempt to extract it.
                            if (!NetUtil.isValidIpV4Address(maybeIP) && !NetUtil.isValidIpV6Address(maybeIP)) {
                                i = maybeIP.lastIndexOf('.');
                                if (i + 1 >= maybeIP.length()) {
                                    throw new IllegalArgumentException("error parsing label " + NAMESERVER_ROW_LABEL +
                                            " in file " + etcResolverFile + ". invalid IP value: " + line);
                                }
                                port = Integer.parseInt(maybeIP.substring(i + 1));
                                maybeIP = maybeIP.substring(0, i);
                            }
                            InetSocketAddress addr = SocketUtils.socketAddress(maybeIP, port);
                            // Check if the address is resolved and only if this is the case use it. Otherwise just
                            // ignore it. This is needed to filter out invalid entries, as if for example an ipv6
                            // address is used with a scope that represent a network interface that does not exists
                            // on the host.
                            if (!addr.isUnresolved()) {
                                addresses.add(addr);
                            }
                        } else if (line.startsWith(DOMAIN_ROW_LABEL)) {
                            int i = indexOfNonWhiteSpace(line, DOMAIN_ROW_LABEL.length());
                            if (i < 0) {
                                throw new IllegalArgumentException("error parsing label " + DOMAIN_ROW_LABEL +
                                        " in file " + etcResolverFile + " value: " + line);
                            }
                            domainName = line.substring(i);
                            if (!addresses.isEmpty()) {
                                putIfAbsent(domainToNameServerStreamMap, domainName, addresses, rotate);
                            }
                            addresses = new ArrayList<InetSocketAddress>(2);
                        } else if (line.startsWith(PORT_ROW_LABEL)) {
                            int i = indexOfNonWhiteSpace(line, PORT_ROW_LABEL.length());
                            if (i < 0) {
                                throw new IllegalArgumentException("error parsing label " + PORT_ROW_LABEL +
                                        " in file " + etcResolverFile + " value: " + line);
                            }

Subdomains

Frequently Asked Questions

What does parse() do?
parse() is a function in the netty codebase, defined in resolver-dns/src/main/java/io/netty/resolver/dns/UnixResolverDnsServerAddressStreamProvider.java.
Where is parse() defined?
parse() is defined in resolver-dns/src/main/java/io/netty/resolver/dns/UnixResolverDnsServerAddressStreamProvider.java at line 158.
What does parse() call?
parse() calls 1 function(s): putIfAbsent.
What calls parse()?
parse() is called by 1 function(s): UnixResolverDnsServerAddressStreamProvider.

Analyze Your Own Codebase

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

Try Supermodel Free