Permalink
Browse files

#8 modify: renameTo() return unchecked, jar file lost

  • Loading branch information...
shadogray authored and n1hility committed Oct 29, 2012
1 parent c7ee3cc commit d8233ead44405d3bae3446af267717ba62b6d89e
Showing with 14 additions and 1 deletion.
  1. +14 −1 src/main/java/org/jboss/jandex/JarIndexer.java
@@ -123,7 +123,20 @@ public static Result createJarIndex(File jarFile, Indexer indexer, boolean modif
if (modify) {
jarFile.delete();
- tmpCopy.renameTo(jarFile);
+ if (!tmpCopy.renameTo(jarFile)) {
+ FileInputStream fis = new FileInputStream(tmpCopy);
+ FileOutputStream fos = new FileOutputStream(new File(jarFile.getAbsolutePath()));
+ try {
+ byte[] b = new byte[1024];
+ for (int count=0; (count = fis.read(b, 0, 1024)) >= 1024; ) {
+ fos.write(b, 0, count);
+ }
+ } finally {
+ fis.close();
+ fos.close();
+ }
+ tmpCopy.delete();
+ }
tmpCopy = null;
}
return new Result(index, modify ? "META-INF/jandex.idx" : outputFile.getPath(), bytes);

0 comments on commit d8233ea

Please sign in to comment.