org.geotools
Class TestData

java.lang.Object
  extended byorg.geotools.resources.TestData
      extended byorg.geotools.TestData
All Implemented Interfaces:
java.lang.Runnable

public final class TestData
extends TestData

Provides access to the common directories provided in the module. This directory is shared by test suites in other modules.

This file has to live in the root package in order to get access to the directory. If you don't need this directory, then use the TestData class provided in the directory.

Since:
2.2
Version:
$Id: TestData.java 17705 2006-01-23 00:45:01Z desruisseaux $
Author:
Martin Desruisseaux

Method Summary
static java.io.File copy(java.lang.Object caller, java.lang.String name)
          Copies the named resources from the module to the directory in an other module.
static java.io.File file(java.lang.String name)
          Access to getResource(name) as a non-null File.
static java.nio.channels.ReadableByteChannel openChannel(java.lang.String name)
          Provides a channel for named test data.
static java.io.LineNumberReader openReader(java.lang.String name)
          Provides a BufferedReader for named test data.
static java.io.InputStream openStream(java.lang.String name)
          Provides a non-null InputStream for named test data.
static java.net.URL url(java.lang.String name)
          Access to getResource(name) as a non-null URL.
 
Methods inherited from class org.geotools.resources.TestData
deleteOnExit, file, getReader, getResource, openChannel, openReader, openStream, run, temp, unzipFile, url
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

url

public static java.net.URL url(java.lang.String name)
                        throws java.io.FileNotFoundException
Access to getResource(name) as a non-null URL. At the difference of , this method throws an exception if the resource is not found. This provides a more explicit explanation about the failure reason than the infamous NullPointerException.

Parameters:
name - Path to file in .
Returns:
The URL to the resource.
Throws:
java.io.FileNotFoundException - if the resource is not found.

file

public static java.io.File file(java.lang.String name)
                         throws java.io.IOException
Access to getResource(name) as a non-null File. You can access the directory with:
 TestData.file(null);
 

Parameters:
name - Path to file in .
Returns:
The file to the resource.
Throws:
java.io.FileNotFoundException - if the file is not found.
java.io.IOException - if the resource can't be fetched for an other reason.

openStream

public static java.io.InputStream openStream(java.lang.String name)
                                      throws java.io.IOException
Provides a non-null InputStream for named test data. It is the caller responsability to close this stream after usage.

Parameters:
name - Path to file in .
Returns:
The input stream.
Throws:
java.io.FileNotFoundException - if the resource is not found.
java.io.IOException - if an error occurs during an input operation.

openReader

public static java.io.LineNumberReader openReader(java.lang.String name)
                                           throws java.io.IOException
Provides a BufferedReader for named test data. The buffered reader is provided as an LineNumberReader instance, which is useful for displaying line numbers where error occur. It is the caller responsability to close this reader after usage.

Parameters:
name - Path to file in .
Returns:
The buffered reader.
Throws:
java.io.FileNotFoundException - if the resource is not found.
java.io.IOException - if an error occurs during an input operation.

openChannel

public static java.nio.channels.ReadableByteChannel openChannel(java.lang.String name)
                                                         throws java.io.IOException
Provides a channel for named test data. It is the caller responsability to close this chanel after usage.

Parameters:
name - Path to file in .
Returns:
The chanel.
Throws:
java.io.FileNotFoundException - if the resource is not found.
java.io.IOException - if an error occurs during an input operation.

copy

public static java.io.File copy(java.lang.Object caller,
                                java.lang.String name)
                         throws java.io.IOException
Copies the named resources from the module to the directory in an other module. For example if is invoked inside a test suite in the package, then this method copies (from module) to (in the module).

This method is useful when a test case needs to access a resource through a File, for example because it want to open it using java.io.RandomAccess. Because the resources provided in the module are available to other modules as a JAR file, other modules can only access them through an URL unless they copy them in their own directory.

If the named file already exists in the caller directory, then this method does nothing. It make it safe to invoke this method many time in a test suite, since this method should not copy the file more than once for a given JVM execution. The file will be deleted on exit.

Parameters:
caller - Calling class or object used to locate the destination .
name - Path to file in .
Returns:
The file to the org/geotools/caller-package/test-data resource copy, returned for convenience.
Throws:
java.io.FileNotFoundException - if the file is not found.
java.io.IOException - if the resource can't be fetched for an other reason.


Copyright © GeoTools. All Rights Reserved.