Class SbFileHelper


  • public class SbFileHelper
    extends Inventor
    Utilities class for file management. Portable utility functions to manage files and manage file path strings.

    File path strings can contain SoPreference (environment) variable names preceded by the '$' (dollar sign) character. These names are expanded to their defined value before passing the string to the operating system. For example, "$OIVHOME/data/models/bird.iv" could be used to access a file installed by the Open Inventor SDK. If the specified name does not have a defined value, the name is used as-is.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String cleanUpPath​(java.lang.String path)
      Removes all multiple occurences of '/' in the path.
      static boolean containsWindowsDrive​(java.lang.String path)
      Returns true if the specified path starts with a Microsoft Windows drive letter.
      static int createDirectory​(java.lang.String directory)
      Create the specified directory.
      static java.lang.String expandString​(java.lang.String string)
      Returns a new version of the string with "$NAME" SoPreference variable names expanded to their defined value.
      static java.lang.String fileSystemURLToFilename​(java.lang.String url)
      Converts a file system URL to a regular filename
      E.g "file:///c:/temp/test.dat" becomes "c:/temp/test.dat".
      static java.lang.String getBaseName​(java.lang.String fullFilePath)
      Returns the filename part of a full path string.
      static java.lang.String getCurrentDirectory()
      Returns the current directory.
      static java.lang.String getDirName​(java.lang.String fullFilePath)
      Returns the directory path part of a full path string.
      static java.lang.String getExtension​(java.lang.String filename)
      Returns the extension part of the specified filename.
      static java.lang.String getTempDirectory()
      Returns the path to the temporary directory used by the system.
      static java.lang.String getTempFilename​(java.lang.String path, java.lang.String prefix)
      Returns a temporary filename.
      static boolean isAccessible​(java.lang.String filename)
      Calls isAccessible(filename, SbFileHelper.FileAccess.valueOf( SbFileHelper.FileAccess.READ.getValue() )).
      static boolean isAccessible​(java.lang.String filename, SbFileHelper.FileAccess mode)
      Returns true if a file is accessible
      The default value of the mode parameter is READ_ONLY.
      static boolean isFileSystemUrl​(java.lang.String filename)
      Returns true if the filename is a file system URL like: file://...
      static boolean isUrl​(java.lang.String filename)
      Returns true if the filename is a network url like: http:// or ftp://.
      static java.lang.String makeFileSystemURL​(java.lang.String filename)
      Converts a filename to a file system URL.
      static int removeFile​(java.lang.String fileName)
      Removes the specified file.
      static int setCurrentDirectory​(java.lang.String directory)
      Sets the current working directory.
      void setValue​(SbFileHelper copyFrom)  
      static java.lang.String toUnixPath​(java.lang.String path)
      Converts a Microsoft Windows path (with '\') to a Unix path (with '/').
      static java.lang.String toWindowsPath​(java.lang.String path)
      Converts a Unix path (with '/') to a Microsoft Windows path (with '\').
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isAccessible

        public static boolean isAccessible​(java.lang.String filename)
        Calls isAccessible(filename, SbFileHelper.FileAccess.valueOf( SbFileHelper.FileAccess.READ.getValue() )).
      • cleanUpPath

        public static java.lang.String cleanUpPath​(java.lang.String path)
        Removes all multiple occurences of '/' in the path.
      • expandString

        public static java.lang.String expandString​(java.lang.String string)
        Returns a new version of the string with "$NAME" SoPreference variable names expanded to their defined value. If the specified name does not have a defined value, the name is copied as-is.
      • setValue

        public void setValue​(SbFileHelper copyFrom)
      • getTempFilename

        public static java.lang.String getTempFilename​(java.lang.String path,
                                                       java.lang.String prefix)
        Returns a temporary filename.

        Parameters:
        path - The path to the directory which will contain the file (see getTempDirectory()).

        prefix - The filename prefix.

        Returns:
        A temporary filename.

      • isAccessible

        public static boolean isAccessible​(java.lang.String filename,
                                           SbFileHelper.FileAccess mode)
        Returns true if a file is accessible
        The default value of the mode parameter is READ_ONLY.

        Note that this method cannot be used to test if it is possible to create a file for writing. It only works on existing files.

        Parameters:
        filename - The file to test.

        mode - The file access mode

        Returns:
        true if the file is accessible, false otherwise.

      • createDirectory

        public static int createDirectory​(java.lang.String directory)
        Create the specified directory.

        Parameters:
        directory - The path of the directory to create.

        Returns:
        -1 if creation failed.

      • getBaseName

        public static java.lang.String getBaseName​(java.lang.String fullFilePath)
        Returns the filename part of a full path string.
        E.g If the full path is "/tmp/a.tmp", the function will return "a.tmp"

        Parameters:
        fullFilePath - The full path string

        Returns:
        The extracted filename

      • getCurrentDirectory

        public static java.lang.String getCurrentDirectory()
        Returns the current directory.
      • fileSystemURLToFilename

        public static java.lang.String fileSystemURLToFilename​(java.lang.String url)
        Converts a file system URL to a regular filename
        E.g "file:///c:/temp/test.dat" becomes "c:/temp/test.dat".

        Parameters:
        url - The URL to convert.

        Returns:
        The converted filename.

      • getTempDirectory

        public static java.lang.String getTempDirectory()
        Returns the path to the temporary directory used by the system. Useful with the getTempFilename() method. The path ends with an operating system dependent directory separator.
      • toWindowsPath

        public static java.lang.String toWindowsPath​(java.lang.String path)
        Converts a Unix path (with '/') to a Microsoft Windows path (with '\').

        Parameters:
        path - The path to convert.

        Returns:
        The converted path

      • getDirName

        public static java.lang.String getDirName​(java.lang.String fullFilePath)
        Returns the directory path part of a full path string.
        E.g. If the full path is "/tmp/a.tmp", returns "/tmp/"

        Parameters:
        fullFilePath - The full path string

        Returns:
        The directory path string

      • toUnixPath

        public static java.lang.String toUnixPath​(java.lang.String path)
        Converts a Microsoft Windows path (with '\') to a Unix path (with '/').
        A leading "\\" (used for network paths) is not converted.

        Parameters:
        path - The path to convert.

        Returns:
        The converted path

      • removeFile

        public static int removeFile​(java.lang.String fileName)
        Removes the specified file.

        Parameters:
        fileName - The file to remove.

        Returns:
        An error code, 0 if there was no error.

      • isUrl

        public static boolean isUrl​(java.lang.String filename)
        Returns true if the filename is a network url like: http:// or ftp://.
      • getExtension

        public static java.lang.String getExtension​(java.lang.String filename)
        Returns the extension part of the specified filename.

        It does not include the '.' used to separate the file name and the extension!
        E.g. If the filename is "test.dat", the function returns "dat".

      • setCurrentDirectory

        public static int setCurrentDirectory​(java.lang.String directory)
        Sets the current working directory. Returns 0 if successful, else one of the POSIX "chdir" error codes.
      • makeFileSystemURL

        public static java.lang.String makeFileSystemURL​(java.lang.String filename)
        Converts a filename to a file system URL.

        Actually it just adds the string file:// to the filename, if and only if the filename is not already a file system URL.

        Parameters:
        filename - The file name to convert

        Returns:
        The converted filename.

      • containsWindowsDrive

        public static boolean containsWindowsDrive​(java.lang.String path)
        Returns true if the specified path starts with a Microsoft Windows drive letter.
      • isFileSystemUrl

        public static boolean isFileSystemUrl​(java.lang.String filename)
        Returns true if the filename is a file system URL like: file://...