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 booleancompareFileDates(Date date1, Date date2) For some reason modification milliseconds for some files are unstable, use this function to compare file dates ignoring milliseconds.static booleancompareFiles(File file1, File file2) Compares two files for directories/files synchronization purposes.static voidCopies one file, existing file will be overridden.static voidcopyFolder(File src, File dest) Copies folder recursively, existing files will be overriddenstatic voidcopyFolder(File src, File dest, boolean recursive) Copies folder, existing files will be overriddenstatic voidcopyFolder(File src, File dest, boolean recursive, boolean onlyNew) Copies folder.static voidcopyFolder(File src, File dest, boolean recursive, boolean onlyNew, FileFilter filter) Copies folder.static voidcopyStream(InputStream in, OutputStream out, int bufferSize) Copies streams.static booleanemptyFolder(File folder) Recursively deletes whole content of the given folder.static URLUtility method to convert aFileobject to a local URL.static InputStreamOpens input stream for given resource.static booleanisResourceExists(URL url) Checks if resource exist and can be opened.static voidsynchronizeFolders(File src, File dest) Performs one-way directories synchronization comparing files only, not folders.static voidsynchronizeFolders(File src, File dest, FileFilter filter) Performs one-way directories synchronization comparing files only, not folders.static FileUtility method to convert local URL to aFileobject.
-
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, ifnullall 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:
trueif 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:
trueif 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:
trueif 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, ifnullall 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:
trueif 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 aFileobject.- Parameters:
url- an URL- Returns:
- file object for given URL or
nullif URL is not local
-
file2url
Utility method to convert aFileobject 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
-