Class MecabDictionaryInstaller
ResourceInstaller under ResourceInstaller.Limits.DEFAULT, including
startup property overrides. An http or https archive requires an
expected checksum. Gzip-compressed tar archives in the ustar, pax, and GNU formats
and zip archives are read. Catalog installs are opt-in via
installFromCatalog(DictionaryCatalog, String, Path).
Only the dictionary payload is installed: the *.csv lexicon files and
*.def definition files that a MecabDictionary reads, plus the
dicrc configuration file distributions ship alongside them, taken from the
archive root only (at most one leading directory deep). Deeper entries are skipped:
mecab-ko-dic, for example, nests user-dic templates whose numeric fields are
empty because they are input for mecab-dict-index, not loadable lexicon
data. Installed files are flattened to their base names. A file whose base name
already exists in the target is not replaced, so it must be removed before refreshing
a dictionary. The archive unpacks into a hidden staging directory beneath the target,
on the target's filesystem, which is removed when the installation ends.
- Since:
- 3.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intThe deepest entry path, relative to the archive root, that holds payload. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrevents construction of this utility class. -
Method Summary
Modifier and TypeMethodDescriptionstatic intUnpacks a localfile:archive URI.static intDownloads a dictionary archive when needed, verifies its checksum, and unpacks it throughResourceInstaller.install(URI, Path, String).private static intinstallDictionaryFiles(Path targetDirectory, ResourceInstaller.StagingStep unpack) Unpacks an archive through the given step and installs its dictionary payload into the target, flattened to base names.static intinstallFromCatalog(DictionaryCatalog catalog, String dictionaryId, Path targetDirectory) Downloads a dictionary named in an application-suppliedDictionaryCatalogand unpacks it.private static booleanisDictionaryFile(String baseName) Recognizes the file names aMecabDictionaryloads.private static PathpayloadName(Path relative) Selects the dictionary payload of an unpacked archive and flattens it.
-
Field Details
-
MAX_PAYLOAD_DEPTH
private static final int MAX_PAYLOAD_DEPTHThe deepest entry path, relative to the archive root, that holds payload.- See Also:
-
-
Constructor Details
-
MecabDictionaryInstaller
private MecabDictionaryInstaller()Prevents construction of this utility class.
-
-
Method Details
-
install
Unpacks a localfile:archive URI. Any other scheme requiresinstall(URI, Path, String)with an expected checksum.- Parameters:
archive- The archive location, a gzip-compressed tar or a zip archive. Must not benull.targetDirectory- The directory to unpack into; created when absent. Must not benull.- Returns:
- The number of dictionary files installed.
- Throws:
IOException- Thrown if reading or writing fails, the archive contains no dictionary file, an installation limit is exceeded, or the target already contains one of the files.IllegalArgumentException- Thrown if a parameter isnullorarchivedoes not use thefilescheme.
-
install
public static int install(URI archive, Path targetDirectory, String expectedChecksum) throws IOException Downloads a dictionary archive when needed, verifies its checksum, and unpacks it throughResourceInstaller.install(URI, Path, String). Afile:URI may omit the checksum.- Parameters:
archive- The archive location, a gzip-compressed tar or a zip archive. Must not benull.targetDirectory- The directory to unpack into; created when absent. Must not benull.expectedChecksum- The expected digest of the archive bytes as a hex string, 64 characters for SHA-256 or 128 for SHA-512. Required for an http or https source; passnullto skip verification for a file source.- Returns:
- The number of dictionary files installed.
- Throws:
IOException- Thrown if fetching, verification, reading, or writing fails, the archive contains no dictionary file, an installation limit is exceeded, or the target already contains one of the files.IllegalArgumentException- Thrown if a parameter isnull, the URI is not supported byResourceInstaller, or an http or https source has no checksum.
-
installFromCatalog
public static int installFromCatalog(DictionaryCatalog catalog, String dictionaryId, Path targetDirectory) throws IOException Downloads a dictionary named in an application-suppliedDictionaryCatalogand unpacks it. RequiresDictionaryCatalog.REMOTE_DOWNLOAD_PROPERTYto betrue.- Parameters:
catalog- The application-supplied catalog. Must not benull.dictionaryId- The catalog id, for examplemecab.ipadicormecab.ko-dic. Must not benull.targetDirectory- The directory to unpack into; created when absent. Must not benull.- Returns:
- The number of dictionary files installed.
- Throws:
IOException- Thrown if the catalog entry is missing, remote downloads are disabled, or install fails.IllegalArgumentException- Thrown if a parameter isnull.
-
installDictionaryFiles
private static int installDictionaryFiles(Path targetDirectory, ResourceInstaller.StagingStep unpack) throws IOException Unpacks an archive through the given step and installs its dictionary payload into the target, flattened to base names.- Parameters:
targetDirectory- The directory to install into; created when absent.unpack- Unpacks the archive into the staging directory it is given.- Returns:
- The number of dictionary files installed.
- Throws:
IOException- Thrown if unpacking fails, the archive holds no dictionary file, two entries flatten to the same base name, a target file already exists, or moving fails.
-
payloadName
Selects the dictionary payload of an unpacked archive and flattens it.- Parameters:
relative- An unpacked file's path relative to the archive root.- Returns:
- The file's base name when it is dictionary payload at most
2 levels deep, or
nullotherwise.
-
isDictionaryFile
Recognizes the file names aMecabDictionaryloads.- Parameters:
baseName- The file name without any directory prefix.- Returns:
truewhen the name is dictionary payload.
-