public static byte[] removeDebugInfo(byte[] bytes) {
        if (bytes.length >= 4) {
            // Check magic number.
            int magic = ((bytes[0] & 0xff) << 24) | ((bytes[1] & 0xff) << 16)
                    | ((bytes[2] & 0xff) << 8) | (bytes[3] & 0xff);
            if (magic != 0xCAFEBABE)
                return bytes;
        } else {
            return bytes;
        }

        // We set the initial size as it cannot exceed that value (but note that
        // this may not be the final size).
        ByteArrayOutputStream baos = new ByteArrayOutputStream(bytes.length);
        DataOutputStream dos = new DataOutputStream(baos);

        try {
            ClassReader classReader = new ClassReader(bytes);
            CleanClass cleanClass = new CleanClass(dos);
            classReader.accept(cleanClass, ClassReader.SKIP_DEBUG);
            if (cleanClass.isFiltered()) {
                return FILTERED_BYTECODE;
            }
        } catch (Exception ex) {
            return bytes;
        }

        return baos.toByteArray();
    }
public static byte [ ] removeDebugInfo ( byte [ ] bytes ) { if ( bytes . length >= 4 ) { int magic = ( ( bytes [ 0 ] & 0xff ) << 24 ) | ( ( bytes [ 1 ] & 0xff ) << 16 ) | ( ( bytes [ 2 ] & 0xff ) << 8 ) | ( bytes [ 3 ] & 0xff ) ; if ( magic != 0xCAFEBABE ) return bytes ; } else { return bytes ; } ByteArrayOutputStream baos = new ByteArrayOutputStream ( bytes . length ) ; DataOutputStream dos = new DataOutputStream ( baos ) ; try { ClassReader classReader = new ClassReader ( bytes ) ; CleanClass cleanClass = new CleanClass ( dos ) ; classReader . accept ( cleanClass , ClassReader . SKIP_DEBUG ) ; if ( cleanClass . isFiltered ( ) ) { return FILTERED_BYTECODE ; } } catch ( Exception ex ) { return bytes ; } return baos . toByteArray ( ) ; }
Removes debug info from the given class file. If the file is not java
class file, the given byte array is returned without any change.

@param bytes
Bytes that are from a classfile.
@return classfile without debug info or the given array if the given
array is not java classfile.