(@NotNull JsonNode data)
| 69 | } |
| 70 | |
| 71 | public void write(@NotNull JsonNode data) throws IOException { |
| 72 | File parent = file.getParentFile(); |
| 73 | if (parent.exists() && !parent.isDirectory()) { |
| 74 | Files.delete(parent.toPath()); |
| 75 | } |
| 76 | if (!parent.exists() && !parent.mkdirs()) { |
| 77 | throw new IOException("Could not create parent directory structure."); |
| 78 | } |
| 79 | |
| 80 | if (file.exists() && file.isDirectory()) { |
| 81 | try (Stream<Path> files = Files.walk(file.toPath())) { |
| 82 | files.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); |
| 83 | } |
| 84 | } |
| 85 | if (!file.exists() && !file.createNewFile()) { |
| 86 | throw new IOException("Could not create parent directory structure."); |
| 87 | } |
| 88 | |
| 89 | try (FileWriter out = new FileWriter(file)) { |
| 90 | if (data.isArray()) { |
| 91 | data.getArray().write(out); |
| 92 | } else { |
| 93 | data.getObject().write(out); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | LOGGER.trace("Wrote {} bytes to {}", file.length(), file.getAbsolutePath()); |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public boolean equals(Object o) { |
no test coverage detected