private void readHeader ( ByteBuffer buf ) throws IOException { //header values String description ; int version ; byte [ ] endianIndicator = new byte [ 2 ] ; // This part of the header is missing if the file isn't a regular mat file. So ignore. if ( matType == MatFileType . Regular ) { //descriptive text 116 bytes byte [ ] descriptionBuffer = new byte [ 116 ] ; buf . get ( descriptionBuffer ) ; description = zeroEndByteArrayToString ( descriptionBuffer ) ; if ( ! description . matches ( "MATLAB 5.0 MAT-file.*" ) ) { throw new MatlabIOException ( "This is not a valid MATLAB 5.0 MAT-file." ) ; } //subsyst data offset 8 bytes buf . position ( buf . position ( ) + 8 ) ; } else { description = "Simulink generated MATLAB 5.0 MAT-file" ; // Default simulink description. } byte [ ] bversion = new byte [ 2 ] ; //version 2 bytes buf . get ( bversion ) ; //endian indicator 2 bytes buf . get ( endianIndicator ) ; //program reading the MAT-file must perform byte swapping to interpret the data //in the MAT-file correctly if ( ( char ) endianIndicator [ 0 ] == ' ' && ( char ) endianIndicator [ 1 ] == ' ' ) { byteOrder = ByteOrder . LITTLE_ENDIAN ; version = bversion [ 1 ] & 0xff | bversion [ 0 ] << 8 ; } else { byteOrder = ByteOrder . BIG_ENDIAN ; version = bversion [ 0 ] & 0xff | bversion [ 1 ] << 8 ; } buf . order ( byteOrder ) ; matFileHeader = new MatFileHeader ( description , version , endianIndicator , byteOrder ) ; // After the header, the next read must be aligned. Thus force the alignment. Only matters with reduced header data, // but apply it regardless for safety. buf . position ( ( buf . position ( ) + 7 ) & 0xfffffff8 ) ; }
Reads MAT - file header .