Skip to content

Commit 0499de5

Browse files
committed
Merge branch 'fix-rename'
2 parents d13a74d + ae0bff2 commit 0499de5

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/main/java/cz/mallat/uasparser/OnlineUpdater.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,27 @@ protected List<Section> loadDataFromInternet() throws IOException {
188188
List<Section> sections = fp.getSections();
189189

190190
// now that we've finished parsing, we can save the temp copy
191-
tmpFile.renameTo(cacheFile);
191+
Boolean result=tmpFile.renameTo(cacheFile);
192+
193+
if( !result ){
194+
// was across filesystems or target exists, or something else. Try other another way
195+
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4017593
196+
InputStream inStream = new FileInputStream (tmpFile);
197+
OutputStream outStream = new FileOutputStream(cacheFile);
198+
199+
byte[] buffer = new byte[4096];
200+
201+
int length;
202+
while ((length = inStream.read(buffer)) > 0){
203+
outStream.write(buffer, 0, length);
204+
}
205+
206+
inStream.close();
207+
outStream.close();
208+
209+
//delete the original file
210+
tmpFile.delete();
211+
}
192212

193213
return sections;
194214

0 commit comments

Comments
 (0)