Update logging calls in FileAccess
This commit is contained in:
parent
f7c130d66e
commit
a7c02cc9c2
1 changed files with 30 additions and 28 deletions
|
@ -250,14 +250,14 @@ public final class FileAccess {
|
|||
|
||||
for (Path path : scheduledDeletion)
|
||||
try (Stream<Path> stream = Files.walk(path)) {
|
||||
Logger.diag("Deleting file or directory \"" + path + "\"");
|
||||
Logger.diag("Deleting file or directory '" + path + "'");
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
stream.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
|
||||
|
||||
if (Files.exists(path))
|
||||
Logger.error("Deleting file or directory \"" + path + "\" failed");
|
||||
Logger.error("Deleting file or directory '" + path + "' failed");
|
||||
} catch (Exception exception) {
|
||||
Logger.error("File or directory \"" + path + "\" could not be deleted\n" + Miscellaneous.throwableHeader(exception) + "\n" + Miscellaneous.stacktraceAsString(exception, true));
|
||||
Logger.error("File or directory '" + path + "' could not be deleted\n" + Miscellaneous.throwableHeader(exception) + "\n" + Miscellaneous.stacktraceAsString(exception, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -406,18 +406,18 @@ public final class FileAccess {
|
|||
* directories in this directory.
|
||||
*
|
||||
* @return array of file and directory names
|
||||
* @throws UnsupportedOperationException if the file is not a directory
|
||||
* @throws IOException on an IO error
|
||||
* @throws UnsupportedOperationException if this file isn't a directory
|
||||
* @throws IOException on an IO error
|
||||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull String @NotNull [] listContents() throws UnsupportedOperationException, IOException {
|
||||
if (getType() != Type.DIRECTORY)
|
||||
throw new UnsupportedOperationException("The file \"" + path + "\" is not a directory");
|
||||
throw new UnsupportedOperationException("The file '" + path + "' is not a directory");
|
||||
|
||||
String[] list = file.list();
|
||||
|
||||
if (list == null)
|
||||
throw new IOException("list is null");
|
||||
throw new IOException("list is null (isn't a directory although it should be one)");
|
||||
else
|
||||
return list;
|
||||
}
|
||||
|
@ -432,7 +432,7 @@ public final class FileAccess {
|
|||
*/
|
||||
public @NotNull String getLinkDestination() throws IOException {
|
||||
if (!isSymbolicLink())
|
||||
throw new UnsupportedOperationException("The file \"" + path + "\" is not a symbolic link");
|
||||
throw new UnsupportedOperationException("The file '" + path + "' is not a symbolic link");
|
||||
return unformatPath(Files.readSymbolicLink(path));
|
||||
}
|
||||
|
||||
|
@ -516,10 +516,10 @@ public final class FileAccess {
|
|||
throw new IllegalArgumentException("Invalid permission format: " + permissions);
|
||||
|
||||
try {
|
||||
Logger.diag("Setting POSIX file permissions for \"" + path + "\" to '" + permissions + "'");
|
||||
Logger.diag("Setting POSIX file permissions for '" + path + "' to '" + permissions + "'");
|
||||
Files.setPosixFilePermissions(path, PosixFilePermissions.fromString(permissions));
|
||||
} catch (UnsupportedOperationException exception) {
|
||||
Logger.diag("Setting POSIX file permissions for \"" + path + "\" to '" + permissions.substring(0, 2) + "'");
|
||||
Logger.diag("Setting POSIX file permissions for '" + path + "' to '" + permissions.substring(0, 2) + "'");
|
||||
char @NotNull [] chars = permissions.toCharArray();
|
||||
|
||||
for (int permission = 0; permission < 3; permission++) {
|
||||
|
@ -622,7 +622,7 @@ public final class FileAccess {
|
|||
Path pathResolved = this.path.resolve(formatPath(path));
|
||||
|
||||
if (!Files.exists(pathResolved))
|
||||
throw new FileNotFoundException("Traversal failed as relative path \"" + path + "\" does not exist from absolute path \"" + path + "\"");
|
||||
throw new FileNotFoundException("Traversal failed as relative path '" + path + "' does not exist from absolute path '" + path + "'");
|
||||
|
||||
return new FileAccess(pathResolved);
|
||||
}
|
||||
|
@ -640,7 +640,7 @@ public final class FileAccess {
|
|||
@SuppressWarnings({"UnusedReturnValue", "ResultOfMethodCallIgnored"})
|
||||
public @NotNull FileAccess createFile() throws IOException {
|
||||
if (!exists()) {
|
||||
Logger.diag("Creating a file at \"" + path + "\"");
|
||||
Logger.diag("Creating a file at '" + path + "'");
|
||||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
}
|
||||
|
@ -658,9 +658,9 @@ public final class FileAccess {
|
|||
*/
|
||||
public @NotNull FileAccess createDirectory() throws IOException {
|
||||
if (!exists()) {
|
||||
Logger.diag("Creating a directory at \"" + path + "\"");
|
||||
Logger.diag("Creating a directory at '" + path + "'");
|
||||
if (!file.mkdirs())
|
||||
throw new IOException("Creating directory \"" + path + "\" recursively failed");
|
||||
throw new IOException("Creating directory '" + path + "' recursively failed");
|
||||
}
|
||||
|
||||
return this;
|
||||
|
@ -679,7 +679,7 @@ public final class FileAccess {
|
|||
@SuppressWarnings("UnusedReturnValue")
|
||||
public @NotNull FileAccess createLink(boolean hard, @NotNull String destination) throws IOException {
|
||||
if (!exists()) {
|
||||
Logger.diag("Creating a " + (hard ? "hard" : "symbolic") + " link at \"" + path + "\"");
|
||||
Logger.diag("Creating a " + (hard ? "hard" : "symbolic") + " link at '" + path + "'");
|
||||
|
||||
if (hard)
|
||||
Files.createLink(path, formatPath(destination));
|
||||
|
@ -725,7 +725,7 @@ public final class FileAccess {
|
|||
*/
|
||||
public @NotNull FileAccess delete() {
|
||||
if (exists()) {
|
||||
Logger.diag("Deleting \"" + path + "\"");
|
||||
Logger.diag("Deleting '" + path + "'");
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.delete();
|
||||
}
|
||||
|
@ -741,7 +741,7 @@ public final class FileAccess {
|
|||
* @since v1-alpha8
|
||||
*/
|
||||
public @NotNull FileAccess deleteOnShutdown() {
|
||||
Logger.diag("Marking \"" + path + "\" for deletion at engine shutdown");
|
||||
Logger.diag("Marking '" + path + "' for deletion at engine shutdown");
|
||||
|
||||
// Append path to scheduledDeletion array
|
||||
List<@NotNull Path> scheduledDeletionList = new ArrayList<>(Arrays.stream(scheduledDeletion).toList());
|
||||
|
@ -800,7 +800,7 @@ public final class FileAccess {
|
|||
if (getType() != Type.FILE)
|
||||
return new byte[0];
|
||||
|
||||
Logger.diag("Reading file \"" + path + "\" (bytes)");
|
||||
Logger.diag("Reading file '" + path + "' (bytes)");
|
||||
return Files.readAllBytes(path);
|
||||
}
|
||||
|
||||
|
@ -819,7 +819,7 @@ public final class FileAccess {
|
|||
if (getType() != Type.FILE)
|
||||
return new ArrayList<>();
|
||||
|
||||
Logger.diag("Reading file \"" + path + "\" (lines)");
|
||||
Logger.diag("Reading file '" + path + "' (lines)");
|
||||
return Files.readAllLines(path);
|
||||
}
|
||||
|
||||
|
@ -856,7 +856,7 @@ public final class FileAccess {
|
|||
if (getType() != Type.FILE)
|
||||
return "";
|
||||
|
||||
Logger.diag("Reading file \"" + path + "\" (string)");
|
||||
Logger.diag("Reading file '" + path + "' (string)");
|
||||
return Files.readString(path, charset);
|
||||
}
|
||||
|
||||
|
@ -875,10 +875,10 @@ public final class FileAccess {
|
|||
if (getType() == Type.VOID)
|
||||
createFile();
|
||||
else if (getType() != Type.FILE)
|
||||
throw new UnsupportedOperationException("File \"" + path + "\" is not of type Type.VOID or Type.FILE");
|
||||
throw new UnsupportedOperationException("File '" + path + "' is not of type Type.VOID or Type.FILE");
|
||||
|
||||
createFile();
|
||||
Logger.diag("Writing file \"" + path + "\" (bytes, " + (async ? "async" : "dsync") + ")");
|
||||
Logger.diag("Writing file '" + path + "' (bytes, " + (async ? "async" : "dsync") + ")");
|
||||
Files.write(path, bytes, StandardOpenOption.WRITE, async ? StandardOpenOption.DSYNC : StandardOpenOption.SYNC);
|
||||
return this;
|
||||
}
|
||||
|
@ -912,9 +912,9 @@ public final class FileAccess {
|
|||
if (getType() == Type.VOID)
|
||||
createFile();
|
||||
else if (getType() != Type.FILE)
|
||||
throw new UnsupportedOperationException("File \"" + path + "\" is not of type Type.VOID or Type.FILE");
|
||||
throw new UnsupportedOperationException("File '" + path + "' is not of type Type.VOID or Type.FILE");
|
||||
|
||||
Logger.diag("Writing file \"" + path + "\" (string, " + (async ? "async" : "dsync") + ")");
|
||||
Logger.diag("Writing file '" + path + "' (string, " + (async ? "async" : "dsync") + ")");
|
||||
Files.writeString(path, string, charset, StandardOpenOption.WRITE, async ? StandardOpenOption.DSYNC : StandardOpenOption.SYNC);
|
||||
return this;
|
||||
}
|
||||
|
@ -934,9 +934,9 @@ public final class FileAccess {
|
|||
if (getType() == Type.VOID)
|
||||
createFile();
|
||||
else if (getType() != Type.FILE)
|
||||
throw new UnsupportedOperationException("File \"" + path + "\" is not of type Type.VOID or Type.FILE");
|
||||
throw new UnsupportedOperationException("File '" + path + "' is not of type Type.VOID or Type.FILE");
|
||||
|
||||
Logger.diag("Appending file \"" + path + "\" (bytes, " + (async ? "async" : "dsync") + ")");
|
||||
Logger.diag("Appending file '" + path + "' (bytes, " + (async ? "async" : "dsync") + ")");
|
||||
Files.write(path, bytes, StandardOpenOption.APPEND, async ? StandardOpenOption.DSYNC : StandardOpenOption.SYNC);
|
||||
return this;
|
||||
}
|
||||
|
@ -970,13 +970,15 @@ public final class FileAccess {
|
|||
if (getType() == Type.VOID)
|
||||
createFile();
|
||||
else if (getType() != Type.FILE)
|
||||
throw new UnsupportedOperationException("File \"" + path + "\" is not of type Type.VOID or Type.FILE");
|
||||
throw new UnsupportedOperationException("File '" + path + "' is not of type Type.VOID or Type.FILE");
|
||||
|
||||
Logger.diag("Appending file \"" + path + "\" (string, " + (async ? "async" : "dsync") + ")");
|
||||
Logger.diag("Appending file '" + path + "' (string, " + (async ? "async" : "dsync") + ")");
|
||||
Files.writeString(path, string, charset, StandardOpenOption.APPEND, async ? StandardOpenOption.DSYNC : StandardOpenOption.SYNC);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
// -----> Inner classes
|
||||
/**
|
||||
* Represents various file types.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue