Class ArchiveTestResourceProvider

  • All Implemented Interfaces:
    TestResourceProvider

    public class ArchiveTestResourceProvider
    extends AbstractTestResourceProvider
    This TestResourceProvider can read archive files (zip/jar format) and provide the Integrity script files within these archives transparently to the Test Runner. It can even read archives within archives, up to an arbitrary depth.
    Author:
    Rene Schneider - initial API and implementation
    • Field Detail

      • ARCHIVE_ENDING_ZIP

        public static final java.lang.String ARCHIVE_ENDING_ZIP
        The ending of zip archives.
        See Also:
        Constant Field Values
      • ARCHIVE_ENDING_JAR

        public static final java.lang.String ARCHIVE_ENDING_JAR
        The ending of jar archives.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ArchiveTestResourceProvider

        public ArchiveTestResourceProvider()
    • Method Detail

      • addArchive

        public void addArchive​(java.io.File anArchiveFile,
                               boolean aRecursiveFlag)
                        throws java.io.IOException
        Adds an archive (all contained .integrity files) to the resource provider.
        Parameters:
        anArchiveFile - the archive file to add
        aRecursiveFlag - whether other archives inside this archive shall be added recursively
        Throws:
        java.io.IOException
      • addArchive

        protected void addArchive​(java.util.zip.ZipInputStream anArchiveInputStream,
                                  java.lang.String aPrefix,
                                  boolean aRecursiveFlag,
                                  java.util.Stack<java.lang.String> anArchiveFileNameStack)
                           throws java.io.IOException
        Recursive-enabled variant of addArchive(File, boolean).
        Parameters:
        anArchiveInputStream - the archive input stream to read from
        aPrefix - the prefix to prepend in front of the filename inside the archive
        aRecursiveFlag - a flag whether recursive invocation is desired
        Throws:
        java.io.IOException
      • 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().
        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).
        Parameters:
        aResourceName - the resource to be closed
        aResourceStream - the resource stream to close
        Throws:
        java.io.IOException
      • findFileInZipInputStream

        protected boolean findFileInZipInputStream​(java.util.zip.ZipInputStream aStream,
                                                   java.lang.String aFileName)
                                            throws java.io.IOException
        Searches the given ZipInputStream for an entry, then stops. This changes the active entry in the stream to the entry to find (if found) or no entry (if not found).
        Parameters:
        aStream - the stream to search in
        aFileName - the entry name
        Returns:
        true if the entry was found, false if not
        Throws:
        java.io.IOException