def _from_io(self, source: IO):
        """
        Loads an existing JVM ClassFile from any file-like object.
        """
        read = source.read

        if unpack('>I', source.read(4))[0] != ClassFile.MAGIC:
            raise ValueError('invalid magic number')

        # The version is swapped on disk to (minor, major), so swap it back.
        self.version = unpack('>HH', source.read(4))[::-1]

        self._constants.unpack(source)

        # ClassFile access_flags, see section #4.1 of the JVM specs.
        self.access_flags.unpack(read(2))

        # The CONSTANT_Class indexes for "this" class and its superclass.
        # Interfaces are a simple list of CONSTANT_Class indexes.
        self._this, self._super, interfaces_count = unpack('>HHH', read(6))
        self._interfaces = unpack(
            f'>{interfaces_count}H',
            read(2 * interfaces_count)
        )

        self.fields.unpack(source)
        self.methods.unpack(source)
        self.attributes.unpack(source)
def _from_io ( self , source : IO ) : read = source . read if unpack ( '>I' , source . read ( 4 ) ) [ 0 ] != ClassFile . MAGIC : raise ValueError ( 'invalid magic number' ) self . version = unpack ( '>HH' , source . read ( 4 ) ) [ : : - 1 ] self . _constants . unpack ( source ) self . access_flags . unpack ( read ( 2 ) ) self . _this , self . _super , interfaces_count = unpack ( '>HHH' , read ( 6 ) ) self . _interfaces = unpack ( f'>{interfaces_count}H' , read ( 2 * interfaces_count ) ) self . fields . unpack ( source ) self . methods . unpack ( source ) self . attributes . unpack ( source )
Loads an existing JVM ClassFile from any file-like object.