From: luukkainen Date: Wed, 15 Aug 2012 14:47:42 +0000 (+0000) Subject: Wrapping FileInputStream to BufferedInputStream seems to increase performance. X-Git-Tag: simantics-1.7~4^2~19 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=b7c99b30d985dc8a25999bb0de0778d78f181310;p=simantics%2Fsysdyn.git Wrapping FileInputStream to BufferedInputStream seems to increase performance. refs #3544 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25458 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.modelica/src/org/simantics/modelica/reader/MatFileReader.java b/org.simantics.modelica/src/org/simantics/modelica/reader/MatFileReader.java index 49170171..032dbc44 100644 --- a/org.simantics.modelica/src/org/simantics/modelica/reader/MatFileReader.java +++ b/org.simantics.modelica/src/org/simantics/modelica/reader/MatFileReader.java @@ -1,7 +1,9 @@ package org.simantics.modelica.reader; +import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -51,7 +53,7 @@ public class MatFileReader implements ResultFileReader { Integer index = indices.get(item); if (index == null) throw new IOException("Unknown item: " + item); - InputStream in = new FileInputStream(file); + InputStream in = openStream(); skip(dataMark, in); Object data = readRow(dataHeader, index, in); @@ -76,7 +78,7 @@ public class MatFileReader implements ResultFileReader { Integer index = indices.get(item); if (index == null) throw new IOException("Unknown item: " + item); - InputStream in = new FileInputStream(file); + InputStream in = openStream(); skip(dataMark, in); Object data = readRow(dataHeader, index, start, count, skip, in); @@ -97,7 +99,7 @@ public class MatFileReader implements ResultFileReader { indexes.add(index); } - InputStream in = new FileInputStream(file); + InputStream in = openStream(); skip(dataMark, in); @@ -110,6 +112,10 @@ public class MatFileReader implements ResultFileReader { } + private InputStream openStream() throws FileNotFoundException { + return new BufferedInputStream(new FileInputStream(file)); + } + @Override public double[][] readData(List items, int start, int count, int skip) throws IOException { @@ -123,7 +129,7 @@ public class MatFileReader implements ResultFileReader { indexes.add(index); } - InputStream in = new FileInputStream(file); + InputStream in = openStream(); skip(dataMark, in); @@ -137,7 +143,7 @@ public class MatFileReader implements ResultFileReader { private void readVariables() throws IOException { - InputStream in = new FileInputStream(file); + InputStream in = openStream(); readMatrix(in); // Header StringMatrix names = (StringMatrix)readMatrix(in); // Variable names readMatrix(in); // Variable descriptions @@ -565,7 +571,7 @@ public class MatFileReader implements ResultFileReader { String name; public MatrixHeader(InputStream in) throws IOException{ - int s = readBytes; + //int s = readBytes; type = getInt(in); rows = getInt(in); columns = getInt(in);