Package digilib.io
Class FileOps
- java.lang.Object
-
- digilib.io.FileOps
-
public class FileOps extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FileOps.FileClass
(package private) static class
FileOps.ImageFileFilter
FileFilter for image types (helper class for getFile)(package private) static class
FileOps.ReadableFileFilter
FileFilter for general files(package private) static class
FileOps.SVGFileFilter
FileFilter for svg types (helper class for getFile).(package private) static class
FileOps.TextFileFilter
FileFilter for text types (helper class for getFile)
-
Field Summary
Fields Modifier and Type Field Description static Map<String,String>
fileTypes
static Integer
HINT_BASEDIRS
static Integer
HINT_DIRS
static Integer
HINT_FILEEXT
static List<String>
imageExtensions
static List<String>
svgExtensions
static List<String>
textExtensions
-
Constructor Summary
Constructors Constructor Description FileOps()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
basename(String fn)
Extract the base of a file name (sans extension).static FileOps.FileClass
classForFilename(String fn)
get the file class for the filename (by extension)static FileOps.FileClass
classForMimetype(String mt)
returns the file class for a mime-typestatic void
emptyDirectory(File dir)
clean up any broken and unfinished files from the temporary directory.static String
extname(String fn)
Extract the extension of a file name.static DocuDirent
fileForClass(FileOps.FileClass fileClass, File file, FsDirectory[] scaleDirs)
Factory for DocuDirents based on file class.static String
filename(String fn)
Extract the file name of a (digilib) path name.static File[]
filterFiles(File[] files, FileFilter filter)
Filters a list of Files through a FileFilter.static FileFilter
filterForClass(FileOps.FileClass fileClass)
Factory for FileFilters (image or text).static Iterator<String>
getImageExtensionIterator()
static List<String>
getImageExtensions()
static Iterator<String>
getSVGExtensionIterator()
static List<String>
getSvgExtensions()
static Iterator<String>
getTextExtensionIterator()
static List<String>
getTextExtensions()
static boolean
isMimeTypeSendable(String mimeType)
Returns if the mime-type is browser compatible.static boolean
isValidFilename(String filename)
Returns if the filename is valid.static String
mimeForFile(File f)
get the mime type for a file format (by extension)static Map<Integer,Object>
newHints(Integer type, Object value)
Creates a new hints Map with the given first element.static String
normalName(String pathname)
Normalize a path name.static String
parent(String fn)
Extract the parent directory of a (digilib) path name.static String[]
pathToArray(String paths)
convert a string with a list of pathnames into an array of strings using the system's path separator stringstatic Predicate<Path>
streamFilterForClass(FileOps.FileClass fileClass)
Factory for DirectoryStream.Filters (image or text).
-
-
-
Method Detail
-
classForMimetype
public static FileOps.FileClass classForMimetype(String mt)
returns the file class for a mime-type- Parameters:
mt
- the mime type- Returns:
- the FileClass
-
mimeForFile
public static String mimeForFile(File f)
get the mime type for a file format (by extension)- Parameters:
f
- the File- Returns:
- the mime type
-
classForFilename
public static FileOps.FileClass classForFilename(String fn)
get the file class for the filename (by extension)- Parameters:
fn
- the fn- Returns:
- the FileClass
-
getImageExtensionIterator
public static Iterator<String> getImageExtensionIterator()
- Returns:
- the Iterator
-
getTextExtensionIterator
public static Iterator<String> getTextExtensionIterator()
- Returns:
- the Iterator
-
getSVGExtensionIterator
public static Iterator<String> getSVGExtensionIterator()
- Returns:
- the extensions
-
pathToArray
public static String[] pathToArray(String paths)
convert a string with a list of pathnames into an array of strings using the system's path separator string- Parameters:
paths
- the paths string- Returns:
- the paths
-
basename
public static String basename(String fn)
Extract the base of a file name (sans extension). Returns the filename without the extension. The extension is the part behind the last dot in the filename. If the filename contains no dot the full file name is returned.- Parameters:
fn
- the fn- Returns:
- the base name
-
extname
public static String extname(String fn)
Extract the extension of a file name. Returns the extension of a file name. The extension is the part behind the last dot in the filename. If the filename has no dot the empty string is returned.- Parameters:
fn
- the fn- Returns:
- the extension
-
parent
public static String parent(String fn)
Extract the parent directory of a (digilib) path name. Returns the parent directory of a path name. The parent is the part before the last slash in the path name. If the path name has no slash the empty string is returned.- Parameters:
fn
- the fn- Returns:
- the parent
-
filename
public static String filename(String fn)
Extract the file name of a (digilib) path name. Returns the file name of a path name. The file name is the part after the last slash in the path name. If the path name has no slash the original string is returned.- Parameters:
fn
- the fn- Returns:
- the file name
-
normalName
public static String normalName(String pathname)
Normalize a path name. Removes leading and trailing slashes. Returns null if there is other unwanted stuff in the path name.- Parameters:
pathname
- the pathname- Returns:
- the pathname
-
isValidFilename
public static boolean isValidFilename(String filename)
Returns if the filename is valid. Currently only checks if filename starts with a dot.- Parameters:
filename
- the filename- Returns:
- is valid
-
filterForClass
public static FileFilter filterForClass(FileOps.FileClass fileClass)
Factory for FileFilters (image or text).- Parameters:
fileClass
- the FileClass- Returns:
- the FileFilter
-
streamFilterForClass
public static Predicate<Path> streamFilterForClass(FileOps.FileClass fileClass)
Factory for DirectoryStream.Filters (image or text).- Parameters:
fileClass
- the FileClass- Returns:
- the FileFilter
-
fileForClass
public static DocuDirent fileForClass(FileOps.FileClass fileClass, File file, FsDirectory[] scaleDirs)
Factory for DocuDirents based on file class. Returns an ImageSet, TextFile or SVGFile. scaleDirs are only for ImageFilesets.- Parameters:
fileClass
- the FileClassfile
- the FilescaleDirs
- optional additional parameters- Returns:
- the DocuDirent
-
filterFiles
public static File[] filterFiles(File[] files, FileFilter filter)
Filters a list of Files through a FileFilter.- Parameters:
files
- the Filesfilter
- the FileFilter- Returns:
- the Files
-
newHints
public static Map<Integer,Object> newHints(Integer type, Object value)
Creates a new hints Map with the given first element.- Parameters:
type
- the typevalue
- the value- Returns:
- the Map
-
emptyDirectory
public static void emptyDirectory(File dir)
clean up any broken and unfinished files from the temporary directory.- Parameters:
dir
- the File
-
isMimeTypeSendable
public static boolean isMimeTypeSendable(String mimeType)
Returns if the mime-type is browser compatible.- Parameters:
mimeType
-- Returns:
-
-