<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_class(data, magic=None):
 """ unpacks a Java class from data, which can be a string, a buffer, or a stream supporting the read method. Returns a populated JavaClassInfo instance. If data is a stream which has already been confirmed to be a java class, it may have had the first four bytes read from it already. In this case, pass those magic bytes as a str or tuple and the unpacker will not attempt to read them again. Raises a ClassUnpackException or an UnpackException if the class data is malformed. Raises Unimplemented if a feature is discovered which isn't understood by javatools yet. """


    with unpack(data) as up:
        magic = magic or up.unpack_struct(_BBBB)
        if magic != JAVA_CLASS_MAGIC:
            raise ClassUnpackException("Not a Java class file")

        o = JavaClassInfo()
        o.unpack(up, magic=magic)

    return o