class LocalStorage {

  private static final String VENDOR_ID = "languagetool.org";
  private static final String APPLICATION_ID = "LanguageTool";
  
  private final File directory;

  LocalStorage() {
    String userHome = null;
    try {
      userHome = System.getProperty("user.home");
    } catch (SecurityException ex) {
    }
    if (userHome == null) {
      directory = null;
    } else if (SystemUtils.IS_OS_WINDOWS) {
      File appDataDir = null;
      try {
        String appData = System.getenv("APPDATA");
        if (!StringUtils.isEmpty(appData)) {
          appDataDir = new File(appData);
        }
      } catch (SecurityException ex) {
      }
      if (appDataDir != null && appDataDir.isDirectory()) {
        String path = VENDOR_ID + "\\" + APPLICATION_ID + "\\";
        directory = new File(appDataDir, path);
      } else {
        String path = "Application Data\\" + VENDOR_ID + "\\" + APPLICATION_ID + "\\";
        directory = new File(userHome, path);
      }
    } else if (SystemUtils.IS_OS_LINUX) {
      File appDataDir = null;
      try {
        String xdgConfigHome = System.getenv("XDG_CONFIG_HOME");
        if (!StringUtils.isEmpty(xdgConfigHome)) {
          appDataDir = new File(xdgConfigHome);
          if (!appDataDir.isAbsolute()) {
            //https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
            //All paths set in these environment variables must be absolute.
            //If an implementation encounters a relative path in any of these
            //variables it should consider the path invalid and ignore it.
            appDataDir = null;
          }
        }
      } catch (SecurityException ex) {
      }
      if (appDataDir != null && appDataDir.isDirectory()) {
        String path = APPLICATION_ID + "/";
        directory = new File(appDataDir, path);
      } else {
        String path = ".config/" + APPLICATION_ID + "/";
        directory = new File(userHome, path);
      }
    } else if (SystemUtils.IS_OS_MAC_OSX) {
      String path = "Library/Application Support/" + APPLICATION_ID + "/";
      directory = new File(userHome, path);
    } else {
      String path = "." + APPLICATION_ID + "/";
      directory = new File(userHome, path);
    }
    if (directory != null && !directory.exists()) {
      directory.mkdirs();
    }
  }

  void saveProperty(String name, Object obj) {
    if (directory == null) {
      return;
    }
    synchronized(directory) {
      try (XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
            new FileOutputStream(new File(directory, name))))) {
        encoder.writeObject(obj);
      } catch (FileNotFoundException ex) {
        Tools.showError(ex);
      }
    }
  }

  <T> T loadProperty(String name, Class<T> clazz) {<FILL_FUNCTION_BODY>}

}

    if (directory == null) {
      return null;
    }
    synchronized(directory) {
      try (XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(
            new FileInputStream(new File(directory, name))))) {
        try {
          return clazz.cast(decoder.readObject());
        } catch (ClassCastException ex) {
          Tools.showError(ex);
          return null;
        } catch (Exception ex) {
          //probably user messed up with files
          Tools.showError(ex);
          return null;
        }
      } catch (FileNotFoundException ex) {
        //ignore, we have not saved yet a property with this name
      }
    }
    return null;
  
<no_super_class>