<h2>org.das2.util.filesystem.FileSystemUtil</h2><p></p>
<h2>FileSystemUtil( )</h2>
<p></p>

<hr>
<a name="copyStream"></a>
<h2>copyStream</h2>
copyStream( <a href='https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html'>java.io.InputStream</a> is, <a href='https://docs.oracle.com/javase/8/docs/api/java/io/OutputStream.html'>java.io.OutputStream</a> out, <a href='http://www-pw.physics.uiowa.edu/~jbf/autoplot/doc/org/das2/util/monitor/ProgressMonitor.html'>ProgressMonitor</a> monitor ) &rarr; void

<p>copies data from in to out, sending the number of bytesTransferred to the monitor.
 The input and output are not closed.</p>

<h3>Parameters</h3>
is - the input stream, which will not be closed.
<br>
out - the output stream, which will not be closed.
<br>
monitor - a monitor, or null.

<h3>Returns:</h3>
void (returns nothing)

<br><br>
<a href="https://github.com/autoplot/dev/search?q=copyStream&unscoped_q=copyStream">[search for examples]</a>
 <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/filesystem/FileSystemUtil.md">[view on GitHub]</a>
 <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/filesystem/FileSystemUtil.html#copyStream">[view on old javadoc]</a>
 <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/filesystem/FileSystemUtil.java">[view source]</a>
<br>
<br>
<hr>
<a name="createTempFile"></a>
<h2>createTempFile</h2>
createTempFile( <a href='https://docs.oracle.com/javase/8/docs/api/java/io/File.html'>java.io.File</a> localFile, int timeoutSeconds ) &rarr; <a href='https://docs.oracle.com/javase/8/docs/api/java/io/File.html'>java.io.File</a>

<p>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.</p>

<h3>Parameters</h3>
localFile - which need not exist.
<br>
timeoutSeconds - the minimum number of seconds this file will exist.

<h3>Returns:</h3>
a new file that is a different but predictable name.
<br><br>
<a href="https://github.com/autoplot/dev/search?q=createTempFile&unscoped_q=createTempFile">[search for examples]</a>
 <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/filesystem/FileSystemUtil.md">[view on GitHub]</a>
 <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/filesystem/FileSystemUtil.html#createTempFile">[view on old javadoc]</a>
 <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/filesystem/FileSystemUtil.java">[view source]</a>
