Package opennlp.tools.util.ext
Class ProviderSpec
java.lang.Object
opennlp.tools.util.ext.ProviderSpec
Describes what a
Provider should create: an optional location, such as a model file,
and string options. Instances are immutable.- Since:
- 3.0.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final ProviderSpecprivate static final charprivate static final Stringprivate final URIprivate static final charprivate static final charprivate static final char -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidappendEscapes(StringBuilder decoded, ByteArrayOutputStream escapes) private booleanprivate static Stringprivate StringDecodes the percent escapes of a raw location, unlikeURLDecoder, which would also read+as a space.static ProviderSpecempty()booleanprivate intescapedByte(String part, int character) private booleanhasControlCharacter(String path) inthashCode()booleanhasOnlyOptions(String... names) Checks whether every option of this spec has one of the given names.location()booleanlocationEndsWith(String suffix) Checks whether the last path segment of the location ends with a suffix, ignoring case.static ProviderSpecCreates a spec with a location and without options.static ProviderSpecCreates a spec with a location and options.static ProviderSpecCreates a spec for a file or directory without options, seeof(Path, Map).static ProviderSpecCreates a spec for a file or directory with options.static ProviderSpecCreates a spec with options and without location.Reads an option.options()path()(package private) static StringRenders a location without the parts that may hold credentials, for a message or a log entry.private Stringprivate static StringtoString()The option values and the user info, query and fragment of the location are omitted, as they may hold credentials.private static URIConverts a path of the default file system without reading it, unlikePath.toUri(), which appends a separator to an existing directory and would make the location depend on what is on disk when the spec is created.private static StringwithoutUserInfo(String authority)
-
Field Details
-
FILE_SCHEME
- See Also:
-
PATH_SEPARATOR
private static final char PATH_SEPARATOR- See Also:
-
QUERY_SEPARATOR
private static final char QUERY_SEPARATOR- See Also:
-
USER_INFO_SEPARATOR
private static final char USER_INFO_SEPARATOR- See Also:
-
ESCAPE
private static final char ESCAPE- See Also:
-
AUTHORITY_PREFIX
- See Also:
-
EMPTY
-
location
-
options
-
-
Constructor Details
-
ProviderSpec
- Parameters:
location- The location, ornullif the spec has none.options- The options. Must not benull, an option name must not benullor blank and an option value must not benull.- Throws:
IllegalArgumentException- Thrown ifoptionsis invalid.
-
-
Method Details
-
empty
- Returns:
- A spec without location and options. Never
null.
-
of
Creates a spec with options and without location.- Parameters:
options- The options. Must not benull, an option name must not benullor blank and an option value must not benull.- Returns:
- The spec. Never
null. - Throws:
IllegalArgumentException- Thrown ifoptionsis invalid.
-
of
Creates a spec with a location and without options.- Parameters:
location- The absolute location. Must not benull.- Returns:
- The spec. Never
null. - Throws:
IllegalArgumentException- Thrown iflocationisnullor not absolute.
-
of
Creates a spec with a location and options.- Parameters:
location- The absolute location, which is taken as it is, unlike the location ofof(Path, Map). Must not benull.options- The options. Must not benull, an option name must not benullor blank and an option value must not benull.- Returns:
- The spec. Never
null. - Throws:
IllegalArgumentException- Thrown iflocationisnullor not absolute, or ifoptionsis invalid.
-
of
Creates a spec for a file or directory without options, seeof(Path, Map).- Parameters:
location- The file or directory. Must not benull.- Returns:
- The spec. Never
null. - Throws:
IllegalArgumentException- Thrown iflocationisnull.
-
of
Creates a spec for a file or directory with options. A relative path is resolved against the working directory of the running process when the spec is created, so a spec that is kept in astaticfield must not be created from a relative path. The file system is not read, so the location of a directory carries no trailing separator and a path holding..is kept as it is.- Parameters:
location- The file or directory. Must not benull.options- The options. Must not benull, an option name must not benullor blank and an option value must not benull.- Returns:
- The spec. Never
null. - Throws:
IllegalArgumentException- Thrown iflocationisnull, or ifoptionsis invalid.
-
uriOf
Converts a path of the default file system without reading it, unlikePath.toUri(), which appends a separator to an existing directory and would make the location depend on what is on disk when the spec is created. The path is made absolute but neither normalized nor resolved against symbolic links.- Parameters:
location- The file or directory. Must not benull.- Returns:
- The location of
location. Nevernull. - Throws:
IllegalArgumentException- Thrown iflocationhas no URI.
-
location
- Returns:
- The location, or
Optional.empty()if this spec has none.
-
path
- Returns:
- The location as a path, or
Optional.empty()if this spec has no location or the location is not a hierarchicalfileURI of the default file system.
-
options
- Returns:
- The options in insertion order. Unmodifiable and never
null.
-
option
Reads an option.- Parameters:
key- The option name. Must not benull.defaultValue- The value to return if the option is absent. May benull.- Returns:
- The option value, or
defaultValue. - Throws:
IllegalArgumentException- Thrown ifkeyisnull.
-
hasOnlyOptions
Checks whether every option of this spec has one of the given names.- Parameters:
names- The accepted option names. Must not benullor contain anullelement.- Returns:
trueif this spec has no option with another name.- Throws:
IllegalArgumentException- Thrown ifnamesisnullor contains anullelement.
-
locationEndsWith
Checks whether the last path segment of the location ends with a suffix, ignoring case. A query and a fragment are not part of the comparison. For an opaque URI, such asjar:file:/models.jar!/model.onnx, the scheme-specific part is used as path. This is a convenience for routing a request to a provider, not a validation of the location.- Parameters:
suffix- The suffix, for example.onnx. Must not benullor empty.- Returns:
trueif this spec has a location and its last path segment ends withsuffix.- Throws:
IllegalArgumentException- Thrown ifsuffixisnullor empty.
-
equals
-
hashCode
public int hashCode() -
toString
The option values and the user info, query and fragment of the location are omitted, as they may hold credentials. -
contains
-
printableLocation
-
printable
Renders a location without the parts that may hold credentials, for a message or a log entry.- Parameters:
location- The location. Must not benull.- Returns:
- The location without its user info, query and fragment. Never
null.
-
redact
- Returns:
- The scheme-specific part of an opaque location, such as
https://user@host/models.jar!/model.onnx, without the user info of a nested authority.
-
withoutUserInfo
-
hasControlCharacter
-
decode
Decodes the percent escapes of a raw location, unlikeURLDecoder, which would also read+as a space. A run of escapes is decoded as UTF-8, and the characters between them, which a raw location holds unescaped if they are not ASCII, are kept as they are.- Returns:
- The decoded part.
-
appendEscapes
-
escapedByte
-
cutQuery
-