MCPcopy Create free account
hub / github.com/egg82/fetcharr / write

Method write

Lib/src/main/java/me/egg82/arr/file/JSONFile.java:71–98  ·  view source on GitHub ↗
(@NotNull JsonNode data)

Source from the content-addressed store, hash-verified

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) {

Callers 5

isCacheWritableMethod · 0.95
isCacheWritableMethod · 0.95
writeCacheMethod · 0.95
isCacheWritableMethod · 0.95
loadConfigMethod · 0.45

Calls 2

existsMethod · 0.80
deleteMethod · 0.45

Tested by

no test coverage detected