<br>
<br>
<hr>
<a name="deleteAllFiles"></a>
<h2>deleteAllFiles</h2>
deleteAllFiles( <a href='https://docs.oracle.com/javase/8/docs/api/java/io/File.html'>java.io.File</a> dir, <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/String.html'>String</a> regex ) &rarr; void

<p>delete all files under the directory, with names matching the regex.</p>

<h3>Parameters</h3>
dir - the directory
<br>
regex - the regular expression, like ".*\.png"

<h3>Returns:</h3>
void (returns nothing)

<h3>See Also:</h3>
<a href='null'>Glob#getRegex(java.lang.String)</a> <br>
<br><br>
<a href="https://github.com/autoplot/dev/search?q=deleteAllFiles&unscoped_q=deleteAllFiles">[search for examples]</a>
 <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/filesystem/FileSystemUtil.md">[view on GitHub]</a>
 <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/filesystem/FileSystemUtil.html#deleteAllFiles">[view on old javadoc]</a>
 <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/filesystem/FileSystemUtil.java">[view source]</a>
<br>
<br>
<hr>
<a name="downloadResourceAsFile"></a>
<h2>downloadResourceAsFile</h2>
downloadResourceAsFile( <a href='https://docs.oracle.com/javase/8/docs/api/java/net/URI.html'>java.net.URI</a> uri, <a href='http://www-pw.physics.uiowa.edu/~jbf/autoplot/doc/org/das2/util/monitor/ProgressMonitor.html'>ProgressMonitor</a> monitor ) &rarr; <a href='https://docs.oracle.com/javase/8/docs/api/java/io/File.html'>java.io.File</a>

<p>download the URI as a file.  Presently these must be files which can be in a FileSystem.</p>

<h3>Parameters</h3>
uri - an URI
<br>
monitor - a ProgressMonitor

<h3>Returns:</h3>
a java.io.File

<br><br>
<a href="https://github.com/autoplot/dev/search?q=downloadResourceAsFile&unscoped_q=downloadResourceAsFile">[search for examples]</a>
 <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/filesystem/FileSystemUtil.md">[view on GitHub]</a>
 <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/filesystem/FileSystemUtil.html#downloadResourceAsFile">[view on old javadoc]</a>
 <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/filesystem/FileSystemUtil.java">[view source]</a>
<br>
<br>
<hr>
<a name="dumpToFile"></a>
<h2>dumpToFile</h2>
dumpToFile( <a href='https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html'>java.io.InputStream</a> in, <a href='https://docs.oracle.com/javase/8/docs/api/java/io/File.html'>java.io.File</a> f ) &rarr; void

<p>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.</p>

<h3>Parameters</h3>
in - an InputStream
<br>
f - a File

<h3>Returns:</h3>
void (returns nothing)

<br><br>
<a href="https://github.com/autoplot/dev/search?q=dumpToFile&unscoped_q=dumpToFile">[search for examples]</a>
 <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/filesystem/FileSystemUtil.md">[view on GitHub]</a>
 <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/filesystem/FileSystemUtil.html#dumpToFile">[view on old javadoc]</a>
 <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/filesystem/FileSystemUtil.java">[view source]</a>
<br>
<br>
<hr>
<a name="fromUri"></a>
<h2>fromUri</h2>
fromUri( <a href='https://docs.oracle.com/javase/8/docs/api/java/net/URI.html'>java.net.URI</a> uri ) &rarr; <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/String.html'>String</a>

<p>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.</p>

<h3>Parameters</h3>
uri - URI like URI("file:/home/jbf/ct/autoplot/bugs/1830227625/%5BajbTest%5D/")

<h3>Returns:</h3>
string representation of a path like file:/home/jbf/ct/autoplot/bugs/1830227625/[ajbTest]/
<br><br>
<a href="https://github.com/autoplot/dev/search?q=fromUri&unscoped_q=fromUri">[search for examples]</a>
 <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/filesystem/FileSystemUtil.md">[view on GitHub]</a>
 <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/filesystem/FileSystemUtil.html#fromUri">[view on old javadoc]</a>
 <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/filesystem/FileSystemUtil.java">[view source]</a>
<br>
<br>
<hr>
<a name="getFileNameExtensionFilter"></a>
<h2>getFileNameExtensionFilter</h2>
getFileNameExtensionFilter( <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/String.html'>String</a> description, <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/String.html'>String</a> ext ) &rarr; <a href='http://www-pw.physics.uiowa.edu/~jbf/autoplot/doc/javax/swing/filechooser/FileFilter.html'>javax.swing.filechooser.FileFilter</a>

<p>get simple filter based on extension for use with JFileChooser.</p>

<h3>Parameters</h3>
description - descriptions, like "png image file"
<br>
ext - file extension, like ".png"

<h3>Returns:</h3>
the FileFilter
<br><br>
<a href="https://github.com/autoplot/dev/search?q=getFileNameExtensionFilter&unscoped_q=getFileNameExtensionFilter">[search for examples]</a>
 <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/filesystem/FileSystemUtil.md">[view on GitHub]</a>
 <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/filesystem/FileSystemUtil.html#getFileNameExtensionFilter">[view on old javadoc]</a>
 <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/filesystem/FileSystemUtil.java">[view source]</a>
<br>
<br>
<hr>
<a name="getParentUri"></a>
<h2>getParentUri</h2>
getParentUri( <a href='https://docs.oracle.com/javase/8/docs/api/java/net/URI.html'>java.net.URI</a> ruri ) &rarr; <a href='https://docs.oracle.com/javase/8/docs/api/java/net/URI.html'>java.net.URI</a>

<p>return the parent of the URI, or null if this is not possible.</p>

<h3>Parameters</h3>
ruri - an URI

<h3>Returns:</h3>
a java.net.URI

<br><br>
<a href="https://github.com/autoplot/dev/search?q=getParentUri&unscoped_q=getParentUri">[search for examples]</a>
 <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/filesystem/FileSystemUtil.md">[view on GitHub]</a>
 <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/filesystem/FileSystemUtil.html#getParentUri">[view on old javadoc]</a>
 <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/filesystem/FileSystemUtil.java">[view source]</a>
<br>
<br>
<hr>
<a name="gunzip"></a>
<h2>gunzip</h2>
gunzip( <a href='https://docs.oracle.com/javase/8/docs/api/java/io/File.html'>java.io.File</a> fz, <a href='https://docs.oracle.com/javase/8/docs/api/java/io/File.html'>java.io.File</a> file ) &rarr; void

<p>un-gzip the file.  This is similar to the unix gunzip command.</p>

<h3>Parameters</h3>
fz - zipped input file
<br>
file - unzipped destination file

<h3>Returns:</h3>
void (returns nothing)

<br><br>
<a href="https://github.com/autoplot/dev/search?q=gunzip&unscoped_q=gunzip">[search for examples]</a>
 <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/filesystem/FileSystemUtil.md">[view on GitHub]</a>
 <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/filesystem/FileSystemUtil.html#gunzip">[view on old javadoc]</a>
 <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/filesystem/FileSystemUtil.java">[view source]</a>
<br>
<br>
<hr>
<a name="isCacheable"></a>
<h2>isCacheable</h2>
isCacheable( <a href='https://docs.oracle.com/javase/8/docs/api/java/net/URI.html'>java.net.URI</a> ruri ) &rarr; <a href='https://docs.oracle.com/javase/8/docs/api/java/net/URI.html'>java.net.URI</a>

<p>return null if the URI is not cacheable, or the URI of the parent if it is.

 For example,
 <pre>
 
 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();
 
 }
 </pre></p>

