public synchronized Map<String, MLArray> read(File file, MatFileFilter filter, int policy) throws IOException { return read(new RandomAccessFile(file, "r"), filter, policy); }
public synchronized Map<String, MLArray> read(File file, MatFileFilter filter, int policy) throws IOException { return read(new RandomAccessFile(file, "r"), filter, policy); }
public MatFileReader(File file, MatFileFilter filter, final boolean allocate) throws IOException { this(); inputFile = file; this.filter = filter; if (allocate) read(file, filter, DEFAULT_ACCESS_METHOD); else init(); }
/** * Reads the content of a MAT-file and returns the mapped content. * <p> * This method calls <code>read(stream, new MatFileFilter())</code>. * * @param stream * a valid MAT-file stream to be read * @return the same as <code>{@link #getContent()}</code> * @throws IOException * if error occurs during file processing */ public synchronized Map<String, MLArray> read(InputStream stream) throws IOException { return read(stream, new MatFileFilter()); }
/** * Reads the content of a MAT-file and returns the mapped content. * <p> * This method calls * <code>read(file, new MatFileFilter(), MallocPolicy.MEMORY_MAPPED_FILE)</code>. * * @param file * a valid MAT-file file to be read * @return the same as <code>{@link #getContent()}</code> * @throws IOException * if error occurs during file processing */ public synchronized Map<String, MLArray> read(File file) throws IOException { return read(file, new MatFileFilter(), MEMORY_MAPPED_FILE); }
/** * Reads the content of a MAT-file and returns the mapped content. * <p> * This method calls <code>read(stream, new MatFileFilter())</code>. * * @param stream * a valid MAT-file stream to be read * @return the same as <code>{@link #getContent()}</code> * @throws IOException * if error occurs during file processing */ public synchronized Map<String, MLArray> read(InputStream stream) throws IOException { return read(stream, new MatFileFilter()); }
/** * Reads the content of a MAT-file and returns the mapped content. * <p> * This method calls * <code>read(file, new MatFileFilter(), MallocPolicy.MEMORY_MAPPED_FILE)</code>. * * @param file * a valid MAT-file file to be read * @return the same as <code>{@link #getContent()}</code> * @throws IOException * if error occurs during file processing */ public synchronized Map<String, MLArray> read(File file) throws IOException { return read(file, new MatFileFilter(), MEMORY_MAPPED_FILE); }
/** * Reads the content of a MAT-file and returns the mapped content. * <p> * This method calls * <code>read(file, new MatFileFilter(), MallocPolicy.MEMORY_MAPPED_FILE)</code>. * * @param file * a valid MAT-file file to be read * @return the same as <code>{@link #getContent()}</code> * @throws IOException * if error occurs during file processing */ public synchronized Map<String, MLArray> read(File file) throws IOException { return read(file, new MatFileFilter(), MEMORY_MAPPED_FILE); } /**
/** * Reads the content of a MAT-file and returns the mapped content. * <p> * This method calls <code>read(file, new MatFileFilter(), policy)</code>. * * @param file * a valid MAT-file file to be read * @param policy * the file memory allocation policy * @return the same as <code>{@link #getContent()}</code> * @throws IOException * if error occurs during file processing */ public synchronized Map<String, MLArray> read(File file, int policy) throws IOException { return read(file, new MatFileFilter(), policy); }
/** * Reads the content of a MAT-file and returns the mapped content. * <p> * This method calls * <code>read(file, new MatFileFilter(), MallocPolicy.MEMORY_MAPPED_FILE)</code>. * * @param file * a valid MAT-file file to be read * @return the same as <code>{@link #getContent()}</code> * @throws IOException * if error occurs during file processing */ public synchronized Map<String, MLArray> read(File file) throws IOException { return read(file, new MatFileFilter(), MEMORY_MAPPED_FILE); }
/** * Reads the content of a MAT-file and returns the mapped content. * <p> * This method calls * <code>read(file, new MatFileFilter(), MallocPolicy.MEMORY_MAPPED_FILE)</code>. * * @param file * a valid MAT-file file to be read * @return the same as <code>{@link #getContent()}</code> * @throws IOException * if error occurs during file processing */ public synchronized Map<String, MLArray> read(File file) throws IOException { return read(file, new MatFileFilter(), MEMORY_MAPPED_FILE); } /**
public static double[][] readDoublesMatrixFromMat(Path matFile, String doublesMatrixName) throws IOException { Objects.requireNonNull(matFile, "mat file is null"); MatFileReader matFileReader = new MatFileReader(); Map<String, MLArray> matFileContent = matFileReader.read(matFile.toFile()); MLDouble doublesMatrix = (MLDouble) matFileContent.get(doublesMatrixName); double[][] doubles = null; if (doublesMatrix != null) { doubles = doublesMatrix.getArray(); } return doubles; }
public MCSMatFileReader(Path matFile) throws Exception { Objects.requireNonNull(matFile, "mat file is null"); MatFileReader sampledDataFileReader = new MatFileReader(); matFileContent = sampledDataFileReader.read(matFile.toFile()); String errorMessage = Utils.MLCharToString((MLChar) matFileContent.get("errmsg")); if (!("Ok".equalsIgnoreCase(errorMessage))) { throw new MatlabException(errorMessage); } }
public static String[] readStringsArrayFromMat(Path matFile, String stringsArrayName) throws IOException { Objects.requireNonNull(matFile, "mat file is null"); Objects.requireNonNull(stringsArrayName, "strings array name is null"); MatFileReader matFileReader = new MatFileReader(); Map<String, MLArray> matFileContent = matFileReader.read(matFile.toFile()); MLCell stringsArray = (MLCell) matFileContent.get(stringsArrayName); String[] strings = new String[stringsArray.getN()]; for (int i = 0; i < stringsArray.getN(); i++) { strings[i] = ((MLChar) stringsArray.get(0, i)).getString(0); } return strings; }
@Before public void setUp() throws IOException { MatFileReader reader = new MatFileReader(); Map<String, MLArray> content = reader.read(spmFile); array = content.get("SPM"); }
/** Reads a full set of bytes (including the header). */ public static MatFile readFull(RandomAccessFile file) throws IOException { MatFileReader reader = new MatFileReader(); reader.read(file, new MatFileFilter(), MatFileReader.HEAP_BYTE_BUFFER); return new MatFile(reader.getMatFileHeader(), reader.getContent()); } }
/** Reads a full set of bytes (including the header). */ public static MatFile readFull(RandomAccessFile file) throws IOException { MatFileReader reader = new MatFileReader(); reader.read(file, new MatFileFilter(), MatFileReader.HEAP_BYTE_BUFFER); return new MatFile(reader.getMatFileHeader(), reader.getContent()); } }
@Test public void testObject() throws Exception { MatFileReader mfr = new MatFileReader(); Map<String, MLArray> content = mfr.read(getTestFile("object.mat")); MLObject mlObject = (MLObject) content.get("X"); assertEquals("inline", mlObject.getClassName()); assertTrue(mlObject.getFields(0).keySet().contains("expr")); }
/** * Test case that exposes the bug found by Julien C. from polymtl.ca * <p> * The test file contains a sparse array on crashes the reader. The bug appeared when the {@link MLSparse} tried to allocate resources (very very big {@link ByteBuffer}) and {@link IllegalArgumentException} was thrown. * * @throws IOException */ @Test public void testBigSparseFile() throws IOException { // read array form file MatFileReader mfr = new MatFileReader(); // reader crashes on reading this file // bug caused by sparse array allocation mfr.read(getTestFile("bigsparse.mat"), MatFileReader.DIRECT_BYTE_BUFFER); }
@Test public void testJavaObject() throws Exception { MatFileReader mfr = new MatFileReader(); Map<String, MLArray> content = mfr.read(getTestFile("java.mat")); MLJavaObject mlJavaObject = (MLJavaObject) content.get("f"); assertEquals("java.io.File", mlJavaObject.getClassName()); // assertEquals( new File("c:/temp"), mlJavaObject.getObject() ); }