de.lmu.ifi.dbs.elki.utilities
Class FileUtil

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.utilities.FileUtil

public final class FileUtil
extends Object

Various static helper methods to deal with files and file names.


Constructor Summary
FileUtil()
           
 
Method Summary
static String getFilenameExtension(File file)
          Returns the lower case extension of the selected file.
static String getFilenameExtension(String name)
          Returns the lower case extension of the selected file.
static File locateFile(String name, String basedir)
          Try to locate an file in the filesystem, given a partial name and a prefix.
static InputStream openSystemFile(String filename)
          Try to open a file, first trying the file system, then falling back to the classpath.
static InputStream tryGzipInput(InputStream in)
          Try to open a stream as gzip, if it starts with the gzip magic.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtil

public FileUtil()
Method Detail

getFilenameExtension

public static String getFilenameExtension(File file)
Returns the lower case extension of the selected file. If no file is selected, null is returned.

Parameters:
file - File object
Returns:
Returns the extension of the selected file in lower case or null

getFilenameExtension

public static String getFilenameExtension(String name)
Returns the lower case extension of the selected file. If no file is selected, null is returned.

Parameters:
name - File name
Returns:
Returns the extension of the selected file in lower case or null

openSystemFile

public static InputStream openSystemFile(String filename)
                                  throws FileNotFoundException
Try to open a file, first trying the file system, then falling back to the classpath.

Parameters:
filename - File name in system notation
Returns:
Input stream
Throws:
FileNotFoundException - When no file was found.

tryGzipInput

public static InputStream tryGzipInput(InputStream in)
                                throws IOException
Try to open a stream as gzip, if it starts with the gzip magic. TODO: move to utils package.

Parameters:
in - original input stream
Returns:
old input stream or a GZIPInputStream if appropriate.
Throws:
IOException - on IO error

locateFile

public static File locateFile(String name,
                              String basedir)
Try to locate an file in the filesystem, given a partial name and a prefix.

Parameters:
name - file name
basedir - extra base directory to try
Returns:
file, if the file could be found. null otherwise

Release 0.4.0 (2011-09-20_1324)