Package org.java.plugin.util
Class IoUtil
java.lang.Object
org.java.plugin.util.IoUtil
Input/Output, File and URL/URI related utilities.
- Version:
- $Id: IoUtil.java,v 1.9 2007/04/17 17:39:52 ddimon Exp $
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
compareFileDates
(Date date1, Date date2) For some reason modification milliseconds for some files are unstable, use this function to compare file dates ignoring milliseconds.static boolean
compareFiles
(File file1, File file2) Compares two files for directories/files synchronization purposes.static void
Copies one file, existing file will be overridden.static void
copyFolder
(File src, File dest) Copies folder recursively, existing files will be overriddenstatic void
copyFolder
(File src, File dest, boolean recursive) Copies folder, existing files will be overriddenstatic void
copyFolder
(File src, File dest, boolean recursive, boolean onlyNew) Copies folder.static void
copyFolder
(File src, File dest, boolean recursive, boolean onlyNew, FileFilter filter) Copies folder.static void
copyStream
(InputStream in, OutputStream out, int bufferSize) Copies streams.static boolean
emptyFolder
(File folder) Recursively deletes whole content of the given folder.static URL
Utility method to convert aFile
object to a local URL.static InputStream
Opens input stream for given resource.static boolean
isResourceExists
(URL url) Checks if resource exist and can be opened.static void
synchronizeFolders
(File src, File dest) Performs one-way directories synchronization comparing files only, not folders.static void
synchronizeFolders
(File src, File dest, FileFilter filter) Performs one-way directories synchronization comparing files only, not folders.static File
Utility method to convert local URL to aFile
object.
-
Method Details
-
copyFile
Copies one file, existing file will be overridden.- Parameters:
src
- source file to copy FROMdest
- destination file to copy TO- Throws:
IOException
- if any I/O error has occurred
-
copyFolder
Copies folder recursively, existing files will be overridden- Parameters:
src
- source folderdest
- target folder- Throws:
IOException
- if any I/O error has occurred
-
copyFolder
Copies folder, existing files will be overridden- Parameters:
src
- source folderdest
- target folderrecursive
- iftrue
, processes folder recursively- Throws:
IOException
- if any I/O error has occurred
-
copyFolder
public static void copyFolder(File src, File dest, boolean recursive, boolean onlyNew) throws IOException Copies folder.- Parameters:
src
- source folderdest
- target folderrecursive
- iftrue
, processes folder recursivelyonlyNew
- iftrue
, target file will be overridden if it is older than source file only- Throws:
IOException
- if any I/O error has occurred
-
copyFolder
public static void copyFolder(File src, File dest, boolean recursive, boolean onlyNew, FileFilter filter) throws IOException Copies folder.- Parameters:
src
- source folderdest
- target folderrecursive
- iftrue
, processes folder recursivelyonlyNew
- iftrue
, target file will be overridden if it is older than source file onlyfilter
- file filter, optional, ifnull
all files will be copied- Throws:
IOException
- if any I/O error has occurred
-
copyStream
Copies streams.- Parameters:
in
- source streamout
- destination streambufferSize
- buffer size to use- Throws:
IOException
- if any I/O error has occurred
-
emptyFolder
Recursively deletes whole content of the given folder.- Parameters:
folder
- folder to be emptied- Returns:
true
if given folder becomes empty or not exists
-
compareFiles
Compares two files for directories/files synchronization purposes.- Parameters:
file1
- one file to comparefile2
- another file to compare- Returns:
true
if file names are equal (case sensitive), files have equal lengths and modification dates (milliseconds ignored)- See Also:
-
compareFileDates
For some reason modification milliseconds for some files are unstable, use this function to compare file dates ignoring milliseconds.- Parameters:
date1
- first file modification datedate2
- second file modification date- Returns:
true
if files modification dates are equal ignoring milliseconds
-
synchronizeFolders
Performs one-way directories synchronization comparing files only, not folders.- Parameters:
src
- source folderdest
- target folder- Throws:
IOException
- if any I/O error has occurred- See Also:
-
synchronizeFolders
Performs one-way directories synchronization comparing files only, not folders.- Parameters:
src
- source folderdest
- target folderfilter
- file filter, optional, ifnull
all files will be included into synchronization process- Throws:
IOException
- if any I/O error has occurred- See Also:
-
isResourceExists
Checks if resource exist and can be opened.- Parameters:
url
- absolute URL which points to a resource to be checked- Returns:
true
if given URL points to an existing resource
-
getResourceInputStream
Opens input stream for given resource. This method behaves differently for different URL types:- for local files it returns buffered file input stream;
- for local JAR files it reads resource content into memory buffer and returns byte array input stream that wraps those buffer (this prevents locking JAR file);
- for common URL's this method simply opens stream to that URL using standard URL API.
- Parameters:
url
- resource URL- Returns:
- input stream for given resource
- Throws:
IOException
- if any I/O error has occurred
-
url2file
Utility method to convert local URL to aFile
object.- Parameters:
url
- an URL- Returns:
- file object for given URL or
null
if URL is not local
-
file2url
Utility method to convert aFile
object to a local URL.- Parameters:
file
- a file object- Returns:
- absolute URL that points to the given file
- Throws:
MalformedURLException
- if file can't be represented as URL for some reason
-