|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.pepper.platform.util.FileUtils
public class FileUtils
Utilities for file manipulation.
Field Summary | |
---|---|
static int |
DEFAULT_BUFFER_SIZE
Size (in bytes) of the buffer to use when copying files |
Constructor Summary | |
---|---|
FileUtils()
|
Method Summary | |
---|---|
static void |
copyFile(File sourceFile,
File destFile)
Copy the specified file. |
static void |
copyFile(File sourceFile,
File destFile,
boolean recurse)
Copy the specified file. |
static void |
copyFile(File srcFile,
File destFile,
int bufferSize)
Copies a file to another file |
static void |
copyFile(File srcFile,
FileOutputStream outStream,
int bufferSize)
Copies source file to destination output stream |
static void |
copyFile(File srcFile,
FileOutputStream outStream,
int bufferSize,
boolean syncToDisk,
com.pepper.platform.util.CopyListener copyListener)
Copies source file to destination output stream |
static String |
copyFile(File progBaseDir,
String destDataPath,
File srcFile)
Copies the file to the specified location. |
static void |
copyFile(File srcFile,
URL destURL,
int bufferSize)
Copies source file to destination url |
static String[] |
copyFiles(File progBaseDir,
String destDataPath,
File[] files)
Copy a set of files to a specified destimation (from pepperfilechooser) |
static void |
copyFileToDir(File sourceFile,
File destDir,
boolean recurse)
Copy the specified file to the specified directory. |
static void |
copyStream(InputStream in,
OutputStream out,
int bufferSize)
Wraps the streams in buffered streams and copies the input stream to the output stream. |
static void |
copyStream(InputStream in,
OutputStream out,
int bufferSize,
com.pepper.platform.util.CopyListener listener)
Wraps the streams in buffered streams and copies the input stream to the output stream. |
static File |
generateUniqueFile(File file)
Given a file, returns a new file with a unique name if the the specified file exists. |
static String |
getFileNameStripExtension(File f)
Return the name of the file without the file name extension |
static long |
getFileSizes(List files)
Return the size (in bytes) of all Files in the given list. |
static String |
getFileType(File f)
|
static List |
getRecursiveDirListing(File dir)
Return a list of all files in the the given directory and any subdirectories. |
static List |
getRecursiveDirListing(File dir,
FileFilter filter)
Return a list of all files in the the given directory and any subdirectories. |
static List |
getRecursiveDirListing(File dir,
List fileTypes)
Return a list of all files in the the given directory and any subdirectories. |
static String |
getRelativeFilename(File file,
File baseDir)
|
static String |
getRelativeFilename(File file,
String baseDir)
Given a file and a base directory specification, return the path of the file relative to the base directory iff the file is in the base directory or one of its subdirectories; otherwise return the file's path as passed in. |
static Collection |
getRelativeFiles(Collection files,
File baseDir)
Given an collection of File s, return a collection of
NameValue objects where the name is the path of the file
relative to the baseDir and the value is the File object
itself. |
static File |
getTempDir()
Return a directory specification suitable for use as a temporary directory. |
static boolean |
wipedir(File dir)
Recursively delete a directory and its contents, including all subdirectories. |
static boolean |
wipedir(File dir,
boolean onExit)
Recursively delete a directory and its contents, including all subdirectories. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_BUFFER_SIZE
Constructor Detail |
---|
public FileUtils()
Method Detail |
---|
public static boolean wipedir(File dir)
dir
- directory to wipe out
public static boolean wipedir(File dir, boolean onExit)
dir
- directory to wipe outonExit
- true to delete files on VM exit, false to delete
them immediately
public static String getRelativeFilename(File file, String baseDir)
TODO: This method needs a rewrite. There are a number of edge cases (basedir = "", etc) that aren't supported well.
file
- file to get the path from. Must not be null, but file
does not need to exist on disk.baseDir
- directory specification. Must not be null, but directory
does not need to exist on disk.
file.getPath()
.public static String getRelativeFilename(File file, File baseDir)
FileUtils.getRelativeFilename(File, String)
public static Collection getRelativeFiles(Collection files, File baseDir)
File
s, return a collection of
NameValue
objects where the name is the path of the file
relative to the baseDir and the value is the File
object
itself.
files
- Collection of File
sbaseDir
- base directory, used to calculate relative paths
public static String getFileType(File f)
public static String getFileNameStripExtension(File f)
public static List getRecursiveDirListing(File dir)
dir
- Directory to return the listing for
File
s for all files in the directory and
its subdirectoriespublic static List getRecursiveDirListing(File dir, List fileTypes)
dir
- Directory to return the listing forfileTypes
- List of file types to filter on; null to return all file types
File
s for all files in the directory and
its subdirectoriespublic static List getRecursiveDirListing(File dir, FileFilter filter)
dir
- Directory to return the listing forfilter
- Filter for files to accept, or null to accept all files.
File
s for all files in the directory and
its subdirectoriespublic static void copyFile(File srcFile, File destFile, int bufferSize) throws Exception
srcFile
- a File
valuedestFile
- a File
valuebufferSize
- an int
value
Exception
public static void copyFile(File srcFile, URL destURL, int bufferSize) throws Exception
srcFile
- a File
valuedestURL
- an URL
valuebufferSize
- an int
value
Exception
- if an error occurspublic static void copyFile(File srcFile, FileOutputStream outStream, int bufferSize) throws Exception
srcFile
- a File
valueoutStream
- a FileOutputStream
valuebufferSize
- an int
value
Exception
- if an error occurspublic static void copyFile(File srcFile, FileOutputStream outStream, int bufferSize, boolean syncToDisk, com.pepper.platform.util.CopyListener copyListener) throws Exception
srcFile
- a File
valueoutStream
- a FileOutputStream
valuebufferSize
- an int
valuesyncToDisk
- if true performs a sync operation on the FileDescriptor
for the FileOutputStream which causes the data to get flushed to the
removable mediacopyListener
- optional listener that gets notified on each chunk read
and when the copy is complete
Exception
- if an error occurspublic static void copyFileToDir(File sourceFile, File destDir, boolean recurse)
sourceFile
- the source file. Must exist on disk.destDir
- the destination directory.recurse
- true to recursively copy all subdirectories of
sourceFile
if it is a directorypublic static void copyFile(File sourceFile, File destFile, boolean recurse)
sourceFile
- the source file. Must exist on disk.destFile
- the destination file.recurse
- true to recursively copy all subdirectories of
sourceFile
if it is a directorypublic static void copyFile(File sourceFile, File destFile)
sourceFile
- the source file. Must exist on disk.destFile
- the destination file.public static long getFileSizes(List files)
files
- List of File
s
public static String[] copyFiles(File progBaseDir, String destDataPath, File[] files) throws Exception
progBaseDir
- a File
valuedestDataPath
- a String
valuefiles
- a File[]
value
File[]
value
Exception
- if an error occurspublic static String copyFile(File progBaseDir, String destDataPath, File srcFile) throws Exception
progBaseDir
- a File
valuedestDataPath
- a String
valuesrcFile
- a File
value
File
value
Exception
- if an error occurspublic static void copyStream(InputStream in, OutputStream out, int bufferSize) throws IOException
in
- the input stream.out
- the output stream.bufferSize
- the buffer size to use.
IOException
public static void copyStream(InputStream in, OutputStream out, int bufferSize, com.pepper.platform.util.CopyListener listener) throws IOException
in
- the input stream.out
- the output stream.bufferSize
- the buffer size to use.listener
- the class that is notified of copy events.
IOException
public static File getTempDir()
public static File generateUniqueFile(File file)
file
- the file to use to determine if the name
is unique.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |