org.das2.util.filesystem.FileSystemUtil
FileSystemUtil( )
copyStream
copyStream( java.io.InputStream is, java.io.OutputStream out, ProgressMonitor monitor ) → void
copies data from in to out, sending the number of bytesTransferred to the monitor.
The input and output are not closed.
Parameters
is - the input stream, which will not be closed.
out - the output stream, which will not be closed.
monitor - a monitor, or null.
Returns:
void (returns nothing)
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
createTempFile
createTempFile( java.io.File localFile, int timeoutSeconds ) → File
create a temporary file, based on the name of the localFile. This will
be a different name, and may exist already. The problem with using
deleteOnExit, is that Autoplot may be running within a webserver that
doesn't exit. Java7 nio2 introduces more methods for cleaning up temporary
files, but even delete-on-close doesn't work because often a file is opened
and closed several times.
Parameters
localFile - which need not exist.
timeoutSeconds - the minimum number of seconds this file will exist.
Returns:
a new file that is a different but predictable name.
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
deleteAllFiles
deleteAllFiles( java.io.File dir, String regex ) → void
delete all files under the directory, with names matching the regex.
Parameters
dir - the directory
regex - the regular expression, like ".*\.png"
Returns:
void (returns nothing)
See Also:
Glob#getRegex(java.lang.String)
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
downloadResourceAsFile
downloadResourceAsFile( java.net.URI uri, ProgressMonitor monitor ) → File
download the URI as a file. Presently these must be files which can be in a FileSystem.
Parameters
uri - an URI
monitor - a ProgressMonitor
Returns:
a java.io.File
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
dumpToFile
dumpToFile( java.io.InputStream in, java.io.File f ) → void
Dump the contents of the InputStream into a file. If the inputStream comes
from a file, then java.nio is used to transfer the data quickly.
Parameters
in - an InputStream
f - a File
Returns:
void (returns nothing)
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
fromUri
fromUri( java.net.URI uri ) → String
canonical method for converting URI to human-readable string, containing
spaces and other illegal characters. Note pluses in the query part
are interpreted as spaces.
This was borrowed from Autoplot's URISplit code.
Parameters
uri - URI like URI("file:/home/jbf/ct/autoplot/bugs/1830227625/%5BajbTest%5D/")
Returns:
string representation of a path like file:/home/jbf/ct/autoplot/bugs/1830227625/[ajbTest]/
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
getFileNameExtensionFilter
getFileNameExtensionFilter( String description, String ext ) → FileFilter
get simple filter based on extension for use with JFileChooser.
Parameters
description - descriptions, like "png image file"
ext - file extension, like ".png"
Returns:
the FileFilter
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
getParentUri
getParentUri( java.net.URI ruri ) → URI
return the parent of the URI, or null if this is not possible.
Parameters
ruri - an URI
Returns:
a java.net.URI
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
gunzip
gunzip( java.io.File fz, java.io.File file ) → void
un-gzip the file. This is similar to the unix gunzip command.
Parameters
fz - zipped input file
file - unzipped destination file
Returns:
void (returns nothing)
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
isCacheable
isCacheable( java.net.URI ruri ) → URI
return null if the URI is not cacheable, or the URI of the parent if it is.
For example,
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();
}
Parameters
ruri - an URI
Returns:
the URI of the parent, or null.
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
maybeMkdirs
maybeMkdirs( java.io.File file ) → void
create the file folder if it does not exist. Throw an IOException if it failed.
Parameters
file - a File
Returns:
void (returns nothing)
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
toUri
toUri( String s ) → URI
encode the string as a URI. The following characters are encoded:
" " % < > [ ]
Parameters
s - string representation of a path like file:/home/jbf/ct/autoplot/bugs/1830227625/[ajbTest]/
Returns:
URI like URI("file:/home/jbf/ct/autoplot/bugs/1830227625/%5BajbTest%5D/")
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
unzip
Deprecated: use gunzip instead.
unzipFile
unzipFile( java.io.File zipFilePath, java.io.File destDir ) → void
Extracts a zip file specified by the zipFilePath to a directory specified by
destDirectory (will be created if does not exists).
From http://www.codejava.net/java-se/file-io/programmatically-extract-a-zip-file-using-java
Parameters
zipFilePath - a File
destDir - a File
Returns:
void (returns nothing)
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
uriDecode
uriDecode( String s ) → String
convert "%20" to " ", etc, by using URLDecoder and catching the UnsupportedEncodingException that will never occur.
Parameters
s - a String
Returns:
a String
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
uriEncode
uriEncode( String surl ) → String
convert " " to "%20", etc, by looking for and encoding illegal characters.
We can't just aggressively convert... Note too that colons still cause problems
on Windows and should not be used in file names!
Parameters
surl - a String
Returns:
a String
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]
zip
zip( java.io.File fz, java.io.File dir ) → void
create a zip file of everything with and under the directory.
Parameters
fz - the output
dir - the root directory.
Returns:
void (returns nothing)
[search for examples]
[view on GitHub]
[view on old javadoc]
[view source]