public class MatFileReader
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
MatFileReader.ISMatTag
TAG operator.
|
| Modifier and Type | Field and Description |
|---|---|
private java.nio.ByteOrder |
byteOrder
Tells how bytes are organized in the buffer.
|
private java.util.Map<java.lang.String,MLArray> |
data
Container for red
MLArrays |
private static int |
DIRECT_BUFFER_LIMIT
Reads the content of a MAT-file and returns the mapped content.
|
static int |
DIRECT_BYTE_BUFFER |
private MatFileFilter |
filter
Array name filter
|
static int |
HEAP_BYTE_BUFFER |
private MatFileHeader |
matFileHeader
MAT-file header
|
static int |
MEMORY_MAPPED_FILE |
| Constructor and Description |
|---|
MatFileReader() |
MatFileReader(java.io.File file)
Creates instance of
MatFileReader and reads MAT-file
from file. |
MatFileReader(java.io.File file,
MatFileFilter filter)
Creates instance of
MatFileReader and reads MAT-file from
file. |
MatFileReader(java.lang.String fileName)
Creates instance of
MatFileReader and reads MAT-file
from location given as fileName. |
MatFileReader(java.lang.String fileName,
MatFileFilter filter)
Creates instance of
MatFileReader and reads MAT-file
from location given as fileName. |
| Modifier and Type | Method and Description |
|---|---|
private void |
clean(java.lang.Object buffer)
Workaround taken from bug #4724038
to release the memory mapped byte buffer.
|
java.util.Map<java.lang.String,MLArray> |
getContent()
Returns a map of
MLArray objects that were inside MAT-file. |
java.util.ArrayList<MLArray> |
getData()
Deprecated.
use
getContent which returns a Map to provide
easier access to MLArrays contained in MAT-file |
MatFileHeader |
getMatFileHeader()
Gets MAT-file header
|
MLArray |
getMLArray(java.lang.String name)
Returns the value to which the red file maps the specified array name.
|
java.util.Map<java.lang.String,MLArray> |
read(java.io.File file)
Reads the content of a MAT-file and returns the mapped content.
|
java.util.Map<java.lang.String,MLArray> |
read(java.io.File file,
int policy)
Reads the content of a MAT-file and returns the mapped content.
|
java.util.Map<java.lang.String,MLArray> |
read(java.io.File file,
MatFileFilter filter,
int policy) |
private void |
readData(java.nio.ByteBuffer buf)
Reads data form byte buffer.
|
private int[] |
readDimension(java.nio.ByteBuffer buf)
Reads Matrix dimensions.
|
private int[] |
readFlags(java.nio.ByteBuffer buf)
Reads Matrix flags.
|
private void |
readHeader(java.nio.ByteBuffer buf)
Reads MAT-file header.
|
private MLArray |
readMatrix(java.nio.ByteBuffer buf,
boolean isRoot)
Reads miMATRIX from from input stream.
|
private java.lang.String |
readName(java.nio.ByteBuffer buf)
Reads Matrix name.
|
private java.lang.String |
zeroEndByteArrayToString(byte[] bytes)
Converts byte array to
String. |
public static final int MEMORY_MAPPED_FILE
public static final int DIRECT_BYTE_BUFFER
public static final int HEAP_BYTE_BUFFER
private MatFileHeader matFileHeader
private java.util.Map<java.lang.String,MLArray> data
MLArraysprivate java.nio.ByteOrder byteOrder
private MatFileFilter filter
private static final int DIRECT_BUFFER_LIMIT
Because of java bug #4724038 which disables releasing the memory mapped resource, additional different allocation modes are available.
MEMORY_MAPPED_FILE - a memory mapped fileDIRECT_BYTE_BUFFER - a uses
ByteBuffer.allocateDirect(int) method to read in
the file contentsHEAP_BYTE_BUFFER - a uses
ByteBuffer.allocate(int) method to read in the
file contentsMatFileFilter,
Constant Field Valuespublic MatFileReader(java.lang.String fileName)
throws java.io.FileNotFoundException,
java.io.IOException
MatFileReader and reads MAT-file
from location given as fileName.
This method reads MAT-file without filtering.fileName - the MAT-file path Stringjava.io.IOException - when error occurred while processing the file.java.io.FileNotFoundExceptionpublic MatFileReader(java.lang.String fileName,
MatFileFilter filter)
throws java.io.IOException
MatFileReader and reads MAT-file
from location given as fileName.
Results are filtered by MatFileFilter. Arrays that do not meet
filter match condition will not be available in results.fileName - the MAT-file path StringMatFileFilter - array name filter.java.io.IOException - when error occurred while processing the file.public MatFileReader(java.io.File file)
throws java.io.IOException
MatFileReader and reads MAT-file
from file.
This method reads MAT-file without filtering.file - the MAT-filejava.io.IOException - when error occurred while processing the file.public MatFileReader(java.io.File file,
MatFileFilter filter)
throws java.io.IOException
MatFileReader and reads MAT-file from
file.
Results are filtered by MatFileFilter. Arrays that do not
meet filter match condition will not be available in results.
Note: this method reads file using the memory mapped file policy, see
notes to #read(File, MatFileFilter, com.jmatio.io.MatFileReader.MallocPolicy)
file - the MAT-fileMatFileFilter - array name filter.java.io.IOException - when error occurred while processing the file.public MatFileReader()
public java.util.Map<java.lang.String,MLArray> read(java.io.File file) throws java.io.IOException
This method calls
read(file, new MatFileFilter(), MallocPolicy.MEMORY_MAPPED_FILE).
file - a valid MAT-file file to be readgetContent()java.io.IOException - if error occurs during file processingpublic java.util.Map<java.lang.String,MLArray> read(java.io.File file, int policy) throws java.io.IOException
This method calls
read(file, new MatFileFilter(), policy).
file - a valid MAT-file file to be readpolicy - the file memory allocation policygetContent()java.io.IOException - if error occurs during file processingpublic java.util.Map<java.lang.String,MLArray> read(java.io.File file, MatFileFilter filter, int policy) throws java.io.IOException
java.io.IOExceptionprivate void clean(java.lang.Object buffer)
throws java.lang.Exception
Little quote from SUN: This is highly inadvisable, to put it mildly. It is exceedingly dangerous to forcibly unmap a mapped byte buffer that's visible to Java code. Doing so risks both the security and stability of the system
Since the memory byte buffer used to map the file is not exposed to the outside world, maybe it's save to use it without being cursed by the SUN. Since there is no other solution this will do (don't trust voodoo GC invocation)
buffer - the buffer to be unmappedjava.lang.Exception - all kind of evil stuffpublic MatFileHeader getMatFileHeader()
MatFileHeader objectpublic java.util.ArrayList<MLArray> getData()
getContent which returns a Map to provide
easier access to MLArrays contained in MAT-fileMLArray objects that were inside MAT-fileArrayListpublic MLArray getMLArray(java.lang.String name)
null if the file contains no content for this name.- - array nameMLArray to which this file maps the specified name,
or null if the file contains no content for this name.public java.util.Map<java.lang.String,MLArray> getContent()
MLArray objects that were inside MAT-file.
MLArrays are mapped with MLArrays' namesMap of MLArrays mapped with their names.private void readData(java.nio.ByteBuffer buf)
throws java.io.IOException
miCOMPRESSED data or miMATRIX data.
Compressed data are inflated and the product is recursively passed back
to this same method.
Modifies buf position.buf - -
input byte bufferjava.io.IOException - when error occurs while reading the buffer.private MLArray readMatrix(java.nio.ByteBuffer buf, boolean isRoot) throws java.io.IOException
null.
Modifies buf position to the position when reading
finished.
Uses recursive processing for some ML**** data types.buf - -
input byte bufferisRoot - -
when true informs that if this is a top level
matrixMLArray or null if matrix does
not match filterjava.io.IOException - when error occurs while reading the buffer.private java.lang.String zeroEndByteArrayToString(byte[] bytes)
throws java.io.IOException
String.
It assumes that String ends with \0 value.bytes - byte array containing the string.java.io.IOException - if reading error occurred.private int[] readFlags(java.nio.ByteBuffer buf)
throws java.io.IOException
buf position.buf - ByteBufferjava.io.IOException - if reading from buffer failsprivate int[] readDimension(java.nio.ByteBuffer buf)
throws java.io.IOException
buf position.buf - ByteBufferjava.io.IOException - if reading from buffer failsprivate java.lang.String readName(java.nio.ByteBuffer buf)
throws java.io.IOException
buf position.buf - ByteBufferStringjava.io.IOException - if reading from buffer failsprivate void readHeader(java.nio.ByteBuffer buf)
throws java.io.IOException
buf position.buf - ByteBufferjava.io.IOException - if reading from buffer fails or if this is not a valid
MAT-file