Jasperreports のコンパイル実行を、Stream 処理でまとめる

Jasperreports のコンパイル実行を、Stream 処理でまとめてみました。

/**
 * @param directoryPath jrxmlを置いたディレクトリPATH
 * @return Map<String, Throwable> key=コンパイル処理実行のjrxmlファイルPATH、value=コンパイルエラー発生のThroawble
 */
public static Map<String, Throwable> jasperCompileWithDirectory(String directoryPath){
   return  Arrays.stream(new File(directoryPath).listFiles()).filter(e->e.getName().endsWith(".jrxml"))
   .collect(HashMap::new,(r, t)->{
      Throwable error = null;
      try(InputStream in=new FileInputStream(t.getAbsolutePath());
          OutputStream out = new FileOutputStream(t.getAbsolutePath().replaceAll("\\.jrxml", ".jasper"))
      ){
         JasperCompileManager.compileReportToStream(in, out);
      }catch(Exception e){
         error = e;
      }finally{
         r.put(t.getAbsolutePath(), error);
      }
   }, (r, u)->r.putAll(u));
}

使い方は、、、

    Map<String, Throwable> map = jasperCompileWithDirectory(Thread.currentThread().getContextClassLoader()
                                                            .getResource("").getPath() + "../../template");

のようにして、map の value が null ならコンパイル成功