in commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/file/CacheFileDAO.java [90:144]
public CacheFileContent readCacheItem(@NonNullable String cacheName, @NonNullable String key)
{
File file = CacheFileUtils.inst.getCacheFile(cacheName, key);
if (!file.exists())
return null;
final long fileSize = file.length();
if (fileSize <= CacheFileContent.MIN_FILE_LENGTH) {
countCorruptMinLength.incrementAndGet();
log.warn("Corrupted file which failed the minimum length condition for cacheName="
+ cacheName + " key=" + key);
return CacheFileContent.CORRUPTED;
}
RandomAccessFile raf = null;
try {
raf = new RandomAccessFile(file, "r");
CacheFileContent cfc = CacheFileContent.getInstance(raf);
if (cfc.isValid()) {
final int contentLength = (int)fileSize - CacheFileContent.MIN_FILE_LENGTH;
if (contentLength != cfc.getContentLength()) {
countCorruptLength.incrementAndGet();
log.warn("Corrupted file with unexpected content length for cacheName="
+ cacheName + " key=" + key);
return CacheFileContent.CORRUPTED;
}
}
else
{
countCorruptInvalid.incrementAndGet();
log.warn("Corrupted file for cacheName=" + cacheName
+ " key=" + key);
return CacheFileContent.CORRUPTED;
}
return cfc;
} catch (IOException ex) {
countReadIOException.incrementAndGet();
log.warn(ex.getClass().getName(), ex);
} catch (org.apache.commons.lang3.SerializationException ex) {
countReadIOException.incrementAndGet();
log.warn(ex.getClass().getName(), ex);
} finally {
if (raf != null) {
try {
raf.close();
} catch (Exception ex) {
countReadCloseException.incrementAndGet();
log.error("", ex);
}
}
}
return CacheFileContent.CORRUPTED;
}