Class FileUtils


  • public final class FileUtils
    extends Object
    Utility class for report generation helper methods.
    • Method Detail

      • loadFileFromWorkspace

        public static FileInfo loadFileFromWorkspace​(@NonNull
                                                     @NonNull FilePath root,
                                                     @NonNull
                                                     @NonNull String fileName,
                                                     String filePath)
                                              throws IOException,
                                                     InterruptedException
        Finds file in the workspace and reads its contents.
        Parameters:
        root - base directory of the jenkins workspace.
        fileName - file name.
        filePath - file path relative to workspace root directory.
        Returns:
        file info comprising file contents and file path.
        Throws:
        IOException - exception occurred during reading file.
        InterruptedException - thrown when execution thread is interrupted.
      • readResource

        public static String readResource​(String filePath)
                                   throws IOException
        Reads a resource present on the resource directory.
        Parameters:
        filePath - location of the file w.r.t. resource directory in the project.
        Returns:
        file contents as string.
        Throws:
        IOException - if the file is not found on the path.
      • readFromInputStream

        public static String readFromInputStream​(InputStream inputStream)
                                          throws IOException
        Reads stream contents and returns them as string.
        Throws:
        IOException - if failure occurs while reading stream contents.