Fixed deleting cache file when it is still opened by a FileInputStream
This commit is contained in:
parent
9867178e8a
commit
998ed44a07
1 changed files with 20 additions and 11 deletions
|
@ -121,27 +121,28 @@ public class DiskFeedInfoCache implements FeedFetcherCache {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SyndFeedInfo remove(final URL url) {
|
public SyndFeedInfo remove(final URL url) {
|
||||||
|
|
||||||
SyndFeedInfo info = null;
|
SyndFeedInfo info = null;
|
||||||
final String fileName = cachePath + File.separator + "feed_" + replaceNonAlphanumeric(url.toString(), '_').trim();
|
final String fileName = cachePath + File.separator + "feed_" + replaceNonAlphanumeric(url.toString(), '_').trim();
|
||||||
FileInputStream fis = null;
|
FileInputStream fis = null;
|
||||||
ObjectInputStream ois = null;
|
ObjectInputStream ois = null;
|
||||||
|
boolean consumed = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
fis = new FileInputStream(fileName);
|
fis = new FileInputStream(fileName);
|
||||||
ois = new ObjectInputStream(fis);
|
ois = new ObjectInputStream(fis);
|
||||||
info = (SyndFeedInfo) ois.readObject();
|
info = (SyndFeedInfo) ois.readObject();
|
||||||
|
consumed = true;
|
||||||
|
|
||||||
final File file = new File(fileName);
|
} catch (final FileNotFoundException e) {
|
||||||
if (file.exists()) {
|
|
||||||
file.delete();
|
|
||||||
}
|
|
||||||
} catch (final FileNotFoundException fnfe) {
|
|
||||||
// That's OK, we'l return null
|
// That's OK, we'l return null
|
||||||
} catch (final ClassNotFoundException cnfe) {
|
} catch (final ClassNotFoundException e) {
|
||||||
// Error writing to cahce is fatal
|
// Error writing to cache is fatal
|
||||||
throw new RuntimeException("Attempting to read from cache", cnfe);
|
throw new RuntimeException("Attempting to read from cache", e);
|
||||||
} catch (final IOException fnfe) {
|
} catch (final IOException e) {
|
||||||
// Error writing to cahce is fatal
|
// Error writing to cache is fatal
|
||||||
throw new RuntimeException("Attempting to read from cache", fnfe);
|
throw new RuntimeException("Attempting to read from cache", e);
|
||||||
} finally {
|
} finally {
|
||||||
if (fis != null) {
|
if (fis != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -155,7 +156,15 @@ public class DiskFeedInfoCache implements FeedFetcherCache {
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (consumed) {
|
||||||
|
final File file = new File(fileName);
|
||||||
|
if (file.exists()) {
|
||||||
|
file.delete();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue