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