package net.liquidpineapple.pang;

import java.io.File;
import java.io.FileNotFoundException;

import lombok.Getter;

/**
 * @author Jurriaan Den Toonder Created on 24-10-16
 */
public class FileHandler {

  /**
   * Singleton constructor
   */
  private FileHandler() {}

  @Getter
  @SuppressWarnings("PMD.UnusedPrivateField") // It is used in the generated getter method
  private static final FileHandler instance = new FileHandler();

  private PropertiesHandler propertiesHandler = PropertiesHandler.getInstance();

  /**
   * Return the application folder for storage of levels etc.
   * @return {@link File} The folder location.
   * @throws FileNotFoundException thrown when folder could not be found or created.
   */
  public File getApplicationFolder() throws FileNotFoundException {
    String homeFolderName = appendSlash(System.getProperty("user.home"));
    String appFolderName = appendSlash(propertiesHandler.getProperty("application-folder"));

    File file = new File(homeFolderName + appFolderName);
    file = new File(file.getAbsoluteFile().toString());
    file.mkdirs();
    if (file.exists() && file.isDirectory()) {
      return file;
    } else {
      throw new FileNotFoundException("Could not get application folder");
    }
  }

  public File getLogsFolder() throws FileNotFoundException {
    String appFolder = appendSlash(getApplicationFolder().toString());
    String logsFolder = appendSlash(propertiesHandler.getProperty("log-folder-name"));
    File folder = new File(appFolder + logsFolder);
    folder.mkdirs();
    return folder;
  }

  private String appendSlash(String path) {
    path = path.endsWith("/") ? path : path + "/";
    return path;
  }
}

@@ -262,17 +262,113 @@
 ndler() 
-%7B
+throws FileNotFoundException %7B%0A    appFolder = appendSlash(getApplicationFolder().toString());%0A  
 %7D%0A%0A  @Ge
@@ -510,29 +510,213 @@
 ance
- = new FileHandler();
+;%0A  static %7B%0A    try %7B%0A      instance = new FileHandler();%0A    %7D catch(Exception ex) %7B%0A      // Note that catching all Exceptions here is allowed!%0A      throw new ExceptionInInitializerError(ex);%0A    %7D%0A  %7D
 %0A%0A  
@@ -793,16 +793,50 @@
 tance();
+%0A  private final String appFolder;
 %0A%0A  /**%0A
@@ -1634,79 +1634,8 @@
 n %7B%0A
-    String appFolder = appendSlash(getApplicationFolder().toString());%0A
     

Improve error handling in FileHandler