/** * Store the given time stamp. * * @param value - time stamp to store. */ private void saveLastUpdate(long value) { File dataFile = getLastUpdateFile(); // The data folder must exist dataFile.getParentFile().mkdirs(); if (dataFile.exists()) dataFile.delete(); try { Files.write(Long.toString(value), dataFile, Charsets.UTF_8); } catch (IOException e) { throw new RuntimeException("Cannot write " + dataFile, e); } }
/** * Load the last update time stamp from the file system. * * @return Last update time stamp. */ private long loadLastUpdate() { File dataFile = getLastUpdateFile(); if (dataFile.exists()) { try { return Long.parseLong(Files.toString(dataFile, Charsets.UTF_8)); } catch (NumberFormatException e) { plugin.getLogger().warning("Cannot parse " + dataFile + " as a number."); } catch (IOException e) { plugin.getLogger().warning("Cannot read " + dataFile); } } // Default last update return 0; }