Class LanguageProfileReader
- java.lang.Object
-
- com.optimaize.langdetect.profiles.LanguageProfileReader
-
public class LanguageProfileReader extends java.lang.ObjectReadsLanguageProfiles.
-
-
Field Summary
Fields Modifier and Type Field Description private static LangProfileReaderinternalReaderprivate static java.lang.StringPROFILES_DIR
-
Constructor Summary
Constructors Constructor Description LanguageProfileReader()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private booleanlooksLikeLanguageProfileFile(java.io.File file)private booleanlooksLikeLanguageProfileName(java.lang.String fileName)private java.lang.StringmakePathForClassLoader(java.lang.String profileDirectory, java.lang.String fileName)private @NotNull java.lang.StringmakeProfileFileName(@NotNull LdLocale locale)LanguageProfileread(java.io.File profileFile)Reads aLanguageProfilefrom a File in UTF-8.LanguageProfileread(java.io.InputStream inputStream)Reads aLanguageProfilefrom an InputStream in UTF-8.java.util.List<LanguageProfile>read(java.lang.ClassLoader classLoader, java.lang.String profileDirectory, java.util.Collection<java.lang.String> profileFileNames)Load profiles from the classpath in a specific directory.java.util.List<LanguageProfile>read(java.lang.String profileDirectory, java.util.Collection<java.lang.String> profileFileNames)Same asread(ClassLoader, String, java.util.Collection)using the class loader of this class.java.util.List<LanguageProfile>read(java.util.Collection<java.lang.String> profileFileNames)Same asread(ClassLoader, String, java.util.Collection)using the class loader of this class, and the default profiles directory of this library.java.util.List<LanguageProfile>readAll()Deprecated.renamed to readAllBuiltIn()java.util.List<LanguageProfile>readAll(java.io.File path)Loads all profiles from the specified directory.java.util.List<LanguageProfile>readAllBuiltIn()Reads all built-in language profiles from the "languages" folder (shipped with the jar).@NotNull LanguageProfilereadBuiltIn(@NotNull LdLocale locale)@NotNull java.util.List<LanguageProfile>readBuiltIn(@NotNull java.util.Collection<LdLocale> languages)
-
-
-
Field Detail
-
internalReader
private static final LangProfileReader internalReader
-
PROFILES_DIR
private static final java.lang.String PROFILES_DIR
- See Also:
- Constant Field Values
-
-
Method Detail
-
read
public LanguageProfile read(java.io.File profileFile) throws java.io.IOException
Reads aLanguageProfilefrom a File in UTF-8.- Throws:
java.io.IOException
-
read
public LanguageProfile read(java.io.InputStream inputStream) throws java.io.IOException
Reads aLanguageProfilefrom an InputStream in UTF-8.- Throws:
java.io.IOException
-
read
public java.util.List<LanguageProfile> read(java.lang.ClassLoader classLoader, java.lang.String profileDirectory, java.util.Collection<java.lang.String> profileFileNames) throws java.io.IOException
Load profiles from the classpath in a specific directory.This is usually used to load built-in profiles, shipped with the jar.
- Parameters:
classLoader- the ClassLoader to load the profiles from. UseMyClass.class.getClassLoader()profileDirectory- profile directory path inside the classpath. The default profiles are in "languages".profileFileNames- for example ["en", "fr", "de"].- Throws:
java.io.IOException
-
makePathForClassLoader
private java.lang.String makePathForClassLoader(java.lang.String profileDirectory, java.lang.String fileName)
-
read
public java.util.List<LanguageProfile> read(java.lang.String profileDirectory, java.util.Collection<java.lang.String> profileFileNames) throws java.io.IOException
Same asread(ClassLoader, String, java.util.Collection)using the class loader of this class.- Throws:
java.io.IOException
-
read
public java.util.List<LanguageProfile> read(java.util.Collection<java.lang.String> profileFileNames) throws java.io.IOException
Same asread(ClassLoader, String, java.util.Collection)using the class loader of this class, and the default profiles directory of this library.- Throws:
java.io.IOException
-
readBuiltIn
@NotNull public @NotNull LanguageProfile readBuiltIn(@NotNull @NotNull LdLocale locale) throws java.io.IOException
- Throws:
java.io.IOException
-
makeProfileFileName
@NotNull private @NotNull java.lang.String makeProfileFileName(@NotNull @NotNull LdLocale locale)
-
readBuiltIn
@NotNull public @NotNull java.util.List<LanguageProfile> readBuiltIn(@NotNull @NotNull java.util.Collection<LdLocale> languages) throws java.io.IOException
- Throws:
java.io.IOException
-
readAll
public java.util.List<LanguageProfile> readAll() throws java.io.IOException
Deprecated.renamed to readAllBuiltIn()- Throws:
java.io.IOException
-
readAllBuiltIn
public java.util.List<LanguageProfile> readAllBuiltIn() throws java.io.IOException
Reads all built-in language profiles from the "languages" folder (shipped with the jar).- Throws:
java.io.IOException
-
readAll
public java.util.List<LanguageProfile> readAll(java.io.File path) throws java.io.IOException
Loads all profiles from the specified directory. Do not use this method for files distributed within a jar.- Parameters:
path- profile directory path- Returns:
- empty if there is no language file in it.
- Throws:
java.io.IOException
-
looksLikeLanguageProfileFile
private boolean looksLikeLanguageProfileFile(java.io.File file)
-
looksLikeLanguageProfileName
private boolean looksLikeLanguageProfileName(java.lang.String fileName)
-
-