Package digilib.io

Class FileOps


  • public class FileOps
    extends Object
    • Field Detail

      • imageExtensions

        public static List<String> imageExtensions
      • textExtensions

        public static List<String> textExtensions
      • svgExtensions

        public static List<String> svgExtensions
      • HINT_BASEDIRS

        public static final Integer HINT_BASEDIRS
      • HINT_FILEEXT

        public static final Integer HINT_FILEEXT
      • HINT_DIRS

        public static final Integer HINT_DIRS
    • Constructor Detail

      • FileOps

        public FileOps()
    • 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
      • getImageExtensions

        public static List<String> getImageExtensions()
        Returns:
        the image extensions
      • getTextExtensionIterator

        public static Iterator<String> getTextExtensionIterator()
        Returns:
        the Iterator
      • getTextExtensions

        public static List<String> getTextExtensions()
        Returns:
        the extensions
      • getSVGExtensionIterator

        public static Iterator<String> getSVGExtensionIterator()
        Returns:
        the extensions
      • getSvgExtensions

        public static List<String> getSvgExtensions()
        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 FileClass
        file - the File
        scaleDirs - 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 Files
        filter - 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 type
        value - 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: