de.smartics.util.test.io
Class IoTestUtils

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

public final class IoTestUtils
     
     
extends Object

Utilities to make unit tests with streams to resources from the class path easier.

Author:
Robert Reiner

Method Summary
static InputStream openStreamFromResource(Class<?> type, String relativeResourceName)
          Returns the specified file from a resource relative to the given type.
static InputStream openStreamFromResource(ClassLoader classLoader, String resourceName)
          Returns a stream to a resource on the class path.
static InputStream openStreamFromResource(String resourceName)
          Returns a stream to a resource on the class path loaded by the class loader of this class.
static InputStream openStreamFromResourceByTypeClassLoader(Class<?> type, String resourceName)
          Returns a stream to a resource on the class path loaded by the class loader that has loaded the given type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

openStreamFromResource

public static InputStream openStreamFromResource(String resourceName)
                                          throws IllegalArgumentException
Returns a stream to a resource on the class path loaded by the class loader of this class.

Parameters:
resourceName - name of the resource on the class path.
Returns:
the opened buffered stream. The client is responsible to close it.
Throws:
IllegalArgumentException - if resourceName cannot be found.

openStreamFromResourceByTypeClassLoader

public static InputStream openStreamFromResourceByTypeClassLoader(Class<?> type,
                                                                  String resourceName)
                                                           throws IllegalArgumentException
Returns a stream to a resource on the class path loaded by the class loader that has loaded 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 on the class path.
Returns:
the opened buffered stream. The client is responsible to close it.
Throws:
IllegalArgumentException - if resourceName cannot be found.

openStreamFromResource

public static InputStream openStreamFromResource(ClassLoader classLoader,
                                                 String resourceName)
                                          throws IllegalArgumentException
Returns a stream to a resource on the class path.

Parameters:
classLoader - the class loader to load the resource from.
resourceName - name of the resource on the class path.
Returns:
the opened buffered stream. The client is responsible to close it.
Throws:
IllegalArgumentException - if resourceName cannot be found.

openStreamFromResource

public static InputStream openStreamFromResource(Class<?> type,
                                                 String relativeResourceName)
                                          throws IllegalArgumentException
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 on the class path, relative to the passed in type.
Returns:
the opened buffered stream. The client is responsible to close it.
Throws:
IllegalArgumentException - if relativeResourceName cannot be found.


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