public final class FileUtil extends Object
| Constructor and Description |
|---|
FileUtil() |
| Modifier and Type | Method and Description |
|---|---|
static File |
createTempFile(String prefix) |
static File |
createTempFile(String prefix,
String extension) |
static void |
deleteAllFilesInDirectory(String directoryPath)
Deletes all files in the specified directory.
|
static URL |
fileToUrl(File file) |
static Collection<File> |
getFilteredFiles(File directory,
FilenameFilter filter,
boolean recurse)
Gets a collection of the files in a given directory.
|
static File[] |
getFilteredFilesAsArray(File directory,
FilenameFilter filter,
boolean recurse)
Gets an array of the files in a given directory.
|
static String |
getLocaleBasedFile(String baseName,
String extension,
LocaleId locale)
Return a path to a locale based resource using the standard java property resource resolution.
|
static String |
getPartBeforeFile(URI uri)
Gets the URI part before the file name.
|
static List<String> |
guessLanguages(Reader reader)
Tries to guess the language(s) declared in the given input.
|
static List<String> |
guessLanguages(String path)
Tries to guess the language(s) declared in the given input file.
|
static boolean |
isXliffSegmented(Reader reader)
Scans xliff file to see if it is segmented (has <seg-source>)
|
static boolean |
isXliffSegmented(String path)
Scans xliff file to see if it is segmented (has <seg-source>)
|
static File |
urlToFile(URL url) |
public static File[] getFilteredFilesAsArray(File directory, FilenameFilter filter, boolean recurse)
This method searches all Files recursively that pass the
FilenameFilter. Adapted from
http://snippets.dzone.com/posts/show/1875
directory - root directoryfilter - FilenameFilter used to filter the File candidatesrecurse - true to recurse in the sub-directories, false to not.Files (File[])public static Collection<File> getFilteredFiles(File directory, FilenameFilter filter, boolean recurse)
This method search all Files recursively that pass the
FilenameFilter. Adapted from
http://snippets.dzone.com/posts/show/1875
directory - root directoryfilter - FilenameFilter used to filter the File candidatesrecurse - true to recurse in the sub-directories, false to not.Collection of Filespublic static List<String> guessLanguages(String path)
The methods looks in the file line by line, in the 10 first KB, or until a source and at least one target are detected, whichever comes first.
The encoding for the file is determined based on the BOM, if present.
path - the full path of the file to process.public static List<String> guessLanguages(Reader reader)
The methods looks in the file line by line, in the 10 first KB, or until a source and at least one target are detected, whichever comes first.
reader - a reader providing the content to examine. This reader will be closed
by this method.public static boolean isXliffSegmented(String path)
path - the full path of the xliff file to process.public static boolean isXliffSegmented(Reader reader)
reader - a reader providing the xliff content to examine. This reader
will be closed by this method.public static void deleteAllFilesInDirectory(String directoryPath)
directoryPath - - the path to the directoryOkapiIOException - if a file cannot be deleted.public static String getLocaleBasedFile(String baseName, String extension, LocaleId locale)
WARNING: Assumes default classLoader only!!
baseName - base name of the resourceextension - resource file extensionlocale - locale of the resource we are looking forpublic static String getPartBeforeFile(URI uri)
uri - The URI to process.Copyright © 2021. All rights reserved.