Reads MAT-file header. Modifies buf position. @param buf ByteBuffer @throws IOException if reading from buffer fails or if this is not a valid MAT-file
(ByteBuffer buf)
| 1313 | * MAT-file |
| 1314 | */ |
| 1315 | void readHeader(ByteBuffer buf) throws IOException { |
| 1316 | //header values |
| 1317 | String description; |
| 1318 | byte[] endianIndicator = new byte[2]; |
| 1319 | |
| 1320 | // This part of the header is missing if the file isn't a regular mat file. So ignore. |
| 1321 | if (matType == MatFileType.Regular) { |
| 1322 | //descriptive text 116 bytes |
| 1323 | byte[] descriptionBuffer = new byte[116]; |
| 1324 | buf.get(descriptionBuffer); |
| 1325 | |
| 1326 | description = zeroEndByteArrayToString(descriptionBuffer); |
| 1327 | |
| 1328 | if (!description.matches("MATLAB 5.0 MAT-file.*")) { |
| 1329 | throw new MatlabIOException("This is not a valid MATLAB 5.0 MAT-file."); |
| 1330 | } |
| 1331 | |
| 1332 | //subsyst data offset 8 bytes |
| 1333 | buf.position(buf.position() + 8); |
| 1334 | } else { |
| 1335 | description = "Simulink generated MATLAB 5.0 MAT-file"; // Default simulink description. |
| 1336 | } |
| 1337 | |
| 1338 | byte[] bversion = new byte[2]; |
| 1339 | //version 2 bytes |
| 1340 | buf.get(bversion); |
| 1341 | |
| 1342 | //endian indicator 2 bytes |
| 1343 | buf.get(endianIndicator); |
| 1344 | |
| 1345 | matFileHeader = MatFileHeader.parseFrom(description, bversion, endianIndicator); |
| 1346 | buf.order(matFileHeader.getByteOrder()); |
| 1347 | |
| 1348 | // After the header, the next read must be aligned. Thus force the alignment. Only matters with reduced header data, |
| 1349 | // but apply it regardless for safety. |
| 1350 | buf.position((buf.position() + 7) & 0xfffffff8); |
| 1351 | } |
| 1352 | |
| 1353 | /** |
| 1354 | * TAG operator. Facilitates reading operations. |
no test coverage detected