Class SbFileHelper

java.lang.Object
com.openinventor.inventor.Inventor
com.openinventor.inventor.helpers.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 Details

    • isAccessible

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

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

      public static String expandString(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 String getTempFilename(String path, 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(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(String directory)
      Create the specified directory.

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

      Returns:
      -1 if creation failed.

    • getBaseName

      public static String getBaseName(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 String getCurrentDirectory()
      Returns the current directory.
    • fileSystemURLToFilename

      public static String fileSystemURLToFilename(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 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 String toWindowsPath(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 String getDirName(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 String toUnixPath(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(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(String filename)
      Returns true if the filename is a network url like: http:// or ftp://.
    • getExtension

      public static String getExtension(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(String directory)
      Sets the current working directory. Returns 0 if successful, else one of the POSIX "chdir" error codes.
    • makeFileSystemURL

      public static String makeFileSystemURL(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(String path)
      Returns true if the specified path starts with a Microsoft Windows drive letter.
    • isFileSystemUrl

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