@Test void testLoadFile() throws Exception { File file = File.createTempFile("test", "txt"); String content = "hello\nred\npen."; Files.write(Paths.get(file.getAbsolutePath()), content.getBytes(UTF_8)); String loadCached = JavaScriptValidator.loadCached(file); assertEquals(content, loadCached); String content2 = "hello\nred\npen.\nmodified\n"; Files.write(Paths.get(file.getAbsolutePath()), content2.getBytes(UTF_8)); file.setLastModified(System.currentTimeMillis() + 2000); String loadCached2 = JavaScriptValidator.loadCached(file); assertEquals(content2, loadCached2); }
static String loadCached(File file) throws IOException { Objects.requireNonNull(file); Long storedTimestamp = loadTime.get(file); if (storedTimestamp != null && storedTimestamp == file.lastModified()) { return fileCache.get(file); } String read = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath())), Charset.forName("UTF-8")); fileCache.put(file, read); loadTime.put(file, file.lastModified()); return read; }
JavaScriptValidator extends Validator { static String loadCached(File file) throws IOException { Objects.requireNonNull(file); Long storedTimestamp = loadTime.get(file); if (storedTimestamp != null && storedTimestamp == file.lastModified()) { return fileCache.get(file); } String read = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath())), Charset.forName("UTF-8")); fileCache.put(file, read); loadTime.put(file, file.lastModified()); return read; } }
JavaScriptValidator extends Validator { static String loadCached(File file) throws IOException { Objects.requireNonNull(file); Long storedTimestamp = loadTime.get(file); if (storedTimestamp != null && storedTimestamp == file.lastModified()) { return fileCache.get(file); } String read = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath())), Charset.forName("UTF-8")); fileCache.put(file, read); loadTime.put(file, file.lastModified()); return read; } JavaScriptValidator(); }
JavaScriptValidator extends Validator { static String loadCached(File file) throws IOException { Objects.requireNonNull(file); Long storedTimestamp = loadTime.get(file); if (storedTimestamp != null && storedTimestamp == file.lastModified()) { return fileCache.get(file); } String read = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath())), Charset.forName("UTF-8")); fileCache.put(file, read); loadTime.put(file, file.lastModified()); return read; } JavaScriptValidator(); @Override void preInit(ValidatorConfiguration config, Configuration globalConfig); @Override void setErrorList(List<ValidationError> errors); @Override void preValidate(Sentence sentence); @Override void preValidate(Section section); @Override void validate(Document document); @Override void validate(Sentence sentence); @Override void validate(Section section); }
JavaScriptValidator extends Validator { static String loadCached(File file) throws IOException { Objects.requireNonNull(file); Long storedTimestamp = loadTime.get(file); if (storedTimestamp != null && storedTimestamp == file.lastModified()) { return fileCache.get(file); } String read = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath())), Charset.forName("UTF-8")); fileCache.put(file, read); loadTime.put(file, file.lastModified()); return read; } JavaScriptValidator(); @Override void preInit(ValidatorConfiguration config, Configuration globalConfig); @Override void setErrorList(List<ValidationError> errors); @Override void preValidate(Sentence sentence); @Override void preValidate(Section section); @Override void validate(Document document); @Override void validate(Sentence sentence); @Override void validate(Section section);  }