gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
mjc2wsl - use java.nio; do not create non-existing files
authorDoni Pracner <quinnuendo@gmail.com>
Sun, 27 Jul 2014 22:39:43 +0000 (00:39 +0200)
committerDoni Pracner <quinnuendo@gmail.com>
Sun, 27 Jul 2014 22:39:43 +0000 (00:39 +0200)
src/com/quemaster/transformations/mjc2wsl/mjc2wsl.java

index 4522d6502796e780d42eb09e6f7e1598c74c2840..3eac782d1c657fe7bbe0b6ca916f5ec4e4fff667 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.
 */
-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();
                }
        }
        
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner