From: Doni Pracner Date: Sun, 27 Jul 2014 22:39:43 +0000 (+0200) Subject: mjc2wsl - use java.nio; do not create non-existing files X-Git-Tag: v0.2.0~21 X-Git-Url: https://svarog.pmf.uns.ac.rs/gitweb/?a=commitdiff_plain;h=1c83577865dc8dac7b69f2202c59843da0441273;p=mjc2wsl.git mjc2wsl - use java.nio; do not create non-existing files --- 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(); } }