private Writer outputFileWriter()

in src/main/java/com/epam/digital/data/platform/generator/ServiceGenerationUtilityApplication.java [98:127]


  private Writer outputFileWriter(String temp, Object model) throws IOException {
    Writer sourceFileWriter;

    String sourceDir = File.separatorChar + "java";
    String resultFile = temp.replace(TEMPLATE_EXTENSION, "");
    if (temp.contains(sourceDir)) {
      String basePackageName =
          context.getSettings().getGeneral().getBasePackageName().replace('.', File.separatorChar);
      String packageDir = File.separatorChar + basePackageName;
      String[] paths = resultFile.split(safeRegexp(sourceDir));
      String completePath = paths[0] + sourceDir + packageDir + paths[1];

      String path = FilenameUtils.getPath(completePath);
      String baseName = FilenameUtils.getBaseName(completePath);

      if (Character.isLowerCase(baseName.codePointAt(0)) && model != null) {
        baseName = ((ClassScope) model).getClassName();
      }

      File dir = new File(path); //NOSONAR
      dir.mkdirs(); //NOSONAR
      sourceFileWriter = new FileWriter(new File(dir, baseName + JAVA_EXTENSION), UTF_8); //NOSONAR
    } else {
      String path = FilenameUtils.getPath(resultFile);
      File dir = new File(path); //NOSONAR
      dir.mkdirs(); //NOSONAR
      sourceFileWriter = new FileWriter(resultFile, UTF_8);
    }
    return sourceFileWriter;
  }