MCPcopy Create free account
hub / github.com/antlr/codebuff / InternetDomainName

Class InternetDomainName

corpus/java/training/guava/net/InternetDomainName.java:70–513  ·  view source on GitHub ↗

An immutable well-formed internet domain name, such as com or foo.co.uk. Only syntactic analysis is performed; no DNS lookups or other network interactions take place. Thus there is no guarantee that the domain actually exists on the internet. One common use of this class is to d

Source from the content-addressed store, hash-verified

68 * @since 5.0
69 */
70@Beta
71@GwtCompatible
72public final class InternetDomainName {
73
74 private static final CharMatcher DOTS_MATCHER = CharMatcher.anyOf(".\u3002\uFF0E\uFF61");
75 private static final Splitter DOT_SPLITTER = Splitter.on('.');
76 private static final Joiner DOT_JOINER = Joiner.on('.');
77
78 /**
79 * Value of {@link #publicSuffixIndex} which indicates that no public suffix was found.
80 */
81 private static final int NO_PUBLIC_SUFFIX_FOUND = -1;
82
83 private static final String DOT_REGEX = "\\.";
84
85 /**
86 * Maximum parts (labels) in a domain name. This value arises from the 255-octet limit described
87 * in <a href="http://www.ietf.org/rfc/rfc2181.txt">RFC 2181</a> part 11 with the fact that the
88 * encoding of each part occupies at least two bytes (dot plus label externally, length byte plus
89 * label internally). Thus, if all labels have the minimum size of one byte, 127 of them will fit.
90 */
91 private static final int MAX_PARTS = 127;
92
93 /**
94 * Maximum length of a full domain name, including separators, and leaving room for the root
95 * label. See <a href="http://www.ietf.org/rfc/rfc2181.txt">RFC 2181</a> part 11.
96 */
97 private static final int MAX_LENGTH = 253;
98
99 /**
100 * Maximum size of a single part of a domain name. See
101 * <a href="http://www.ietf.org/rfc/rfc2181.txt">RFC 2181</a> part 11.
102 */
103 private static final int MAX_DOMAIN_PART_LENGTH = 63;
104
105 /**
106 * The full domain name, converted to lower case.
107 */
108 private final String name;
109
110 /**
111 * The parts of the domain name, converted to lower case.
112 */
113 private final ImmutableList<String> parts;
114
115 /**
116 * The index in the {@link #parts()} list at which the public suffix begins. For example, for the
117 * domain name {@code www.google.co.uk}, the value would be 2 (the index of the {@code co} part).
118 * The value is negative (specifically, {@link #NO_PUBLIC_SUFFIX_FOUND}) if no public suffix was
119 * found.
120 */
121 private final int publicSuffixIndex;
122
123 /**
124 * Constructor used to implement {@link #from(String)}, and from subclasses.
125 */
126 InternetDomainName(String name) {
127 // Normalize:

Callers

nothing calls this directly

Calls 5

anyOfMethod · 0.95
onMethod · 0.95
onMethod · 0.95
javaLetterOrDigitMethod · 0.95
orMethod · 0.45

Tested by

no test coverage detected