de.smartics.util.test.io
Class FileTestUtils

Package class diagram package FileTestUtils
java.lang.Object
  extended by de.smartics.util.test.io.FileTestUtils

public final class FileTestUtils
     
     
extends Object

Utilities to make unit tests with files easier.

Author:
Robert Reiner

Method Summary
static File getFileFromRelativeResource(Class<?> type, String relativeResourceName)
          Returns the specified file from a resource relative to the given type.
static File getFileFromResource(Class<?> type, String resourceName)
          Returns the specified file from the class loader associated with the given type.
static File getFileFromResource(ClassLoader classLoader, String resourceName)
          Returns the specified file from the specified class loader.
static File getFileFromResource(String resourceName)
          Returns the specified file from the class path.
static Properties getPropertiesFromRelativePropertiesFileForClass(Class<?> clazz)
          Returns a properties object backed by the specified file from a resource relative to the given type with the simple name of the resource with an ending .properties .
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getFileFromResource

public static File getFileFromResource(String resourceName)
Returns the specified file from the class path.

Parameters:
resourceName - name of the resource (file or directory) in the class path.
Returns:
the file representation of the resource or null if the resource does not exist, is not accessible via the file:/ protocol or due to missing privileges.

getFileFromResource

public static File getFileFromResource(ClassLoader classLoader,
                                       String resourceName)
Returns the specified file from the specified class loader.

Parameters:
classLoader - the class loader to load the resource from.
resourceName - name of the resource (file or directory) in the class path.
Returns:
the file representation of the resource or null if the resource does not exist, is not accessible via the file:/ protocol or due to missing privileges.

getFileFromResource

public static File getFileFromResource(Class<?> type,
                                       String resourceName)
Returns the specified file from the class loader associated with the given type.

Parameters:
type - the type to refer to the class loader to load the resource from. The resource is relative to this type.
resourceName - name of the resource (file or directory) in the class path.
Returns:
the file representation of the resource or null if the resource does not exist, is not accessible via the file:/ protocol or due to missing privileges.

getFileFromRelativeResource

public static File getFileFromRelativeResource(Class<?> type,
                                               String relativeResourceName)
Returns the specified file from a resource relative to the given type.

Parameters:
type - the type to refer to the class loader to load the resource from. The resource is relative to this type.
relativeResourceName - name of the resource (file or directory) in the class path, relative to the passed in type.
Returns:
the file representation of the resource or null if the resource does not exist, is not accessible via the file:/ protocol or due to missing privileges.

getPropertiesFromRelativePropertiesFileForClass

public static Properties getPropertiesFromRelativePropertiesFileForClass(Class<?> clazz)
Returns a properties object backed by the specified file from a resource relative to the given type with the simple name of the resource with an ending .properties .

Parameters:
clazz - the type to refer to the class loader to load the resource from. The resource is relative to this type and has its simple name.
Returns:
the properties object containing the properties or empty if the resource does not exist or is empty.


Copyright © 2008-2013 Kronseder & Reiner GmbH - smartics. All Rights Reserved.