Skip navigation links

Oracle® Fusion Middleware Java API Reference for Oracle Coherence
12c (12.1.3.0.0)

E47890-01


com.tangosol.io
Class FileHelper

java.lang.Object
  extended by com.tangosol.io.FileHelper


public class FileHelper
extends java.lang.Object

A Collection of helper methods for files.

Author:
jh 2012.07.13

Constructor Summary
FileHelper()
           

 

Method Summary
static long calculateDirectoryUsage(java.io.File fileDir, boolean fRecurse)
          Return the approximate disk usage in bytes for a given directory optionally including sub-dirs.
static void copyDir(java.io.File fileDirFrom, java.io.File fileDirTo, java.io.FileFilter filter)
          Create a deep copy of the specified directory into the specified target directory.
static void copyFile(java.io.File fileFrom, java.io.File fileTo)
          Copy the specified file according to the source and destination File objects preserving the time-stamp of the source.
static java.io.File createTempDir()
          Create a unique temporary directory.
static void deleteDir(java.io.File fileDir)
          Delete a directory recursively.
static java.io.File ensureDir(java.io.File file)
          Validate that the given File represents a directory, creating it if it doesn't already exist.
static boolean isSymlink(java.io.File file)
          Determine whether the specified file is a symbolic link rather than an actual file.
static boolean isWindows()
          Determine if a Windows file system is in use.
static java.nio.channels.FileLock lockFile(java.io.File file)
          Obtain an exclusive lock on the specified file.
static void moveDir(java.io.File fileDirFrom, java.io.File fileDirTo)
          Move the specified directory to the specified destination path.
static void moveFile(java.io.File fileFrom, java.io.File fileTo)
          Move the specified file to the specified destination path.
static java.lang.String toFilename(java.lang.String sName)
          Given a string, return a derivative version that is safe to use for a filename.
static void unlockFile(java.nio.channels.FileLock lock)
          Release an exclusive lock on a file.

 

Constructor Detail

FileHelper

public FileHelper()

Method Detail

isWindows

public static boolean isWindows()
Determine if a Windows file system is in use.
Returns:
true if the file system is Windows, false otherwise

toFilename

public static java.lang.String toFilename(java.lang.String sName)
Given a string, return a derivative version that is safe to use for a filename.
Parameters:
sName - the string
Returns:
a derivative of the given string that is safe to use as a filename (may be the same as the string supplied)

isSymlink

public static boolean isSymlink(java.io.File file)
                         throws java.io.IOException
Determine whether the specified file is a symbolic link rather than an actual file.
Parameters:
file - the file to check
Returns:
true if the file is a symbolic link
Throws:
java.io.IOException - if an IO error occurs while checking the file

createTempDir

public static java.io.File createTempDir()
Create a unique temporary directory.
Returns:
a unique temporary directory

ensureDir

public static java.io.File ensureDir(java.io.File file)
                              throws java.io.IOException
Validate that the given File represents a directory, creating it if it doesn't already exist.
Parameters:
file - the File to check
Returns:
the validated File
Throws:
java.io.IOException

copyDir

public static void copyDir(java.io.File fileDirFrom,
                           java.io.File fileDirTo,
                           java.io.FileFilter filter)
                    throws java.io.IOException
Create a deep copy of the specified directory into the specified target directory.
Parameters:
fileDirFrom - the directory to copy from
fileDirTo - the directory to copy into
filter - an optional filter that can be used to filter out files from the copy operation
Throws:
java.io.IOException - if an error occurred copying the directory

deleteDir

public static void deleteDir(java.io.File fileDir)
                      throws java.io.IOException
Delete a directory recursively.
Parameters:
fileDir - directory to delete
Throws:
java.io.IOException - if an error occurred deleting the directory

moveDir

public static void moveDir(java.io.File fileDirFrom,
                           java.io.File fileDirTo)
                    throws java.io.IOException
Move the specified directory to the specified destination path.
Parameters:
fileDirFrom - the directory to move
fileDirTo - the destination path
Throws:
java.io.IOException - if an error occurred moving the directory

lockFile

public static java.nio.channels.FileLock lockFile(java.io.File file)
Obtain an exclusive lock on the specified file. The lock should be released with the unlockFile method.
Parameters:
file - the file to lock
Returns:
a FileLock if an exclusive lock was obtained, null otherwise

unlockFile

public static void unlockFile(java.nio.channels.FileLock lock)
Release an exclusive lock on a file.
Parameters:
lock - the exclusive lock to release

copyFile

public static void copyFile(java.io.File fileFrom,
                            java.io.File fileTo)
                     throws java.io.IOException
Copy the specified file according to the source and destination File objects preserving the time-stamp of the source.
Parameters:
fileFrom - the File to copy from
fileTo - the File to copy to
Throws:
java.io.IOException - if an error occurred copying the file

moveFile

public static void moveFile(java.io.File fileFrom,
                            java.io.File fileTo)
                     throws java.io.IOException
Move the specified file to the specified destination path.
Parameters:
fileFrom - the file to move
fileTo - the destination path
Throws:
java.io.IOException - if an error occurred moving the file

calculateDirectoryUsage

public static long calculateDirectoryUsage(java.io.File fileDir,
                                           boolean fRecurse)
Return the approximate disk usage in bytes for a given directory optionally including sub-dirs. This does not take into account the block sizes of the O/S (e.g. a file may be 1 byte but may take up 2K).
Parameters:
fileDir - the directory to interrogate
fRecurse - indicates if we should recurse through sub-directories that are found
Returns:
the number of total bytes used by the files in the directory

Skip navigation links

Oracle® Fusion Middleware Java API Reference for Oracle Coherence
12c (12.1.3.0.0)

E47890-01


Copyright © 2000, 2014, Oracle and/or its affiliates. All rights reserved.