Class FileStorageHelper


  • public class FileStorageHelper
    extends Object
    A collection of utility routines used by the file storage system. Routines exist to:
    • encode filenames for safe storage
    • decode filenames to their original values
    • convert an ID (with namespaces) to a path, relative to the root directory
    • convert an ID (with namespaces) to an absolute path
    • convert an ID (with namespaces) and a filename to a full path for storing the file
    • Field Detail

      • PATH_SINGLE_CHARACTER_SOURCES

        public static final char[] PATH_SINGLE_CHARACTER_SOURCES
      • PATH_SINGLE_CHARACTER_TARGETS

        public static final char[] PATH_SINGLE_CHARACTER_TARGETS
      • NAME_SINGLE_CHARACTER_SOURCES

        public static final char[] NAME_SINGLE_CHARACTER_SOURCES
        Same as for path, except that a period is not translated.
      • NAME_SINGLE_CHARACTER_TARGETS

        public static final char[] NAME_SINGLE_CHARACTER_TARGETS
        Same as for path, except that a period is not translated.
      • WINDOWS_RESERVED_NAMES

        public static final String[] WINDOWS_RESERVED_NAMES
        Windows reserves these names (case-insensitive), so they can't be used for directories or files.
    • Constructor Detail

      • FileStorageHelper

        public FileStorageHelper()
    • Method Detail

      • encodeName

        public static String encodeName​(String filename)
        Encode the filename as needed to guard against illegal characters.
      • decodeName

        public static String decodeName​(String stored)
        Restore the filename to its original form, removing the encoding.
      • id2Path

        public static String id2Path​(String id,
                                     Map<Character,​String> namespacesMap)
        Translate the object ID to a relative directory path. A recognized namespace is translated to its prefix, and illegal characters are encoded. The resulting string is broken up into 3-character directory names (or less). Windows reserved words are prefixed with tilde.
      • getPathToIdDirectory

        public static File getPathToIdDirectory​(String id,
                                                Map<Character,​String> namespacesMap,
                                                File rootDir)
        Translate the object ID and the file storage root directory into a full path to the directory that would represent that ID.
      • getFullPath

        public static File getFullPath​(File rootDir,
                                       String id,
                                       String filename,
                                       Map<Character,​String> namespacesMap)
        Translate the object ID, the file storage root directory and the filename into a full path to where the file would be stored.