private static void removeDuplicates()

in tools/javac/CompatibilityPlugin.java [95:118]


    private static void removeDuplicates(String out8, String out9) {
        byte[] cafeBabe = {(byte) 0xca, (byte) 0xfe, (byte) 0xba, (byte) 0xbe};
        Path path8 = Path.of(out8), path9 = Path.of(out9);
        try (Stream<Path> stream8 = Files.walk(path8)) {
            stream8.filter(Files::isRegularFile).forEach(f8 -> {
                Path f9 = path9.resolve(path8.relativize(f8));
                try {
                    byte[] b9 = Files.readAllBytes(f9);
                    byte[] b8 = Files.readAllBytes(f8);
                    // First 4 bytes are a magic number, next 4 bytes are version which we are ignoring.
                    if (Arrays.equals(b8, 0, 4, cafeBabe, 0, 4) && Arrays.equals(b9, 0, 4, cafeBabe, 0, 4) &&
                            Arrays.equals(b8, 8, b8.length, b9, 8, b9.length)) {
                        // Duplicate! Remove it.
                        Files.delete(f9);
                    }
                } catch (NoSuchFileException | IllegalArgumentException | ArrayIndexOutOfBoundsException ignore) {
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            });
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }