Interface FileService

  • All Superinterfaces:
    Service

    public interface FileService
    extends Service
    This class provides the ability to manipulate and query files, directories, and partitions at runtime. It is used, for example, by files beans, file-system bean conditions, ASCII file update beans, the Destination wizard panel, etc.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFERRED
      The constant used with deleteFile when delete is deferred.
      static int DIRECTORIES
      Indicates what type of files to return to the getDirectoryList() method.
      static java.lang.String FAT16
      The constant used with getPartitionFormat for FAT16 partitions.
      static java.lang.String FAT32
      The constant used with getPartitionFormat for FAT32 partitions.
      static int FILES
      Indicates what type of files to return to the getDirectoryList() method.
      static int FILES_AND_DIRECTORIES  
      static int FIXED
      The constant used with getPartitionType for FIXED partitions.
      static java.lang.String HOME_DIR
      The constant used with getNamedDirectory to return the directory for home files.
      static java.lang.String HPFS
      The constant used with getPartitionFormat for HPFS partitions.
      static java.lang.String HPFS386
      The constant used with getPartitionFormat for HPFS partitions.
      static java.lang.String INSTALL_DIR
      The constant used with getNamedDirectory to return the root directory for the program files on the system.
      static java.lang.String JFS
      The constant used with getpartitionFormat for JFS partitions.
      static java.lang.String LIB_DIR
      The constant used with getNamedDirectory to return the directory for the library files on the system.
      static java.lang.String LOG_DIR
      The constant used with getNamedDirectory to return the directory for writing log files.
      static java.lang.String NAME  
      static java.lang.String NTFS
      The constant used with getPartitionFormat for NTFS partitions.
      static int REMOVABLE
      The constant used with getPartitionType for REMOVABLE partitions.
      static int SUCCESS
      The constant used with deleteFile when delete succeeds.
      static java.lang.String TEMP_DIR
      The constant used with getNamedDirectory to return the directory for writing temporary files.
      static java.lang.String TIMESTAMP
      The constant used with getNamedDirectory to return a filename fragment generated using the current time.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void appendBinaryFile​(java.lang.String fileName, byte[] content)
      Appends bytes to a binary file.
      void appendToAsciiFile​(java.lang.String fileName, java.lang.String[] content)
      Appends lines to an ASCII file.
      long calculateDirectorySize​(java.lang.String dirName)
      Calculates the size of a given directory recursively and returns the total size (in bytes).
      boolean canRead​(java.lang.String file)
      This method is useful to developers when creating a custom bean.
      boolean comparePaths​(java.lang.String path1, java.lang.String path2)
      Verifies whether or not two paths are the same, taking into account multiple path separators and folder relocators within the path (such as "/." and "/..").
      void copyDirectory​(java.lang.String source, java.lang.String target, boolean copySubDirectories, boolean overwrite)
      This method is useful to developers when creating a custom bean.
      int copyFile​(java.lang.String sourceFileName, java.lang.String destinationFileName, boolean overwrite)
      This method is useful to developers when creating a custom bean.
      void createAsciiFile​(java.lang.String fileName, java.lang.String[] content)
      This method is useful to developers when creating a custom bean.
      void createAsciiFile​(java.lang.String fileName, java.lang.String[] content, java.lang.String fileEncoding)
      This method is useful to developers when creating a custom bean.
      void createBinaryFile​(java.lang.String fileName, byte[] content)
      This method is useful to developers when creating a custom bean.
      void createDirectory​(java.lang.String directoryName)
      Creates a directory on the target system.
      java.lang.String[] createDirectoryReturnNew​(java.lang.String directoryName)
      This method is useful to developers when creating a custom bean.
      java.lang.String createFileName​(java.lang.String context, java.lang.String fileName)
      This method is useful to developers when creating a custom bean.
      void createSymbolicLink​(java.lang.String target, java.lang.String linkName, boolean forceLink)
      This method is used to create a symbolic link on unix based platforms.
      int deleteDirectory​(java.lang.String directory)
      This method is useful to developers when creating a custom bean.
      int deleteDirectory​(java.lang.String directory, boolean ifEmpty, boolean includeSubDirs)
      This method is useful to developers when creating a custom bean.
      int deleteFile​(java.lang.String fileName)
      This method is useful to developers when creating a custom bean.
      boolean fileExists​(java.lang.String fileName)
      This method is useful to developers when creating a custom bean.
      java.lang.String formatSizeAsBytes​(long bytes)
      Formats the specified number of bytes as a human-readable string.
      int getAsciiFileLineCount​(java.lang.String fileName)
      Returns the number of lines in an ASCII file.
      java.lang.String[] getDirectoryList​(java.lang.String dir, int type)
      Gets a list of files in a directory.
      FileAttributes getFileAttributes​(java.lang.String file)
      This method is useful to developers when creating a custom bean.
      java.lang.String getFileOwner​(java.lang.String file)
      Gets a file's owner.
      java.lang.String getFileOwnerGroup​(java.lang.String file)
      Gets a file's owner group.
      int getFileSize​(java.lang.String fileName)
      Returns the size of an a file (in bytes).
      java.lang.String getName​(java.lang.String pathName)
      Gets the name portion of the supplied path name.
      java.lang.String getNamedDirectory​(java.lang.String directoryName)
      Returns the directory for the specified type.
      java.lang.String getParent​(java.lang.String child)
      Returns the parent directory of the specified directory.
      java.lang.String getPartitionFormat​(java.lang.String partition)
      This method is useful to developers when creating a custom bean.
      long getPartitionFreeSpace​(java.lang.String partitionName)
      This method is useful to developers when creating a custom bean.
      long getPartitionFreeSpace​(java.lang.String partitionName, long requiredBytes)
      This method is useful to developers when creating a custom bean.
      java.lang.String getPartitionName​(java.lang.String absolutePath, java.lang.String[] partitionNames)
      Maps the specified path into a valid partition out of a list of partition names.
      java.lang.String getPartitionName​(java.lang.String absolutePath, java.lang.String[] partitionNames, java.lang.String defaultPartition)
      Maps the specified path into a valid partition out of a list of partition names.
      java.lang.String[] getPartitionNames()
      This method is useful to developers when creating a custom bean.
      int getPartitionType​(java.lang.String directory)
      This method is useful to developers when creating a custom bean.
      java.lang.String getPathSeparator()
      Gets the path separator for the file system this service is executing on.
      char getPathSeparatorChar()
      Gets the path separator character for the file system this service is executing on.
      java.lang.String getPlatformId()
      NOTE : This API is for internal use.
      java.lang.String getSeparator()
      Returns the separator for the file system on which this service is executing.
      char getSeparatorChar()
      Returns the separator character for the file system on which this service is executing.
      int getSystemUMask()
      Returns the umask setting for the current process.
      boolean isAbsolute​(java.lang.String fileName)
      This method is useful to developers when creating a custom bean.
      boolean isDirectory​(java.lang.String file)
      This method is useful to developers when creating a custom bean.
      boolean isDirectoryWritable​(java.lang.String directory)
      This method is useful to developers when creating a custom bean.
      boolean isFile​(java.lang.String file)
      This method is useful to developers when creating a custom bean.
      int moveFile​(java.lang.String sourceFileName, java.lang.String destinationFileName, boolean overwrite)
      This method is useful to developers when creating a custom bean.
      java.lang.String normalizeFileName​(java.lang.String fileName)
      This method is useful to developers when creating a custom bean.
      java.lang.String normalizeFileName​(java.lang.String fileName, char normalSeparator)
      This method is useful to developers when creating a custom bean.
      java.lang.String[] readAsciiFile​(java.lang.String fileName)
      Returns all of the lines of an ASCII file.
      java.lang.String[] readAsciiFile​(java.lang.String fileName, java.lang.String fileEncoding)
      Returns all of the lines of an ASCII file.
      int readAsciiFile​(java.lang.String fileName, java.lang.String[] linesRead, int start, int number)
      Reads lines in an ASCII file, starting at a specified line, and reading a specified number of lines.
      int readBinaryFile​(java.lang.String fileName, byte[] bytesRead, int start, int number)
      Reads bytes in a binary file, starting at a specified offset, and reading a specified number of bytes.
      void removeSymbolicLink​(java.lang.String linkName)
      This method is used to remove a symbolic link on unix based platforms.
      void setFileAttributes​(java.lang.String file, FileAttributes attributes)
      Sets the attributes of the specified file.
      void setFileCreated​(java.lang.String fileName, long date)
      Changes the created date for the specified file.
      void setFileExecutable​(java.lang.String file)
      Sets the attributes of the specified file to be an executable.
      void setFileModified​(java.lang.String fileName, long date)
      This method is useful to developers when creating a custom bean.
      void setFileOwner​(java.lang.String file, java.lang.String userid)
      Sets a file's owner.
      void setFileOwnerGroup​(java.lang.String file, java.lang.String groupid)
      Sets a file's owner group.
      void setFileTimes​(java.lang.String fileName, long creationDate, long accessDate, long writeDate)
      Changes the dates for the specified file.
      void setSystemUMask​(int mode)
      Modifies the system umask for the current process.
      boolean supportsLongFileNames​(java.lang.String partition)
      This method is useful to developers when creating a custom bean.
      void updateAsciiFile​(java.lang.String fileName, java.lang.String[] lines, int start)
      Updates the lines in an ASCII file starting at and including the specified line.
      void updateBinaryFile​(java.lang.String fileName, byte[] bytes, int start)
      Updates the bytes in a binary file starting at and including the specified offset.
      void validateFileName​(java.lang.String fileName)
      Validates the specified file name.
    • Field Detail

      • NAME

        static final java.lang.String NAME
      • FILES

        static final int FILES
        Indicates what type of files to return to the getDirectoryList() method.
        See Also:
        Constant Field Values
      • DIRECTORIES

        static final int DIRECTORIES
        Indicates what type of files to return to the getDirectoryList() method.
        See Also:
        Constant Field Values
      • INSTALL_DIR

        static final java.lang.String INSTALL_DIR
        The constant used with getNamedDirectory to return the root directory for the program files on the system.
        See Also:
        Constant Field Values
      • LIB_DIR

        static final java.lang.String LIB_DIR
        The constant used with getNamedDirectory to return the directory for the library files on the system.
        See Also:
        Constant Field Values
      • TEMP_DIR

        static final java.lang.String TEMP_DIR
        The constant used with getNamedDirectory to return the directory for writing temporary files.
        See Also:
        Constant Field Values
      • LOG_DIR

        static final java.lang.String LOG_DIR
        The constant used with getNamedDirectory to return the directory for writing log files.
        See Also:
        Constant Field Values
      • TIMESTAMP

        static final java.lang.String TIMESTAMP
        The constant used with getNamedDirectory to return a filename fragment generated using the current time. This is useful for creating a unique file name, e.g., / .log.
        See Also:
        Constant Field Values
      • HOME_DIR

        static final java.lang.String HOME_DIR
        The constant used with getNamedDirectory to return the directory for home files.
        See Also:
        Constant Field Values
      • FAT16

        static final java.lang.String FAT16
        The constant used with getPartitionFormat for FAT16 partitions.
        See Also:
        Constant Field Values
      • NTFS

        static final java.lang.String NTFS
        The constant used with getPartitionFormat for NTFS partitions.
        See Also:
        Constant Field Values
      • HPFS

        static final java.lang.String HPFS
        The constant used with getPartitionFormat for HPFS partitions.
        See Also:
        Constant Field Values
      • HPFS386

        static final java.lang.String HPFS386
        The constant used with getPartitionFormat for HPFS partitions.
        See Also:
        Constant Field Values
      • JFS

        static final java.lang.String JFS
        The constant used with getpartitionFormat for JFS partitions.
        See Also:
        Constant Field Values
      • FAT32

        static final java.lang.String FAT32
        The constant used with getPartitionFormat for FAT32 partitions.
        See Also:
        Constant Field Values
      • FIXED

        static final int FIXED
        The constant used with getPartitionType for FIXED partitions.
        See Also:
        Constant Field Values
      • REMOVABLE

        static final int REMOVABLE
        The constant used with getPartitionType for REMOVABLE partitions.
        See Also:
        Constant Field Values
      • SUCCESS

        static final int SUCCESS
        The constant used with deleteFile when delete succeeds.
        See Also:
        Constant Field Values
      • DEFERRED

        static final int DEFERRED
        The constant used with deleteFile when delete is deferred.
        See Also:
        Constant Field Values
    • Method Detail

      • deleteFile

        int deleteFile​(java.lang.String fileName)
                throws ServiceException
        This method is useful to developers when creating a custom bean. Deletes the specified file from the target system.
        Returns:
        SUCCESS if the operation was carried out immediately, or DEFERRED if the operation will be carried out later when the specified file is no longer locked.
        Throws:
        ServiceException - if an error occurred during the operation.
      • deleteDirectory

        int deleteDirectory​(java.lang.String directory)
                     throws ServiceException
        This method is useful to developers when creating a custom bean. Performs the safe deletion of a directory -- The directory is only deleted if it empty. (Note: This method calls the alternate form of deleteDirectory using the appropriate parameters for safeguarding non-empty directories.)
        Returns:
        SUCCESS if the operation was carried out immediately, or DEFERRED if the operation will be carried out later when the specified directory is no longer locked.
        Throws:
        ServiceException
      • deleteDirectory

        int deleteDirectory​(java.lang.String directory,
                            boolean ifEmpty,
                            boolean includeSubDirs)
                     throws ServiceException
        This method is useful to developers when creating a custom bean. Removes the specified directory according to the following table:

        ifEmpty includeSubDirs result
        true true Delete all empty directories in specified directory tree, including the specified directory if it is empty, after processing its subdirectories.
        true false Delete only specified directory if empty.
        false true Delete specified directory tree no matter what. Any files or directories in use should be deleted at a later time when they have been unlocked.
        false false Delete all files in the specified directory only . Remove the directory itself if it is empty after removing the files. Files in use should be deleted at a later time when they have been unlocked.

        Parameters:
        directory - The fully qualified directory name to delete.
        ifEmpty - If "true", only empty directories are deleted.
        includeSubdirs - A flag indicating whether or not subdirectories should also be deleted. If the value is "true", the ifEmpty flag applies to each directory that was considered for deletion.
        Returns:
        SUCCESS if the operation was carried out immediately, or DEFERRED if the operation will be carried out later when the specified file is no longer locked.
        Throws:
        ServiceException - if an error occurred during the operation.
      • createDirectory

        void createDirectory​(java.lang.String directoryName)
                      throws ServiceException
        Creates a directory on the target system. This method is useful to developers when creating a custom bean.
        Throws:
        ServiceException - if an error occurred during the operation
      • createDirectoryReturnNew

        java.lang.String[] createDirectoryReturnNew​(java.lang.String directoryName)
                                             throws ServiceException
        This method is useful to developers when creating a custom bean. Creates a directory on the target system and returns a String array containing each directory that was created. Each element in the array is an absolute path, and parent directories preceed child directories.

        For example, if you call this method passing "/home/myself/subdir1/subdir2", and "/home/myself" already exists, but "/home/myself/subdir1" does not exist, this method will return an array containing:

      • /home/myself/subdir1
      • /home/myself/subdir1/subdir2
Parameters:
directoryName - The name of the directory to create.
Returns:
A String array indicating the directories created during this procedure.
Throws:
ServiceException - if an error occurred during the operation