public class FileSystemUtil
extends java.lang.Object
Constructor and Description |
---|
FileSystemUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
copyStream(java.io.InputStream is,
java.io.OutputStream out,
ProgressMonitor monitor)
copies data from in to out, sending the number of bytesTransferred to the monitor.
|
static java.io.File |
createTempFile(java.io.File localFile,
int timeoutSeconds)
create a temporary file, based on the name of the localFile.
|
static void |
deleteAllFiles(java.io.File dir,
java.lang.String regex)
delete all files under the directory, with names matching the regex.
|
static java.io.File |
downloadResourceAsFile(java.net.URI uri,
ProgressMonitor monitor)
download the URI as a file.
|
static void |
dumpToFile(java.io.InputStream in,
java.io.File f)
Dump the contents of the InputStream into a file.
|
static java.lang.String |
fromUri(java.net.URI uri)
canonical method for converting URI to human-readable string, containing
spaces and other illegal characters.
|
static javax.swing.filechooser.FileFilter |
getFileNameExtensionFilter(java.lang.String description,
java.lang.String ext)
get simple filter based on extension for use with JFileChooser.
|
static java.net.URI |
getParentUri(java.net.URI ruri)
return the parent of the URI, or null if this is not possible.
|
static void |
gunzip(java.io.File fz,
java.io.File file)
un-gzip the file.
|
static java.net.URI |
isCacheable(java.net.URI ruri)
return null if the URI is not cacheable, or the URI of the parent if it is.
|
static void |
maybeMkdirs(java.io.File file)
create the file folder if it does not exist.
|
static java.net.URI |
toUri(java.lang.String s)
encode the string as a URI.
|
static void |
unzip(java.io.File fz,
java.io.File file)
Deprecated.
use gunzip instead.
|
static void |
unzipFile(java.io.File zipFilePath,
java.io.File destDir)
Extracts a zip file specified by the zipFilePath to a directory specified by
destDirectory (will be created if does not exists).
|
static java.lang.String |
uriDecode(java.lang.String s)
convert "%20" to " ", etc, by using URLDecoder and catching the UnsupportedEncodingException that will never occur.
|
static java.lang.String |
uriEncode(java.lang.String surl)
convert " " to "%20", etc, by looking for and encoding illegal characters.
|
static void |
zip(java.io.File fz,
java.io.File dir)
create a zip file of everything with and under the directory.
|
public static void dumpToFile(java.io.InputStream in, java.io.File f) throws java.io.FileNotFoundException, java.io.IOException
in
- f
- java.io.FileNotFoundException
java.io.IOException
public static void unzip(java.io.File fz, java.io.File file) throws java.io.IOException
fz
- zipped input filefile
- unzipped destination filejava.io.IOException
public static void gunzip(java.io.File fz, java.io.File file) throws java.io.IOException
fz
- zipped input filefile
- unzipped destination filejava.io.IOException
public static void zip(java.io.File fz, java.io.File dir) throws java.io.IOException
fz
- the outputdir
- the root directory.java.io.IOException
public static void unzipFile(java.io.File zipFilePath, java.io.File destDir) throws java.io.IOException
zipFilePath
- destDir
- java.io.IOException
public static void deleteAllFiles(java.io.File dir, java.lang.String regex)
dir
- the directoryregex
- the regular expression, like ".*\.png"Glob.getRegex(java.lang.String)
public static void copyStream(java.io.InputStream is, java.io.OutputStream out, ProgressMonitor monitor) throws java.io.IOException
is
- the input stream, which will not be closed.out
- the output stream, which will not be closed.monitor
- a monitor, or null.java.io.IOException
public static java.net.URI isCacheable(java.net.URI ruri)
URI uri= new URL("http://autoplot.org/data/demos2011.xml").toURI();
URI parentUri= FileSystemUtil.isCacheable( uri );
if ( parentUri ) {
FileSystem fd= FileSystem.create(parentUri);
FileObject fo= fd.getFileObject( ruri.relativize(parentUri).toString() );
in= fo.getInputStream();
}
ruri
- public static java.net.URI getParentUri(java.net.URI ruri)
ruri
- public static void maybeMkdirs(java.io.File file) throws java.io.IOException
file
- java.io.IOException
public static java.lang.String uriEncode(java.lang.String surl)
surl
- public static java.lang.String uriDecode(java.lang.String s)
s
- public static java.lang.String fromUri(java.net.URI uri)
uri
- URI like URI("file:/home/jbf/ct/autoplot/bugs/1830227625/%5BajbTest%5D/")public static java.net.URI toUri(java.lang.String s)
s
- string representation of a path like file:/home/jbf/ct/autoplot/bugs/1830227625/[ajbTest]/public static java.io.File createTempFile(java.io.File localFile, int timeoutSeconds)
localFile
- which need not exist.timeoutSeconds
- the minimum number of seconds this file will exist.public static javax.swing.filechooser.FileFilter getFileNameExtensionFilter(java.lang.String description, java.lang.String ext)
description
- descriptions, like "png image file"ext
- file extension, like ".png"public static java.io.File downloadResourceAsFile(java.net.URI uri, ProgressMonitor monitor) throws java.io.IOException
uri
- monitor
- java.io.IOException