verinec.util
Class FileUtil

java.lang.Object
  extended by verinec.util.FileUtil

public class FileUtil
extends Object

Utility functions for file system manipulations.

Version:
$Revision: 1045 $
Author:
david.buchmann at unifr.ch

Constructor Summary
private FileUtil()
          Do not instantiate FileUtil, it contains only static methods.
 
Method Summary
static File createTempDir(String prefix)
          Create a temporary directory in the tmp directory.
static void deltree(File dir)
          Delete directories and files recursively.
static File[] findFiles(File dir, String beginwith)
          Return all files in a directory beginning with a certain String.
static String readFileAsString(InputStream in)
          Read input stream and put content into String.
static void saveXMLElement(Element element, String fileName)
          Saves an Element into a File.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtil

private FileUtil()
Do not instantiate FileUtil, it contains only static methods.

Method Detail

createTempDir

public static File createTempDir(String prefix)
                          throws IOException
Create a temporary directory in the tmp directory. This directory will NOT be automatically removed, you have to do this manually.

Parameters:
prefix - A prefix for the directory name.
Returns:
An existing temporary directory.
Throws:
IOException - if the temporary dir can not be created.

deltree

public static void deltree(File dir)
                    throws IOException
Delete directories and files recursively. If dir is a file, deletes the file (but for this you can also use File.delete() ).

Parameters:
dir - A file denoting an existing directory or file to be deleted.
Throws:
IOException - if the directory or some of its content can not be deleted.

saveXMLElement

public static void saveXMLElement(Element element,
                                  String fileName)
                           throws VerinecException
Saves an Element into a File.

Parameters:
element - the Element to be saved.
fileName - filename into which the Element is written.
Throws:
VerinecException - if the Element is null or an IO Error happens when writing the file.

readFileAsString

public static String readFileAsString(InputStream in)
                               throws IOException
Read input stream and put content into String. (Take care not to open too big files with this, or you will reach memory limits)

Parameters:
in - The input stream with the data
Returns:
String form of the input
Throws:
IOException - If opening or reading the file fails

findFiles

public static File[] findFiles(File dir,
                               String beginwith)
Return all files in a directory beginning with a certain String.

Parameters:
dir - the directory to parse
beginwith - the type of the files to return
Returns:
a list of files in the directory dir beginning with beginwith

Copyright © 2005 Verinec, DIUF