com.groiss.util
Class FileUtil

java.lang.Object
  extended by com.groiss.util.FileUtil

public class FileUtil
extends java.lang.Object

Some convenient file methods.


Constructor Summary
FileUtil()
           
 
Method Summary
static void copyTo(java.io.File src, java.io.File dest)
          Copy a file.
static java.io.File copyToDir(java.io.File src, java.io.File dir)
          Copy file to directory
static void deleteDir(java.io.File dir)
          Deletes the passed direcory and all its subdirectories (and so on).
static void deleteDir(java.lang.String dirPath)
          Deletes the direcory with the given path.
static byte[] getBytesFromStream(java.io.InputStream is)
           
static java.lang.String getContent(java.io.File file)
          Get the content of a file as string.
static java.io.File getFileFromPath(java.lang.String path)
          Get a file object from a pathname.
static java.lang.String getMimeType(java.lang.String ext)
          Return the mime-type from the extension.
static java.lang.String getNoComment(java.io.InputStream in)
           
static java.lang.String getNoComment(java.io.Reader in)
          Get the contents of an input stream without the comments.
static java.lang.String getNoCommentContent(java.lang.String filename)
           
static java.util.List listFiles(java.lang.String namePattern, java.io.File dir)
          List file with name specified with wildcard in directory and all its subdirectories.
static java.lang.String loadResource(java.lang.String resource)
          Load a resource as string from the classpath.
static byte[] loadResourceBytes(java.lang.String resource)
           
static byte[] loadResourceBytes(java.net.URL url)
          Load a resource as byte array from the classpath.
 
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

getMimeType

public static java.lang.String getMimeType(java.lang.String ext)
Return the mime-type from the extension. The available mime-types are defined in the file mime.types in the conf directory.

Parameters:
ext - the extension, for example "doc" or "html"
Returns:
the mime-type, for example "text/html"

loadResource

public static java.lang.String loadResource(java.lang.String resource)
                                     throws ApplicationException
Load a resource as string from the classpath. The class loader defined in Settings is used.

Parameters:
resource - a path to a resource
Returns:
the content of the resource
Throws:
ApplicationException

loadResourceBytes

public static byte[] loadResourceBytes(java.net.URL url)
                                throws ApplicationException
Load a resource as byte array from the classpath. The class loader defined in Settings is used.

Parameters:
url - the url of a resource
Returns:
the content of the resource
Throws:
ApplicationException

loadResourceBytes

public static byte[] loadResourceBytes(java.lang.String resource)
                                throws ApplicationException
Throws:
ApplicationException

getBytesFromStream

public static byte[] getBytesFromStream(java.io.InputStream is)
                                 throws ApplicationException
Throws:
ApplicationException

copyTo

public static void copyTo(java.io.File src,
                          java.io.File dest)
                   throws java.io.FileNotFoundException,
                          java.io.IOException
Copy a file.

Parameters:
src - the source file
dest - the destination file
Throws:
java.io.FileNotFoundException
java.io.IOException

copyToDir

public static java.io.File copyToDir(java.io.File src,
                                     java.io.File dir)
                              throws java.io.FileNotFoundException,
                                     java.io.IOException
Copy file to directory

Parameters:
src -
dir -
Throws:
java.io.FileNotFoundException
java.io.IOException

getContent

public static java.lang.String getContent(java.io.File file)
                                   throws java.io.IOException
Get the content of a file as string.

Parameters:
file - the file
Returns:
the content
Throws:
java.io.IOException

getNoComment

public static java.lang.String getNoComment(java.io.InputStream in)
                                     throws java.lang.Exception
Throws:
java.lang.Exception

getNoComment

public static java.lang.String getNoComment(java.io.Reader in)
                                     throws java.lang.Exception
Get the contents of an input stream without the comments. The method filters out the comments starting with "/*" and ending with "*/"

Parameters:
in - the input stream
Returns:
the content
Throws:
java.lang.Exception

getNoCommentContent

public static java.lang.String getNoCommentContent(java.lang.String filename)
                                            throws java.lang.Exception
Throws:
java.lang.Exception

deleteDir

public static void deleteDir(java.lang.String dirPath)
Deletes the direcory with the given path. All subdirectories (and so on) will be also deleted.

Parameters:
dirPath - the directory path

deleteDir

public static void deleteDir(java.io.File dir)
Deletes the passed direcory and all its subdirectories (and so on). If the passed parameter is a file and not a directory it will not be deleted

Parameters:
dir - the directory

getFileFromPath

public static java.io.File getFileFromPath(java.lang.String path)
Get a file object from a pathname. If the path is absolute, the method returns the corresponding file. If the path is relative, the moethod returns the path using the base directory from settings as base for the relative path.

Parameters:
path - the path string
Returns:
the file object

listFiles

public static java.util.List listFiles(java.lang.String namePattern,
                                       java.io.File dir)
List file with name specified with wildcard in directory and all its subdirectories.

Parameters:
namePattern -
dir -
Returns:
list of found File objects


Copyright © 2001-2006 Groiss Informatics GmbH. All Rights Reserved.