FileUtils

public class FileUtils

Fields

chownScript

public static String chownScript

Methods

createFolders

public static Undoable createFolders(File folder)

delete

public static Undoable delete(File file)

delete

public static Undoable delete(File file, boolean recursive)

Delete a file undoable. If file is a directory and ‘recursive’ is true the directory and all of its sub folders are deleted. If file is a directory and ‘recursive’ is false file is deleted unless it has sub folders. If file is an actual file (and not a directory) the file is deleted. Otherwise, nothing happens.

Parameters:
  • file

  • recursive

Throws:

getChecksum

public static String getChecksum(File file)

Get the HEXed SHA-512 checksum of a file or a folder. The Checksum C of a folder f is calculated by (recursively): C(f) = C(C(f_name) + C(f_subfile_1) + … + C(f_subfile_N)) while f_name is the (String) name of f and f_subfile_1 to f_subfile_N are the alphabetically ordered subfiles and subfolders of f. The alphabetical order is defined by UTF16.

Parameters:
  • file

Returns:

SHA-512 Checksum

getMimeType

public static String getMimeType(File file)

Guess the MIME type of a file. This is based on the unix program ‘file –mime-type’ and might not work on other systems.

Parameters:
  • file

getSize

public static Long getSize(File file)

Get the size of a file or folder.

Parameters:
  • file

isSubDirSymlinkSave

public static boolean isSubDirSymlinkSave(File file, File root)

Return true iff file is not a simlink to a directory and root is not a simlink.

Symlinks are not allowed for the root. Symlinks are allowed only for a File object if it is a file symlink, not a directory symlink.

Parameters:
  • file

  • root

Throws:
  • RuntimeException, – if subdir is symlink on a directory or if the root is a simlink.

isSymlinkPointingTo

public static boolean isSymlinkPointingTo(File symlink, File target)
Parameters:
  • symlink

  • target

Returns:

true, if symlink is a symbolic link and pointing to target. false otherwise

rename

public static Undoable rename(File file, File target)

runChownScript

public static void runChownScript(File file)

testChownScript

public static void testChownScript()
Throws:

toHex

public static String toHex(byte[] binary)

Convert a byte array to HEX

Parameters:
  • b

Returns:

hexadecimal (as String).