<h3>Parameters</h3>
ruri - an URI

<h3>Returns:</h3>
the URI of the parent, or null.
<br><br>
<a href="https://github.com/autoplot/dev/search?q=isCacheable&unscoped_q=isCacheable">[search for examples]</a>
 <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/filesystem/FileSystemUtil.md">[view on GitHub]</a>
 <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/filesystem/FileSystemUtil.html#isCacheable">[view on old javadoc]</a>
 <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/filesystem/FileSystemUtil.java">[view source]</a>
<br>
<br>
<hr>
<a name="maybeMkdirs"></a>
<h2>maybeMkdirs</h2>
maybeMkdirs( <a href='https://docs.oracle.com/javase/8/docs/api/java/io/File.html'>java.io.File</a> file ) &rarr; void

<p>create the file folder if it does not exist.  Throw an IOException if it failed.</p>

<h3>Parameters</h3>
file - a File

<h3>Returns:</h3>
void (returns nothing)

<br><br>
<a href="https://github.com/autoplot/dev/search?q=maybeMkdirs&unscoped_q=maybeMkdirs">[search for examples]</a>
 <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/filesystem/FileSystemUtil.md">[view on GitHub]</a>
 <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/filesystem/FileSystemUtil.html#maybeMkdirs">[view on old javadoc]</a>
 <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/filesystem/FileSystemUtil.java">[view source]</a>
