def is_class(data):
    """
    checks that the data (which is a string, buffer, or a stream
    supporting the read method) has the magic numbers indicating it is
    a Java class file. Returns False if the magic numbers do not
    match, or for any errors.
    """

    try:
        with unpack(data) as up:
            magic = up.unpack_struct(_BBBB)

        return magic == JAVA_CLASS_MAGIC

    except UnpackException:
        return False