From 975b6363415035891444bac0145630b92ba04515 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Tue, 14 Mar 2017 11:20:08 +0100 Subject: [PATCH] avoid overwriting of ots file in stamp --- src/main/java/com/eternitywall/OtsCli.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/eternitywall/OtsCli.java b/src/main/java/com/eternitywall/OtsCli.java index 165206c..049581d 100644 --- a/src/main/java/com/eternitywall/OtsCli.java +++ b/src/main/java/com/eternitywall/OtsCli.java @@ -132,22 +132,24 @@ public static void info (String argsOts) { private static void stamp(String argsFile, List calendarsUrl, Integer m) { FileInputStream fis = null; try { - + String argsOts = argsFile + ".ots"; + Path path = Paths.get(argsOts); + if(Files.exists(path)) { + System.out.println("File '" + argsOts + "' already exist"); + return; + } File file = new File(argsFile); fis = new FileInputStream(file); byte[] stampResult = OpenTimestamps.stamp(fis,calendarsUrl,m); - //System.out.println(Utils.bytesToHex(stampResult)); - - String argsOts = argsFile + ".ots"; - Files.write(Paths.get(argsOts), stampResult); + Files.write(path, stampResult); System.out.println("The timestamp proof '" + argsOts + "' has been created!"); - } catch (IOException e) { e.printStackTrace(); log.severe("No valid file"); } finally { try { - fis.close(); + if(fis!=null) + fis.close(); }catch (IOException e) { log.severe("No valid file"); }