Package org.wso2.carbon.server.util
Class FileUtils
- java.lang.Object
-
- org.wso2.carbon.server.util.FileUtils
-
public class FileUtils extends Object
taken from the commons file utils class. we didnt want to use the library. hence copied the source
-
-
Constructor Summary
Constructors Constructor Description FileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcloseQuietly(InputStream input)Unconditionally close anInputStream.static voidcloseQuietly(OutputStream output)Unconditionally close anOutputStream.static intcopy(InputStream input, OutputStream output)Copy bytes from anInputStreamto anOutputStream.static voidcopyDirectory(File srcDir, File destDir)Copies a whole directory to a new location preserving the file dates.static voidcopyDirectory(File srcDir, File destDir, boolean preserveFileDate)Copies a whole directory to a new location.static voidcopyFile(File srcFile, File destFile, boolean preserveFileDate)Copy file method.static booleandeleteDir(File dir)Deletes all files and subdirectories under dir.static FilegetFile(File parentFile, String fileName)static Map<String,String>readJarsWithMD5(BufferedReader bufferedReader)static List<String>readLinesToList(BufferedReader bufferedReader)
-
-
-
Method Detail
-
copyDirectory
public static void copyDirectory(File srcDir, File destDir) throws IOException
Copies a whole directory to a new location preserving the file dates. This method copies the specified directory and all its child directories and files to the specified destination. The destination is the new location and name of the directory. The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.- Parameters:
srcDir- an existing directory to copy, must not be nulldestDir- the new directory, must not be null- Throws:
NullPointerException- if source or destination is nullIOException- if source or destination is invalid- Since:
- Commons IO 1.1
-
copyDirectory
public static void copyDirectory(File srcDir, File destDir, boolean preserveFileDate) throws IOException
Copies a whole directory to a new location. This method copies the contents of the specified source directory to within the specified destination directory. The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.- Parameters:
srcDir- an existing directory to copy, must not be nulldestDir- the new directory, must not be nullpreserveFileDate- true if the file date of the copy should be the same as the original- Throws:
NullPointerException- if source or destination is nullIOException- if source or destination is invalid- Since:
- Commons IO 1.1
-
copyFile
public static void copyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException
Copy file method.- Parameters:
srcFile- the validated source file, not nulldestFile- the validated destination file, not nullpreserveFileDate- whether to preserve the file date- Throws:
IOException- if an error occurs
-
closeQuietly
public static void closeQuietly(OutputStream output)
Unconditionally close anOutputStream. Equivalent toOutputStream.close(), except any exceptions will be ignored. This is typically used in finally blocks.- Parameters:
output- the OutputStream to close, may be null or already closed
-
closeQuietly
public static void closeQuietly(InputStream input)
Unconditionally close anInputStream. Equivalent toInputStream.close(), except any exceptions will be ignored. This is typically used in finally blocks.- Parameters:
input- the InputStream to close, may be null or already closed
-
copy
public static int copy(InputStream input, OutputStream output) throws IOException
Copy bytes from anInputStreamto anOutputStream. This method buffers the input internally, so there is no need to use aBufferedInputStream.- Parameters:
input- theInputStreamto read fromoutput- theOutputStreamto write to- Returns:
- the number of bytes copied
- Throws:
NullPointerException- if the input or output is nullIOException- if an I/O error occurs- Since:
- Commons IO 1.1
-
deleteDir
public static boolean deleteDir(File dir)
Deletes all files and subdirectories under dir. Returns true if all deletions were successful. If a deletion fails, the method stops attempting to delete and returns false.- Parameters:
dir- The directory to be deleted- Returns:
- true if the directory and its descendents were deleted
-
readLinesToList
public static List<String> readLinesToList(BufferedReader bufferedReader) throws IOException
- Throws:
IOException
-
readJarsWithMD5
public static Map<String,String> readJarsWithMD5(BufferedReader bufferedReader) throws IOException
- Throws:
IOException
-
-