|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectucar.unidata.util.IOUtil
public class IOUtil
A set of io related utilities
| Nested Class Summary | |
|---|---|
static interface |
IOUtil.FileViewer
FileViewer is used to walk dir trees |
| Field Summary | |
|---|---|
static boolean |
debug
debug flag |
| Constructor Summary | |
|---|---|
IOUtil()
Default constructor; does nothing |
|
| Method Summary | |
|---|---|
static String |
cleanFileName(String name)
Remove illegal characters in the given filename |
static void |
copyFile(File from,
File to)
Copy from file to to file |
static void |
deleteDirectory(File root)
This will recursively delete all contents under the given directory. |
static List |
getDirectories(File dir,
boolean recurse)
Recursively descend (if recurse is true) through the given directory and return a list of all subdirectories. |
static List |
getDirectories(List dirs,
boolean recurse)
Recursively descend (if recurse is true) through the given directories and return a list of all subdirectories. |
static String |
getFileExtension(String f)
Return the file extension from the given file (including the "."). |
static String |
getFileRoot(String f)
Excise the filename from the given path and return the root. |
static List |
getFiles(File dir,
boolean recurse)
Recursively descend (if recurse is true) through the given directory and return a list of all files |
static List |
getFiles(List files,
File dir,
boolean recurse)
Recursively descend (if recurse is true) through the given directory and return a list of all files |
static List |
getFiles(List files,
File dir,
boolean recurse,
PatternFileFilter filter)
Recursively descend (if recurse is true) through the given directory and return a list of all files |
static String |
getFileTail(String f)
Gets the file name, removing any leading directory paths. |
static InputStream |
getInputStream(String filename)
Get an input stream for the filename |
static InputStream |
getInputStream(String filename,
Class origin)
Get an input stream for the filename |
static InputStream |
getInputStreamOLDWAY(String filename,
Class origin)
Get an input stream for the filename |
static List<String> |
getListing(String path,
Class c)
Lists the contents in the given file directory or java resource directory |
static File |
getMostRecentFile(File dir)
Find the youngest file in the given directory. |
static File |
getMostRecentFile(File dir,
FileFilter filter)
Find the youngest file in the given directory that matches the given FileFilter. |
static File |
getMostRecentFile(File dir,
FileFilter filter)
Find the youngest file in the given directory that matches the given FileFilter. |
static File[] |
getNormalFiles(File[] files)
Return an array of the file Files. |
static URL |
getURL(String filename,
Class origin)
Get an input stream for the filename |
static boolean |
hasSuffix(String fileOrUrl,
String suffix)
Does the given file or url have the given suffix |
static boolean |
isHtmlFile(String filenameOrUrl)
Determine if the given filename is an html file. |
static boolean |
isHtmlSuffix(String url)
Does the given url end with an html suffix. |
static boolean |
isHttpProtocol(String url)
Is the given url an http protocol. |
static boolean |
isImageFile(String filename)
Determine if the given filename is an image file (e.g., ends with .gif, .jpg, .jpeg, .png) |
static boolean |
isRelativePath(String path)
Is the given path relative |
static boolean |
isTextFile(String filename)
Determine if the given filename is a text file. |
static String |
joinDir(File f1,
String filename)
Return the String representation of the given filename joined to the given directory f1. |
static String |
joinDir(String f1,
String f2)
Return the String representation of the given filename joined to the given directory. |
static void |
main(String[] args)
test main |
static String |
makeDir(File f)
If the directory defined in the given argument f does not exist then make it. |
static String |
makeDir(String path)
If the directory defined in the given argument path does not exist then make it. |
static void |
makeDirRecursive(File f)
Make the directory. |
static void |
moveFile(File from,
File to)
Move the from file to the to file |
static void |
pruneEmptyDirectories(File root)
This will recursively prune empty subdirectories of the given root directory. |
static void |
pruneIfEmpty(File root)
This will recursively prune empty subdirectories of the given root directory. |
static byte[] |
readBytes(InputStream is)
Read in the bytes from the given InputStream Closes the InputStream argument. |
static byte[] |
readBytes(InputStream is,
Object loadId)
Read in the bytes from the given InputStream Closes the InputStream argument. |
static byte[] |
readBytes(InputStream is,
Object loadId,
boolean closeIt)
Read the bytes in the given input stream. |
static byte[] |
readBytesAndCache(String contentName,
String cacheGroup)
See if the content is in the perma-cache. |
static byte[] |
readBytesAndCache(String contentName,
String cacheGroup,
boolean unzipIfNeeded)
See if the content is in the perma-cache. |
static String |
readContents(File file)
Read the contents of a File. |
static String |
readContents(InputStream is)
Read in the bytes from the given InputStream and construct and return a String. |
static String |
readContents(String contentName)
Return the String contents of the specified contentName. |
static String |
readContents(String contentName,
Class origin)
Return the String contents of the specified contentName. |
static String |
readContents(String contentName,
Class origin,
String dflt)
Return the String contents of the specified contentName. |
static String |
readContents(String contentName,
String dflt)
Return the String contents of the specified contentName. |
static File[] |
sortFilesOnAge(File[] files,
boolean youngestFirst)
Sort the given files |
static File[] |
sortFilesOnAge(File directory,
FileFilter filter,
boolean youngestFirst)
Sort the files contained by the given directory and that (if non-null) match the given filter. |
static String |
stripExtension(String f)
Remove any file extension from the given file name. |
static File[] |
toFiles(List files)
Convert the toString value of the objects in the given files list to an array of File-s |
static void |
wait(File directory,
String filePattern,
double sleepSeconds)
Wait until there are new files in the given directory. |
static void |
wait(List files,
double sleepSeconds)
Wait until one or more of the files in the files list (File) has changed. |
static boolean |
walkDirectory(File dir,
IOUtil.FileViewer fileViewer)
Walk the dir tree with the given file viewer |
static boolean |
walkDirectory(File dir,
IOUtil.FileViewer fileViewer,
int level)
Walk the dir tree with the given file viewer |
static FileFilter |
wrapFilter(FileFilter filter)
Create a javaio FileFilter from the filechooser package file filter. |
static void |
writeBytes(File filename,
byte[] contents)
Write out a file to the File specified. |
static void |
writeFile(File filename,
String contents)
Write out a file to the File specified. |
static void |
writeFile(String filename,
String contents)
Write out a file to the filename specified. |
static void |
writeJarFile(String filename,
List files)
Write out the list of files to the jar file specified by filename |
static void |
writeJarFile(String filename,
List files,
String pathPrefix)
Write out the list of files to the jar file specified by filename |
static void |
writeJarFile(String filename,
List files,
String pathPrefix,
boolean makeFilesUnique)
Write out the list of files to the jar file specified by filename |
static int |
writeTo(InputStream from,
OutputStream to)
Copy the input stream to the output stream |
static int |
writeTo(InputStream from,
OutputStream to,
Object loadId,
int length)
Copy the input stream to the output stream |
static List |
writeTo(List urls,
String prefix,
String suffix)
Copy the files pointed to by the urls list to the directory/file pointed to by prefx. |
static List |
writeTo(List urls,
String prefix,
String suffix,
Object loadId)
Copy the files pointed to by the urls list to the directory/file pointed to by prefx. |
static int |
writeTo(URL from,
File file,
Object loadId)
Write to the file from the URL stream |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static boolean debug
| Constructor Detail |
|---|
public IOUtil()
| Method Detail |
|---|
public static boolean hasSuffix(String fileOrUrl,
String suffix)
fileOrUrl - The name of the file or urlsuffix - The suffix
public static File getMostRecentFile(File dir)
dir - The directory to search in.
public static File getMostRecentFile(File dir,
FileFilter filter)
FileFilter.
dir - The directory to search in.filter - The FileFilter to be used to limit what files we look at (may be null).
public static File[] sortFilesOnAge(File directory,
FileFilter filter,
boolean youngestFirst)
directory - The directoryfilter - The filteryoungestFirst - Ascending or descending
public static File[] getNormalFiles(File[] files)
files - Array of files
public static File[] sortFilesOnAge(File[] files,
boolean youngestFirst)
files - The filesyoungestFirst - Ascending or descending
public static File[] toFiles(List files)
files - List of files
public static FileFilter wrapFilter(FileFilter filter)
filter - The filechooser file filter
public static File getMostRecentFile(File dir,
FileFilter filter)
FileFilter.
dir - The directory to search in.filter - The filter to be used to limit what files we look at (may be null).
public static int writeTo(InputStream from,
OutputStream to)
throws IOException
from - input streamto - output
IOException - On badness
public static int writeTo(URL from,
File file,
Object loadId)
throws IOException
from - URL for inputfile - file for outputloadId - A JobManager loadId that, if set, can be used to
stop the load
IOException - problem writing to file.
public static int writeTo(InputStream from,
OutputStream to,
Object loadId,
int length)
throws IOException
from - input streamto - outputloadId - A JobManager loadId that, if set, can be used to
stop the loadlength - number of bytes to write
IOException - On badness
public static List writeTo(List urls,
String prefix,
String suffix)
throws IOException
urls - List of urls to copyprefix - file directory prefixsuffix - suffix
IOException - On badness
public static List writeTo(List urls,
String prefix,
String suffix,
Object loadId)
throws IOException
urls - List of urls to copyprefix - file directory prefixsuffix - suffixloadId - JobManager loadId
IOException - On badness
public static List<String> getListing(String path,
Class c)
path - may be a file directory path or a java resource directoryc - base class to use if its java resources
public static String getFileTail(String f)
f - The file path.
public static String getFileRoot(String f)
f - The file path.
public static String stripExtension(String f)
f - The file path.
public static String cleanFileName(String name)
name - The filename to be cleaned up
public static String getFileExtension(String f)
f - The file path.
public static void writeFile(String filename,
String contents)
throws FileNotFoundException,
IOException
filename - filename to write tocontents - file contents
FileNotFoundException - if the file does not exist
IOException - if there is a problem writing
public static void writeFile(File filename,
String contents)
throws FileNotFoundException,
IOException
File specified.
filename - File to write tocontents - file contents
FileNotFoundException - if the file does not exist
IOException - if there is a problem writing
public static void writeBytes(File filename,
byte[] contents)
throws FileNotFoundException,
IOException
File specified.
filename - File to write tocontents - file contents
FileNotFoundException - if the file does not exist
IOException - if there is a problem writing
public static void moveFile(File from,
File to)
throws FileNotFoundException,
IOException
from - File to moveto - The destination
FileNotFoundException - When we cannot find the file
IOException - When something untoward happens
public static void copyFile(File from,
File to)
throws FileNotFoundException,
IOException
from - File to copyto - The destination
FileNotFoundException - When we cannot find the file
IOException - When something untoward happenspublic static boolean isTextFile(String filename)
filename - The filename to check.
public static boolean isImageFile(String filename)
filename - The filename to check.
public static boolean isHtmlFile(String filenameOrUrl)
filenameOrUrl - The filename to check.
public static boolean isHtmlSuffix(String url)
url - The url
public static boolean isHttpProtocol(String url)
url - The url
public static InputStream getInputStream(String filename)
throws FileNotFoundException,
IOException
filename - name of file
FileNotFoundException - couldn't find the file
IOException - problem opening stream
public static InputStream getInputStream(String filename,
Class origin)
throws FileNotFoundException,
IOException
filename - name of fileorigin - relative origin point for file location
FileNotFoundException - couldn't find the file
IOException - problem opening stream
public static InputStream getInputStreamOLDWAY(String filename,
Class origin)
throws FileNotFoundException,
IOException
filename - name of fileorigin - relative origin point for file location
FileNotFoundException - couldn't find the file
IOException - problem opening stream
public static URL getURL(String filename,
Class origin)
throws FileNotFoundException,
IOException
filename - name of fileorigin - relative origin point for file location
FileNotFoundException - couldn't find the file
IOException - problem opening stream
public static String readContents(File file)
throws FileNotFoundException,
IOException
File. Used for reading text type
files (XML, HTML, etc)
file - file to read.
FileNotFoundException - couldn't find the file
IOException - problem opening stream
public static String readContents(String contentName,
String dflt)
contentName - URL or filenamedflt - default to return if a problem
public static String readContents(String contentName,
Class origin,
String dflt)
contentName - URL or filenameorigin - origin classdflt - default to return if a problem
public static String readContents(String contentName)
throws FileNotFoundException,
IOException
contentName - can either be a URL, a filename or a resource.
null if there is a problem.
FileNotFoundException - couldn't find the file
IOException - problem reading contentspublic static boolean isRelativePath(String path)
path - file path
public static String readContents(String contentName,
Class origin)
throws FileNotFoundException,
IOException
contentName - can either be a URL, a filename or a resource.origin - relative origin for path to file
null if there is a problem.
FileNotFoundException - couldn't find the file
IOException - problem reading contents
public static byte[] readBytesAndCache(String contentName,
String cacheGroup)
throws FileNotFoundException,
IOException
contentName - url or filenamecacheGroup - Cache group
FileNotFoundException - On badness
IOException - On badness
public static byte[] readBytesAndCache(String contentName,
String cacheGroup,
boolean unzipIfNeeded)
throws FileNotFoundException,
IOException
contentName - url or filenamecacheGroup - Cache groupunzipIfNeeded - IF true and if the url is a zip file then unzip it
FileNotFoundException - On badness
IOException - On badness
public static String readContents(InputStream is)
throws IOException
is - InputStream to read from
IOException - problem reading contents
public static byte[] readBytes(InputStream is)
throws IOException
is - InputStream to read from
IOException - problem reading contents
public static byte[] readBytes(InputStream is,
Object loadId)
throws IOException
is - InputStream to read fromloadId - Job manager load id
IOException - problem reading contents
public static byte[] readBytes(InputStream is,
Object loadId,
boolean closeIt)
throws IOException
is - The input streamloadId - If non-null check with the JobManager if we should continuecloseIt - If true then close the input stream
IOException - On badness
public static String joinDir(String f1,
String f2)
f1 - directory pathf2 - filename
public static String joinDir(File f1,
String filename)
f1 - directory pathfilename - filename
public static String makeDir(String path)
path - directory to make
public static String makeDir(File f)
f - directory as a file
public static final void makeDirRecursive(File f)
f - directory to make
public static List getFiles(File dir,
boolean recurse)
dir - The directory to look atrecurse - Do we recurse
public static List getFiles(List files,
File dir,
boolean recurse)
files - The list of files to add todir - The directory to look atrecurse - Do we recurse
public static List getFiles(List files,
File dir,
boolean recurse,
PatternFileFilter filter)
files - The list of files to add todir - The directory to look atrecurse - Do we recursefilter - If non-null then use this to find files
public static boolean walkDirectory(File dir,
IOUtil.FileViewer fileViewer)
throws Exception
dir - dirfileViewer - viewer
Exception - on badness_
public static boolean walkDirectory(File dir,
IOUtil.FileViewer fileViewer,
int level)
throws Exception
dir - dirfileViewer - viewerlevel - tree depth
Exception - on badness_
public static List getDirectories(File dir,
boolean recurse)
dir - The directory to look atrecurse - Do we recurse
public static List getDirectories(List dirs,
boolean recurse)
dirs - List of directories to look atrecurse - Do we recurse
public static void pruneIfEmpty(File root)
root - Directory to prunepublic static void pruneEmptyDirectories(File root)
root - Directory to prunepublic static void deleteDirectory(File root)
root - Directory to delete
public static void wait(File directory,
String filePattern,
double sleepSeconds)
directory - The directoryfilePattern - The patternsleepSeconds - Sleep this number of seconds between each check
public static void wait(List files,
double sleepSeconds)
files - List of File-ssleepSeconds - Seconds to sleep between checks.
public static void main(String[] args)
throws Exception
args - cmd line args
Exception - On badness
public static void writeJarFile(String filename,
List files)
throws IOException
filename - jar file namefiles - list of files
IOException - On badness
public static void writeJarFile(String filename,
List files,
String pathPrefix)
throws IOException
filename - jar file namefiles - list of filespathPrefix - If not null this is the prefx we add to the jar entry
IOException - On badness
public static void writeJarFile(String filename,
List files,
String pathPrefix,
boolean makeFilesUnique)
throws IOException
filename - jar file namefiles - list of filespathPrefix - If not null this is the prefx we add to the jar entrymakeFilesUnique - If true then make all of the file names unique in case of conflict
IOException - On badness
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||