Skip to content

Commit

Permalink
BZ1034030 : 0 byte local cache file in UrlResource
Browse files Browse the repository at this point in the history
(cherry picked from commit 05196fa)
  • Loading branch information
tkobayas authored and etirelli committed Dec 18, 2013
1 parent fe42528 commit 1621e3b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion drools-core/src/main/java/org/drools/io/impl/UrlResource.java
Expand Up @@ -173,12 +173,20 @@ private File getCacheFile() {
}
}

private File getTemproralCacheFile() {
try {
return new File(CACHE_DIR, URLEncoder.encode(this.url.toString(), "UTF-8") + "_tmp");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}

/**
* Save a copy in the local cache - in case remote source is not available in future.
*/
private void cacheStream() {
try {
File fi = getCacheFile();
File fi = getTemproralCacheFile();
if (fi.exists()) fi.delete();
FileOutputStream fout = new FileOutputStream(fi);
InputStream in = grabStream();
Expand All @@ -190,6 +198,9 @@ private void cacheStream() {
fout.flush();
fout.close();
in.close();

File cacheFile = getCacheFile();
fi.renameTo(cacheFile);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 1621e3b

Please sign in to comment.