diff --git a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java index deee58e7..3a088591 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/FileManager.java +++ b/source/src/main/java/one/nem/lacerta/source/file/FileManager.java @@ -35,6 +35,8 @@ public interface FileManager { // Create FileManager createFile() throws IOException; FileManager createFile(String fileName) throws IOException; + FileManager createFileIfNotExist() throws IOException; + FileManager createFileIfNotExist(String fileName) throws IOException; FileManager createDirectory() throws IOException; FileManager createDirectory(String directoryName) throws IOException; FileManager createDirectoryIfNotExist() throws IOException; diff --git a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java index 01f0bc07..ed011f9c 100644 --- a/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java +++ b/source/src/main/java/one/nem/lacerta/source/file/impl/FileManagerImpl.java @@ -190,6 +190,20 @@ public class FileManagerImpl implements FileManager { return this.createFile(); } + @Override + public FileManager createFileIfNotExist() throws IOException { + if (!this.isExist()) { + this.createFile(); + } + return this; + } + + @Override + public FileManager createFileIfNotExist(String fileName) throws IOException { + this.resolve(fileName); + return this.createFileIfNotExist(); + } + @Override public FileManager createDirectory() throws IOException { try { @@ -237,6 +251,7 @@ public class FileManagerImpl implements FileManager { transformer.transform(source, result); } catch (Exception e) { logger.error("saveXmlInternal", e.getMessage()); + e.printStackTrace(); throw new IOException("Failed to save xml"); } }