<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def unpack(self, unpacker, magic=None):
 """ Unpacks a Java class from an unpacker stream. Updates the structure of this instance. If the unpacker has already had the magic header read off of it, the read value may be passed via the optional magic parameter and it will not attempt to read the value again. """


        # only unpack the magic bytes if it wasn't specified
        magic = magic or unpacker.unpack_struct(_BBBB)

        if isinstance(magic, (str, buffer)):
            magic = tuple(ord(m) for m in magic)
        else:
            magic = tuple(magic)

        if magic != JAVA_CLASS_MAGIC:
            raise ClassUnpackException("Not a Java class file")

        self.magic = magic

        # unpack (minor, major), store as (major, minor)
        self.version = unpacker.unpack_struct(_HH)[::-1]

        # unpack constant pool
        self.cpool.unpack(unpacker)

        (a, b, c) = unpacker.unpack_struct(_HHH)
        self.access_flags = a
        self.this_ref = b
        self.super_ref = c

        # unpack interfaces
        (count,) = unpacker.unpack_struct(_H)
        self.interfaces = unpacker.unpack(">%iH" % count)

        uobjs = unpacker.unpack_objects

        # unpack fields
        self.fields = tuple(uobjs(JavaMemberInfo,
                                  self.cpool, is_method=False))

        # unpack methods
        self.methods = tuple(uobjs(JavaMemberInfo,
                                   self.cpool, is_method=True))

        # unpack attributes
        self.attribs.unpack(unpacker)