Package io.netty.resolver
Class HostsFileParser
- java.lang.Object
-
- io.netty.resolver.HostsFileParser
-
public final class HostsFileParser extends java.lang.Object
A parser for hosts files.
-
-
Field Summary
Fields Modifier and Type Field Description private static InternalLogger
logger
private static java.util.regex.Pattern
WHITESPACES
private static java.lang.String
WINDOWS_DEFAULT_SYSTEM_ROOT
private static java.lang.String
WINDOWS_HOSTS_FILE_RELATIVE_PATH
private static java.lang.String
X_PLATFORMS_HOSTS_FILE_PATH
-
Constructor Summary
Constructors Modifier Constructor Description private
HostsFileParser()
Can't be instantiated.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.io.File
locateHostsFile()
static HostsFileEntries
parse()
Parse hosts file at standard OS location using the system defaultCharset
for decoding.static HostsFileEntries
parse(java.io.File file)
Parse a hosts file using the system defaultCharset
for decoding.static HostsFileEntries
parse(java.io.File file, java.nio.charset.Charset... charsets)
Parse a hosts file.static HostsFileEntries
parse(java.io.Reader reader)
Parse a reader of hosts file format.static HostsFileEntries
parseSilently()
Parse hosts file at standard OS location using the systems defaultCharset
for decoding.static HostsFileEntries
parseSilently(java.nio.charset.Charset... charsets)
Parse hosts file at standard OS location using the givenCharset
s one after each other until we were able to parse something or none is left.
-
-
-
Field Detail
-
WINDOWS_DEFAULT_SYSTEM_ROOT
private static final java.lang.String WINDOWS_DEFAULT_SYSTEM_ROOT
- See Also:
- Constant Field Values
-
WINDOWS_HOSTS_FILE_RELATIVE_PATH
private static final java.lang.String WINDOWS_HOSTS_FILE_RELATIVE_PATH
- See Also:
- Constant Field Values
-
X_PLATFORMS_HOSTS_FILE_PATH
private static final java.lang.String X_PLATFORMS_HOSTS_FILE_PATH
- See Also:
- Constant Field Values
-
WHITESPACES
private static final java.util.regex.Pattern WHITESPACES
-
logger
private static final InternalLogger logger
-
-
Method Detail
-
locateHostsFile
private static java.io.File locateHostsFile()
-
parseSilently
public static HostsFileEntries parseSilently()
Parse hosts file at standard OS location using the systems defaultCharset
for decoding.- Returns:
- a
HostsFileEntries
-
parseSilently
public static HostsFileEntries parseSilently(java.nio.charset.Charset... charsets)
Parse hosts file at standard OS location using the givenCharset
s one after each other until we were able to parse something or none is left.- Parameters:
charsets
- theCharset
s to try as file encodings when parsing.- Returns:
- a
HostsFileEntries
-
parse
public static HostsFileEntries parse() throws java.io.IOException
Parse hosts file at standard OS location using the system defaultCharset
for decoding.- Returns:
- a
HostsFileEntries
- Throws:
java.io.IOException
- file could not be read
-
parse
public static HostsFileEntries parse(java.io.File file) throws java.io.IOException
Parse a hosts file using the system defaultCharset
for decoding.- Parameters:
file
- the file to be parsed- Returns:
- a
HostsFileEntries
- Throws:
java.io.IOException
- file could not be read
-
parse
public static HostsFileEntries parse(java.io.File file, java.nio.charset.Charset... charsets) throws java.io.IOException
Parse a hosts file.- Parameters:
file
- the file to be parsedcharsets
- theCharset
s to try as file encodings when parsing.- Returns:
- a
HostsFileEntries
- Throws:
java.io.IOException
- file could not be read
-
parse
public static HostsFileEntries parse(java.io.Reader reader) throws java.io.IOException
Parse a reader of hosts file format.- Parameters:
reader
- the file to be parsed- Returns:
- a
HostsFileEntries
- Throws:
java.io.IOException
- file could not be read
-
-