public final class PropertyCacheFile extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
PropertyCacheFile.ExternalResource
Class which represents external resource.
|
| Modifier and Type | Field and Description |
|---|---|
private static int |
BASE_16
Default number for base 16 encoding.
|
private static byte[] |
BUFFER
Default buffer for reading from streams.
|
private static int |
BUFFER_SIZE
Size of default byte array for buffer.
|
private Configuration |
config
Configuration object.
|
static java.lang.String |
CONFIG_HASH_KEY
The property key to use for storing the hashcode of the
configuration.
|
private java.lang.String |
configHash
Generated configuration hash.
|
private java.util.Properties |
details
The details on files.
|
static java.lang.String |
EXTERNAL_RESOURCE_KEY_PREFIX
The property prefix to use for storing the hashcode of an
external resource.
|
private java.lang.String |
fileName
File name of cache.
|
| Constructor and Description |
|---|
PropertyCacheFile(Configuration config,
java.lang.String fileName)
Creates a new
PropertyCacheFile instance. |
| Modifier and Type | Method and Description |
|---|---|
private boolean |
areExternalResourcesChanged(java.util.Set<PropertyCacheFile.ExternalResource> resources)
Checks whether the contents of external configuration resources were changed.
|
private void |
fillCacheWithExternalResources(java.util.Set<PropertyCacheFile.ExternalResource> externalResources)
Fills cache with a set of
PropertyCacheFile.ExternalResource. |
java.lang.String |
get(java.lang.String name)
Retrieves the hash of a specific file.
|
private static java.lang.String |
getHashCodeBasedOnObjectContent(java.io.Serializable object)
Calculates the hashcode for the serializable object based on its content.
|
boolean |
isInCache(java.lang.String uncheckedFileName,
long timestamp)
Checks that file is in cache.
|
private boolean |
isResourceChanged(PropertyCacheFile.ExternalResource resource)
Checks whether the resource is changed.
|
private boolean |
isResourceLocationInCache(java.lang.String location)
Checks whether resource location is in cache.
|
void |
load()
Load cached values from file.
|
private static byte[] |
loadExternalResource(java.lang.String location)
Loads the content of external resource.
|
private static java.util.Set<PropertyCacheFile.ExternalResource> |
loadExternalResources(java.util.Set<java.lang.String> resourceLocations)
Loads a set of
PropertyCacheFile.ExternalResource based on their locations. |
void |
persist()
Cleans up the object and updates the cache file.
|
void |
put(java.lang.String checkedFileName,
long timestamp)
Records that a file checked ok.
|
void |
putExternalResources(java.util.Set<java.lang.String> locations)
Puts external resources in cache.
|
void |
remove(java.lang.String checkedFileName)
Removed a specific file from the cache.
|
void |
reset()
Resets the cache to be empty except for the configuration hash.
|
private static void |
serialize(java.io.Serializable object,
java.io.OutputStream outputStream)
Serializes object to output stream.
|
private static byte[] |
toByteArray(java.io.InputStream stream)
Reads all the contents of an input stream and returns it as a byte array.
|
public static final java.lang.String CONFIG_HASH_KEY
public static final java.lang.String EXTERNAL_RESOURCE_KEY_PREFIX
private static final int BUFFER_SIZE
private static final byte[] BUFFER
private static final int BASE_16
private final java.util.Properties details
private final Configuration config
private final java.lang.String fileName
private java.lang.String configHash
public PropertyCacheFile(Configuration config, java.lang.String fileName)
PropertyCacheFile instance.config - the current configuration, not nullfileName - the cache filejava.lang.IllegalArgumentException - when either arguments are nullpublic void load() throws java.io.IOException
java.io.IOException - when there is a problems with file readpublic void persist() throws java.io.IOException
java.io.IOException - when there is a problems with file savepublic void reset()
public boolean isInCache(java.lang.String uncheckedFileName, long timestamp)
uncheckedFileName - the file to checktimestamp - the timestamp of the file to checkpublic void put(java.lang.String checkedFileName, long timestamp)
checkedFileName - name of the file that checked oktimestamp - the timestamp of the filepublic java.lang.String get(java.lang.String name)
name - The name of the file to retrieve.null.public void remove(java.lang.String checkedFileName)
checkedFileName - The name of the file to remove.private static java.lang.String getHashCodeBasedOnObjectContent(java.io.Serializable object)
object - serializable object.java.lang.IllegalStateException - when some unexpected happened.private static void serialize(java.io.Serializable object, java.io.OutputStream outputStream) throws java.io.IOException
object - object to be serializedoutputStream - serialization streamjava.io.IOException - if an error occurspublic void putExternalResources(java.util.Set<java.lang.String> locations)
locations - locations of external resources.private static java.util.Set<PropertyCacheFile.ExternalResource> loadExternalResources(java.util.Set<java.lang.String> resourceLocations)
PropertyCacheFile.ExternalResource based on their locations.resourceLocations - locations of external configuration resources.PropertyCacheFile.ExternalResource.private static byte[] loadExternalResource(java.lang.String location) throws java.io.IOException, CheckstyleException
location - external resource location.java.io.IOException - if error while loading occurs.CheckstyleException - if error while loading occurs.private static byte[] toByteArray(java.io.InputStream stream) throws java.io.IOException
stream - The input stream to read from.java.io.IOException - if there is an error reading the input stream.private boolean areExternalResourcesChanged(java.util.Set<PropertyCacheFile.ExternalResource> resources)
resources - a set of PropertyCacheFile.ExternalResource.private boolean isResourceChanged(PropertyCacheFile.ExternalResource resource)
resource - resource to check.private void fillCacheWithExternalResources(java.util.Set<PropertyCacheFile.ExternalResource> externalResources)
PropertyCacheFile.ExternalResource.
If external resource from the set is already in cache, it will be skipped.externalResources - a set of PropertyCacheFile.ExternalResource.private boolean isResourceLocationInCache(java.lang.String location)
location - resource location.Copyright © 2001-2022. All Rights Reserved.