private static void filterClass()

in html4j-maven-plugin/src/main/java/org/netbeans/html/mojo/ProcessJsAnnotations.java [133:171]


    private static void filterClass(MultiFile f, String className) throws IOException {
        if (!f.exists()) {
            return;
        }
        if (className.endsWith(".class")) {
            className = className.substring(0, className.length() - 6);
        }

        List<String> arr;
        boolean modified;
        try (BufferedReader r = new BufferedReader(f.reader())) {
            arr = new ArrayList<>();
            modified = false;
            for (;;) {
                String line = r.readLine();
                if (line == null) {
                    break;
                }
                if (line.endsWith(className)) {
                    modified = true;
                    continue;
                }
                arr.add(line);
            }
        }

        if (modified) {
            if (arr.isEmpty()) {
                f.delete();
            } else {
                try (BufferedWriter w = new BufferedWriter(f.writer())) {
                    for (String l : arr) {
                        w.write(l);
                        w.write("\n");
                    }
                }
            }
        }
    }