<br>
<br>
<hr>
<a name="toUri"></a>
<h2>toUri</h2>
toUri( <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/String.html'>String</a> s ) &rarr; <a href='https://docs.oracle.com/javase/8/docs/api/java/net/URI.html'>java.net.URI</a>

<p>encode the string as a URI.  The following characters are encoded:
 " " % &lt; &gt; [ ]</p>

<h3>Parameters</h3>
s - string representation of a path like file:/home/jbf/ct/autoplot/bugs/1830227625/[ajbTest]/

<h3>Returns:</h3>
URI like URI("file:/home/jbf/ct/autoplot/bugs/1830227625/%5BajbTest%5D/")
<br><br>
<a href="https://github.com/autoplot/dev/search?q=toUri&unscoped_q=toUri">[search for examples]</a>
 <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/filesystem/FileSystemUtil.md">[view on GitHub]</a>
 <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/filesystem/FileSystemUtil.html#toUri">[view on old javadoc]</a>
 <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/filesystem/FileSystemUtil.java">[view source]</a>
<br>
<br>
<hr>
<a name="unzip"></a>
<h2><del>unzip</del></h2>
Deprecated: use gunzip instead.
<hr>
<a name="unzipFile"></a>
<h2>unzipFile</h2>
unzipFile( <a href='https://docs.oracle.com/javase/8/docs/api/java/io/File.html'>java.io.File</a> zipFilePath, <a href='https://docs.oracle.com/javase/8/docs/api/java/io/File.html'>java.io.File</a> destDir ) &rarr; void

<p>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</p>

<h3>Parameters</h3>
zipFilePath - a File
<br>
destDir - a File

<h3>Returns:</h3>
void (returns nothing)

<br><br>
<a href="https://github.com/autoplot/dev/search?q=unzipFile&unscoped_q=unzipFile">[search for examples]</a>
 <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/filesystem/FileSystemUtil.md">[view on GitHub]</a>
 <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/filesystem/FileSystemUtil.html#unzipFile">[view on old javadoc]</a>
 <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/filesystem/FileSystemUtil.java">[view source]</a>
<br>
<br>
<hr>
<a name="uriDecode"></a>
<h2>uriDecode</h2>
uriDecode( <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/String.html'>String</a> s ) &rarr; <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/String.html'>String</a>

<p>convert "%20" to " ", etc, by using URLDecoder and catching the UnsupportedEncodingException that will never occur.</p>

<h3>Parameters</h3>
s - a String

<h3>Returns:</h3>
a String

<br><br>
<a href="https://github.com/autoplot/dev/search?q=uriDecode&unscoped_q=uriDecode">[search for examples]</a>
 <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/filesystem/FileSystemUtil.md">[view on GitHub]</a>
 <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/filesystem/FileSystemUtil.html#uriDecode">[view on old javadoc]</a>
 <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/filesystem/FileSystemUtil.java">[view source]</a>
<br>
<br>
<hr>
<a name="uriEncode"></a>
<h2>uriEncode</h2>
uriEncode( <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/String.html'>String</a> surl ) &rarr; <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/String.html'>String</a>

<p>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!</p>

<h3>Parameters</h3>
surl - a String

<h3>Returns:</h3>
a String

<br><br>
<a href="https://github.com/autoplot/dev/search?q=uriEncode&unscoped_q=uriEncode">[search for examples]</a>
 <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/filesystem/FileSystemUtil.md">[view on GitHub]</a>
 <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/filesystem/FileSystemUtil.html#uriEncode">[view on old javadoc]</a>
 <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/filesystem/FileSystemUtil.java">[view source]</a>
<br>
<br>
<hr>
<a name="zip"></a>
<h2>zip</h2>
zip( <a href='https://docs.oracle.com/javase/8/docs/api/java/io/File.html'>java.io.File</a> fz, <a href='https://docs.oracle.com/javase/8/docs/api/java/io/File.html'>java.io.File</a> dir ) &rarr; void

<p>create a zip file of everything with and under the directory.</p>

<h3>Parameters</h3>
fz - the output
<br>
dir - the root directory.

<h3>Returns:</h3>
void (returns nothing)

<br><br>
<a href="https://github.com/autoplot/dev/search?q=zip&unscoped_q=zip">[search for examples]</a>
 <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/filesystem/FileSystemUtil.md">[view on GitHub]</a>
 <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/filesystem/FileSystemUtil.html#zip">[view on old javadoc]</a>
 <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/filesystem/FileSystemUtil.java">[view source]</a>
<br>
<br>