]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.acorn/src/org/simantics/acorn/FileIO.java
MainProgram polls nanoTime too often
[simantics/platform.git] / bundles / org.simantics.acorn / src / org / simantics / acorn / FileIO.java
index c5480d86ec6c636233b5e5b21d8d5e688f319966..305094f8315ac443ed75933219111e1deda8eb04 100644 (file)
@@ -19,41 +19,32 @@ import java.util.Map;
 import java.util.Set;
 
 import org.simantics.databoard.file.RuntimeIOException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class FileIO {
-       
-    private static final FileAttribute<?>[] NO_ATTRIBUTES = new FileAttribute[0];
-    
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(FileIO.class);
+
+    private static final FileAttribute<?>[] NO_ATTRIBUTES = {};
+
     private static final Set<OpenOption> CREATE_OPTIONS = new HashSet<>(2);
     private static final Set<OpenOption> APPEND_OPTIONS = new HashSet<>(1);
-    
+
     static {
         CREATE_OPTIONS.add(StandardOpenOption.WRITE);
         CREATE_OPTIONS.add(StandardOpenOption.CREATE);
-        
+
         APPEND_OPTIONS.add(StandardOpenOption.APPEND);
     }
-    
+
        private Path path;
        private int writePosition = 0;
 
-       private FileIO(Path path) {
+       public FileIO(Path path) {
                this.path = path;
        }
-       
-       private static Map<Path, FileIO> map = new HashMap<Path, FileIO>();
-       
-       public static FileIO get(Path path) {
-               synchronized(map) {
-                       FileIO existing = map.get(path);
-                       if(existing == null) {
-                               existing = new FileIO(path);
-                               map.put(path, existing);
-                       }
-                       return existing;
-               }
-       }
-       
+
        //private static final boolean TRACE_SWAP = false;
        private static final boolean TRACE_PERF = false;
 
@@ -71,7 +62,7 @@ public class FileIO {
             if(TRACE_PERF) {
                 long duration = System.nanoTime()-start;
                 double ds = 1e-9*duration;
-                System.err.println("Wrote " + bytes.length + " bytes @ " + 1e-6*bytes.length / ds + "MB/s");
+                LOGGER.info("Wrote " + bytes.length + " bytes @ " + 1e-6*bytes.length / ds + "MB/s");
             }
             return result;
                } catch (Throwable t) {
@@ -90,11 +81,11 @@ public class FileIO {
             }
             byte[] result = buf.array();
             if (result.length != length)
-                System.err.println("faa");
+                LOGGER.info("result length does not match expected {} {} {}", this, result.length, length);
             if (TRACE_PERF) {
                 long duration = System.nanoTime() - start;
                 double ds = 1e-9 * duration;
-                System.err.println("Read " + result.length + " bytes @ " + 1e-6 * result.length / ds + "MB/s");
+                LOGGER.info("Read " + result.length + " bytes @ " + 1e-6 * result.length / ds + "MB/s");
             }
             return result;
         }
@@ -135,10 +126,10 @@ public class FileIO {
                
                syncPath(test);
                
-               long duration = System.nanoTime()-s;
-               System.err.println("Took " + 1e-6*duration + "ms.");
-               
-               
+               if (LOGGER.isDebugEnabled()) {
+               long duration = System.nanoTime()-s;
+               LOGGER.info("Took " + 1e-6*duration + "ms.");
+               }
        }
        
 }