From 1c83577865dc8dac7b69f2202c59843da0441273 Mon Sep 17 00:00:00 2001 From: Doni Pracner Date: Mon, 28 Jul 2014 00:39:43 +0200 Subject: [PATCH] mjc2wsl - use java.nio; do not create non-existing files --- .../transformations/mjc2wsl/mjc2wsl.java | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/com/quemaster/transformations/mjc2wsl/mjc2wsl.java b/src/com/quemaster/transformations/mjc2wsl/mjc2wsl.java index 4522d65..3eac782 100644 --- a/src/com/quemaster/transformations/mjc2wsl/mjc2wsl.java +++ b/src/com/quemaster/transformations/mjc2wsl/mjc2wsl.java @@ -17,8 +17,16 @@ package com.quemaster.transformations.mjc2wsl; You should have received a copy of the GNU General Public License along with mjc2wsl. If not, see . */ -import java.io.*; -import java.util.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Calendar; +import java.util.Properties; import com.quemaster.transformations.TransMessages; @@ -827,7 +835,12 @@ public class mjc2wsl{ System.out.println("no filename supplied"); System.exit(2); } - File f = new File(args[i]); + + Path p = FileSystems.getDefault().getPath(args[i]); + if (!Files.exists(p)){ + System.out.println("input file does not exist"); + System.exit(1); + } if (i + 1 < args.length) { try { @@ -846,16 +859,18 @@ public class mjc2wsl{ e.printStackTrace(); } } - if (f.exists()) { - Calendar now = Calendar.getInstance(); - convertFile(f); - long mili = Calendar.getInstance().getTimeInMillis() - - now.getTimeInMillis(); - System.out.println("conversion time:" + mili + " ms"); - messages.printMessageCounters(); - out.close(); - } else - System.out.println("file does not exist"); + Calendar now = Calendar.getInstance(); + try { + convertStream(Files.newInputStream(p)); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + long mili = Calendar.getInstance().getTimeInMillis() + - now.getTimeInMillis(); + System.out.println("conversion time:" + mili + " ms"); + messages.printMessageCounters(); + out.close(); } } -- 2.25.1