@Test void testReadSuperblockThrowsWhenGivenInvalidOffset() { assertThrows(HdfException.class, () -> Superblock.readSuperblock(fc, 5)); }
public static Superblock readSuperblock(FileChannel fc, long address) { final boolean verifiedSignature = verifySignature(fc, address); if (!verifiedSignature) { throw new HdfException("Superblock didn't contain valid signature"); } logger.trace("Verified superblock signature"); long fileLocation = address + HDF5_FILE_SIGNATURE_LENGTH; ByteBuffer version = ByteBuffer.allocate(1); try { fc.read(version, fileLocation); } catch (IOException e) { throw new HdfException("Failed to read superblock at address = " + Utils.toHex(address)); } version.rewind(); final byte versionOfSuperblock = version.get(); logger.debug("Version of superblock is = {}", versionOfSuperblock); switch (versionOfSuperblock) { case 0: case 1: return new SuperblockV0V1(fc, fileLocation); case 2: case 3: return new SuperblockV2V3(fc, fileLocation); default: throw new UnsupportedHdfException( "Superblock version is not supported. Detected version = " + versionOfSuperblock); } }
Superblock { public static Superblock readSuperblock(FileChannel fc, long address) { final boolean verifiedSignature = verifySignature(fc, address); if (!verifiedSignature) { throw new HdfException("Superblock didn't contain valid signature"); } logger.trace("Verified superblock signature"); long fileLocation = address + HDF5_FILE_SIGNATURE_LENGTH; ByteBuffer version = ByteBuffer.allocate(1); try { fc.read(version, fileLocation); } catch (IOException e) { throw new HdfException("Failed to read superblock at address = " + Utils.toHex(address)); } version.rewind(); final byte versionOfSuperblock = version.get(); logger.debug("Version of superblock is = {}", versionOfSuperblock); switch (versionOfSuperblock) { case 0: case 1: return new SuperblockV0V1(fc, fileLocation); case 2: case 3: return new SuperblockV2V3(fc, fileLocation); default: throw new UnsupportedHdfException( "Superblock version is not supported. Detected version = " + versionOfSuperblock); } } }
Superblock { public static Superblock readSuperblock(FileChannel fc, long address) { final boolean verifiedSignature = verifySignature(fc, address); if (!verifiedSignature) { throw new HdfException("Superblock didn't contain valid signature"); } logger.trace("Verified superblock signature"); long fileLocation = address + HDF5_FILE_SIGNATURE_LENGTH; ByteBuffer version = ByteBuffer.allocate(1); try { fc.read(version, fileLocation); } catch (IOException e) { throw new HdfException("Failed to read superblock at address = " + Utils.toHex(address)); } version.rewind(); final byte versionOfSuperblock = version.get(); logger.debug("Version of superblock is = {}", versionOfSuperblock); switch (versionOfSuperblock) { case 0: case 1: return new SuperblockV0V1(fc, fileLocation); case 2: case 3: return new SuperblockV2V3(fc, fileLocation); default: throw new UnsupportedHdfException( "Superblock version is not supported. Detected version = " + versionOfSuperblock); } }  }
Superblock { public static Superblock readSuperblock(FileChannel fc, long address) { final boolean verifiedSignature = verifySignature(fc, address); if (!verifiedSignature) { throw new HdfException("Superblock didn't contain valid signature"); } logger.trace("Verified superblock signature"); long fileLocation = address + HDF5_FILE_SIGNATURE_LENGTH; ByteBuffer version = ByteBuffer.allocate(1); try { fc.read(version, fileLocation); } catch (IOException e) { throw new HdfException("Failed to read superblock at address = " + Utils.toHex(address)); } version.rewind(); final byte versionOfSuperblock = version.get(); logger.debug("Version of superblock is = {}", versionOfSuperblock); switch (versionOfSuperblock) { case 0: case 1: return new SuperblockV0V1(fc, fileLocation); case 2: case 3: return new SuperblockV2V3(fc, fileLocation); default: throw new UnsupportedHdfException( "Superblock version is not supported. Detected version = " + versionOfSuperblock); } }  abstract int getVersionOfSuperblock(); abstract int getSizeOfOffsets(); abstract int getSizeOfLengths(); abstract long getBaseAddressByte(); abstract long getEndOfFileAddress(); static Superblock readSuperblock(FileChannel fc, long address); }
Superblock { public static Superblock readSuperblock(FileChannel fc, long address) { final boolean verifiedSignature = verifySignature(fc, address); if (!verifiedSignature) { throw new HdfException("Superblock didn't contain valid signature"); } logger.trace("Verified superblock signature"); long fileLocation = address + HDF5_FILE_SIGNATURE_LENGTH; ByteBuffer version = ByteBuffer.allocate(1); try { fc.read(version, fileLocation); } catch (IOException e) { throw new HdfException("Failed to read superblock at address = " + Utils.toHex(address)); } version.rewind(); final byte versionOfSuperblock = version.get(); logger.debug("Version of superblock is = {}", versionOfSuperblock); switch (versionOfSuperblock) { case 0: case 1: return new SuperblockV0V1(fc, fileLocation); case 2: case 3: return new SuperblockV2V3(fc, fileLocation); default: throw new UnsupportedHdfException( "Superblock version is not supported. Detected version = " + versionOfSuperblock); } }  abstract int getVersionOfSuperblock(); abstract int getSizeOfOffsets(); abstract int getSizeOfLengths(); abstract long getBaseAddressByte(); abstract long getEndOfFileAddress(); static Superblock readSuperblock(FileChannel fc, long address);  }