Class InMemoryTestResourceProvider

  • All Implemented Interfaces:
    TestResourceProvider

    public class InMemoryTestResourceProvider
    extends java.lang.Object
    implements TestResourceProvider
    This test resource provider holds the entire resources in memory and returns them from memory on demand. It is intended to be used to create fully self-sufficient clones of other resource providers (that typically just enumerate resources from external sources and load them on demand) which can then be transferred over the remoting connection to forks.
    Author:
    Rene Schneider - initial API and implementation
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void closeResource​(TestResource aResourceName, java.io.InputStream aResourceStream)
      Closes a specified resources' stream (and all the stuff opened for this stream in the background).
      java.lang.ClassLoader getClassLoader()
      Returns the classloader to use for all dynamic class resolving needs.
      TestResource[] getResourceNames()
      Returns all known resource names.
      java.io.InputStream openResource​(TestResource aResourceName)
      Opens a specific named resource.
      void setClassLoader​(java.lang.ClassLoader aClassLoader)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • InMemoryTestResourceProvider

        public InMemoryTestResourceProvider()
        Default constructor for serialization.
      • InMemoryTestResourceProvider

        public InMemoryTestResourceProvider​(TestResourceProvider aSourceProvider,
                                            java.lang.String aNamePrefix)
                                     throws java.io.IOException
        Creates a new instance that acts as an in-memory copy of the given resource provider.
        Parameters:
        aSourceProvider - the provider that is to be copied
        aNamePrefix - a prefix to be added to all resource names on copy (if null, nothing is added)
        Throws:
        java.io.IOException
    • Method Detail

      • setClassLoader

        public void setClassLoader​(java.lang.ClassLoader aClassLoader)
      • getClassLoader

        public java.lang.ClassLoader getClassLoader()
        Description copied from interface: TestResourceProvider
        Returns the classloader to use for all dynamic class resolving needs.
        Specified by:
        getClassLoader in interface TestResourceProvider
        Returns:
        the classloader to use
      • openResource

        public java.io.InputStream openResource​(TestResource aResourceName)
                                         throws java.io.IOException
        Description copied from interface: TestResourceProvider
        Opens a specific named resource. This should return an InputStream at the start of the data of the respective resources, and it is only expected to work if the resource is one of those enumerated by a call to TestResourceProvider.getResourceNames().
        Specified by:
        openResource in interface TestResourceProvider
        Parameters:
        aResourceName - the resource to be opened
        Returns:
        an InputStream to read the resource
        Throws:
        java.io.IOException
      • closeResource

        public void closeResource​(TestResource aResourceName,
                                  java.io.InputStream aResourceStream)
                           throws java.io.IOException
        Description copied from interface: TestResourceProvider
        Closes a specified resources' stream (and all the stuff opened for this stream in the background).
        Specified by:
        closeResource in interface TestResourceProvider
        Parameters:
        aResourceName - the resource to be closed
        aResourceStream - the resource stream to close
        Throws:
        java.io.IOException