org.apache.ivy.util

Class FileUtil

public final class FileUtil extends Object

Utility class used to deal with file related operations, like copy, full reading, symlink, ...
Method Summary
static Stringconcat(String dir, String file)
static booleancopy(File src, File dest, CopyProgressListener l)
static booleancopy(File src, File dest, CopyProgressListener l, boolean overwrite)
static voidcopy(URL src, File dest, CopyProgressListener l)
static voidcopy(File src, URL dest, CopyProgressListener l)
static voidcopy(InputStream src, File dest, CopyProgressListener l)
static voidcopy(InputStream src, OutputStream dest, CopyProgressListener l)
static booleanforceDelete(File file)
Recursively delete file
static ListgetPathFiles(File root, File file)
Returns a list of Files composed of all directories being parent of file and child of root + file and root themselves.
static CollectionlistAll(File dir, Collection ignore)
Returns a collection of all Files being contained in the given directory, recursively, including directories.
static StringreadEntirely(BufferedReader in)
Reads the whole BufferedReader line by line, using \n as line separator for each line.
static StringreadEntirely(File f)
Reads the entire content of the file and returns it as a String.
static StringreadEntirely(InputStream is)
Reads the entire content of the InputStream and returns it as a String.
static FileresolveFile(File file, String filename)
static voidsymlink(File src, File dest, CopyProgressListener l, boolean overwrite)

Method Detail

concat

public static String concat(String dir, String file)

copy

public static boolean copy(File src, File dest, CopyProgressListener l)

copy

public static boolean copy(File src, File dest, CopyProgressListener l, boolean overwrite)

copy

public static void copy(URL src, File dest, CopyProgressListener l)

copy

public static void copy(File src, URL dest, CopyProgressListener l)

copy

public static void copy(InputStream src, File dest, CopyProgressListener l)

copy

public static void copy(InputStream src, OutputStream dest, CopyProgressListener l)

forceDelete

public static boolean forceDelete(File file)
Recursively delete file

Parameters: file the file to delete

Returns: true if the deletion completed successfully (ie if the file does not exist on the filesystem after this call), false if a deletion was not performed successfully.

getPathFiles

public static List getPathFiles(File root, File file)
Returns a list of Files composed of all directories being parent of file and child of root + file and root themselves. Example: getPathFiles(new File("test"), new File("test/dir1/dir2/file.txt")) => {new File("test/dir1"), new File("test/dir1/dir2"), new File("test/dir1/dir2/file.txt") } Note that if root is not an ancester of file, or if root is null, all directories from the file system root will be returned.

listAll

public static Collection listAll(File dir, Collection ignore)
Returns a collection of all Files being contained in the given directory, recursively, including directories.

Parameters: dir The directory from which all files, including files in subdirectory) are extracted. ignore a Collection of filenames which must be excluded from listing

Returns: A collectoin containing all the files of the given directory and it's subdirectories.

readEntirely

public static String readEntirely(BufferedReader in)
Reads the whole BufferedReader line by line, using \n as line separator for each line.

Note that this method will add a final \n to the last line even though there is no new line character at the end of last line in the original reader.

The BufferedReader is closed when this method returns.

Parameters: in the BufferedReader to read from

Returns: a String with the whole content read from the BufferedReader

Throws: IOException if an IO problems occur during reading

readEntirely

public static String readEntirely(File f)
Reads the entire content of the file and returns it as a String.

Parameters: f the file to read from

Returns: a String with the file content

Throws: IOException if an IO problems occurs during reading

readEntirely

public static String readEntirely(InputStream is)
Reads the entire content of the InputStream and returns it as a String.

The input stream is closed when this method returns.

Parameters: is the InputStream to read from

Returns: a String with the input stream content

Throws: IOException if an IO problems occurs during reading

resolveFile

public static File resolveFile(File file, String filename)

symlink

public static void symlink(File src, File dest, CopyProgressListener l, boolean overwrite)