]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Wrapping FileInputStream to BufferedInputStream seems to increase performance.
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 15 Aug 2012 14:47:42 +0000 (14:47 +0000)
committerluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 15 Aug 2012 14:47:42 +0000 (14:47 +0000)
refs #3544

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25458 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.modelica/src/org/simantics/modelica/reader/MatFileReader.java

index 491701710dc757b74725ec0a10d0cd0de9fb2072..032dbc440d20cae242a23cd92e0dc8e519c495ec 100644 (file)
@@ -1,7 +1,9 @@
 package org.simantics.modelica.reader;\r
 \r
+import java.io.BufferedInputStream;\r
 import java.io.File;\r
 import java.io.FileInputStream;\r
+import java.io.FileNotFoundException;\r
 import java.io.IOException;\r
 import java.io.InputStream;\r
 import java.util.ArrayList;\r
@@ -51,7 +53,7 @@ public class MatFileReader implements ResultFileReader {
                Integer index = indices.get(item);\r
                if (index == null)\r
                        throw new IOException("Unknown item: " + item);\r
-               InputStream in = new FileInputStream(file);\r
+               InputStream in = openStream();\r
                skip(dataMark, in);\r
                \r
                Object data = readRow(dataHeader, index, in);\r
@@ -76,7 +78,7 @@ public class MatFileReader implements ResultFileReader {
                Integer index = indices.get(item);\r
                if (index == null)\r
                        throw new IOException("Unknown item: " + item);\r
-               InputStream in = new FileInputStream(file);\r
+               InputStream in = openStream();\r
                skip(dataMark, in);\r
                \r
                Object data = readRow(dataHeader, index, start, count, skip, in);\r
@@ -97,7 +99,7 @@ public class MatFileReader implements ResultFileReader {
                        indexes.add(index);\r
                }\r
                \r
-               InputStream in = new FileInputStream(file);\r
+               InputStream in = openStream();\r
                skip(dataMark, in);\r
                \r
                \r
@@ -110,6 +112,10 @@ public class MatFileReader implements ResultFileReader {
 \r
        }\r
        \r
+       private InputStream openStream() throws FileNotFoundException {\r
+               return new BufferedInputStream(new FileInputStream(file));\r
+       }\r
+       \r
        @Override\r
        public double[][] readData(List<String> items, int start, int count,\r
                        int skip) throws IOException {\r
@@ -123,7 +129,7 @@ public class MatFileReader implements ResultFileReader {
                        indexes.add(index);\r
                }\r
                \r
-               InputStream in = new FileInputStream(file);\r
+               InputStream in = openStream();\r
                skip(dataMark, in);\r
                \r
                \r
@@ -137,7 +143,7 @@ public class MatFileReader implements ResultFileReader {
        \r
        \r
        private void readVariables() throws IOException {\r
-               InputStream in = new FileInputStream(file);\r
+               InputStream in = openStream();\r
                readMatrix(in); // Header\r
                StringMatrix names = (StringMatrix)readMatrix(in); // Variable names\r
            readMatrix(in); // Variable descriptions\r
@@ -565,7 +571,7 @@ public class MatFileReader implements ResultFileReader {
         String name;\r
         \r
         public MatrixHeader(InputStream in) throws IOException{\r
-               int s = readBytes;\r
+               //int s = readBytes;\r
                type = getInt(in);\r
             rows = getInt(in);\r
             columns = getInt(in);\r