/** * Load cached values from file. * @throws IOException when there is a problems with file read */ public void load() throws IOException { // get the current config so if the file isn't found // the first time the hash will be added to output file configHash = getHashCodeBasedOnObjectContent(config); final File file = new File(fileName); if (file.exists()) { try (InputStream inStream = Files.newInputStream(file.toPath())) { details.load(inStream); final String cachedConfigHash = details.getProperty(CONFIG_HASH_KEY); if (!configHash.equals(cachedConfigHash)) { // Detected configuration change - clear cache reset(); } } } else { // put the hash in the file if the file is going to be created reset(); } }
/** * Loads a set of {@link ExternalResource} based on their locations. * @param resourceLocations locations of external configuration resources. * @return a set of {@link ExternalResource}. */ private static Set<ExternalResource> loadExternalResources(Set<String> resourceLocations) { final Set<ExternalResource> resources = new HashSet<>(); for (String location : resourceLocations) { try { final byte[] content = loadExternalResource(location); final String contentHashSum = getHashCodeBasedOnObjectContent(content); resources.add(new ExternalResource(EXTERNAL_RESOURCE_KEY_PREFIX + location, contentHashSum)); } catch (CheckstyleException ex) { // if exception happened (configuration resource was not found, connection is not // available, resource is broken, etc), we need to calculate hash sum based on // exception object content in order to check whether problem is resolved later // and/or the configuration is changed. final String contentHashSum = getHashCodeBasedOnObjectContent(ex); resources.add(new ExternalResource(EXTERNAL_RESOURCE_KEY_PREFIX + location, contentHashSum)); } } return resources; }
/** * Load cached values from file. * @throws IOException when there is a problems with file read */ public void load() throws IOException { // get the current config so if the file isn't found // the first time the hash will be added to output file configHash = getHashCodeBasedOnObjectContent(config); final File file = new File(fileName); if (file.exists()) { try (InputStream inStream = Files.newInputStream(file.toPath())) { details.load(inStream); final String cachedConfigHash = details.getProperty(CONFIG_HASH_KEY); if (!configHash.equals(cachedConfigHash)) { // Detected configuration change - clear cache reset(); } } } else { // put the hash in the file if the file is going to be created reset(); } }
/** * Loads a set of {@link ExternalResource} based on their locations. * @param resourceLocations locations of external configuration resources. * @return a set of {@link ExternalResource}. */ private static Set<ExternalResource> loadExternalResources(Set<String> resourceLocations) { final Set<ExternalResource> resources = new HashSet<>(); for (String location : resourceLocations) { try { final byte[] content = loadExternalResource(location); final String contentHashSum = getHashCodeBasedOnObjectContent(content); resources.add(new ExternalResource(EXTERNAL_RESOURCE_KEY_PREFIX + location, contentHashSum)); } catch (CheckstyleException ex) { // if exception happened (configuration resource was not found, connection is not // available, resource is broken, etc), we need to calculate hash sum based on // exception object content in order to check whether problem is resolved later // and/or the configuration is changed. final String contentHashSum = getHashCodeBasedOnObjectContent(ex); resources.add(new ExternalResource(EXTERNAL_RESOURCE_KEY_PREFIX + location, contentHashSum)); } } return resources; }