private void rewriteManifestFile(boolean dryRun, Path filePath, Set<String> elements) throws IOException, TerseException {
        Objects.requireNonNull(filePath, "filePath must be non-null");
        Objects.requireNonNull(elements, "elements must be non-null");
        Path writableFile = getWritablePath(dryRun, filePath);
        if (elements.isEmpty()) {
            if (Files.exists(filePath)) {
                log.debug("Delete {}", filePath);
                if (!dryRun) {
                    Files.delete(writableFile);
                }
            }
        } else {
            if (!Files.exists(filePath)) {
                log.debug("Create {}", filePath);
            }
            log.debug("Write {} with content {}", filePath, elements);
            if (!dryRun) {
                try (OutputStream stream = new BufferedOutputStream(Files.newOutputStream(
                        writableFile,
                        StandardOpenOption.CREATE,
                        StandardOpenOption.WRITE,
                        StandardOpenOption.TRUNCATE_EXISTING
                ))) {
                    byte[] newline = System.lineSeparator().getBytes(StandardCharsets.UTF_8);
                    stream.write(MANIFEST_HEADER.getBytes(StandardCharsets.UTF_8));
                    stream.write(newline);
                    for (String element : elements) {
                        stream.write(element.getBytes(StandardCharsets.UTF_8));
                        stream.write(newline);
                    }
                }
            }
        }
    }
Rewrite a single manifest file.
Will create the file if it does not exist and at least one element is specified.
Will delete the file if it exists and no elements are specified.

@param dryRun              True if the rewrite should be applied, false if it should be simulated.
@param filePath            Path to file which should be rewritten.
@param elements            Class names of plugins which should appear in the manifest
tools/src/main/java/org/apache/kafka/tools/ManifestWorkspace.java