From a11f6c631aae9d0cd4414deea3da910b0e1da022 Mon Sep 17 00:00:00 2001
From: ulrich
Date: Wed, 13 Nov 2024 16:53:54 +0000
Subject: [PATCH] Dokumentation in Arbeit
---
src/de/uhilger/fm/Eraser.java | 2 +-
src/de/uhilger/fm/Mover.java | 2 +-
src/de/uhilger/fm/FileOpsVisitor.java | 52 +++++++++++++++++++++++++++++++++++++++++++++++-----
3 files changed, 49 insertions(+), 7 deletions(-)
diff --git a/src/de/uhilger/fm/Eraser.java b/src/de/uhilger/fm/Eraser.java
index d42f12f..36a3a62 100644
--- a/src/de/uhilger/fm/Eraser.java
+++ b/src/de/uhilger/fm/Eraser.java
@@ -44,7 +44,7 @@
File targetFile = new File(targetDir, fileName);
//logger.fine(targetFile.getAbsolutePath());
if (targetFile.isDirectory()) {
- CopyMoveVisitor bearbeiter = new CopyMoveVisitor();
+ FileOpsVisitor bearbeiter = new FileOpsVisitor();
bearbeiter.setOperation(OP_DELETE);
Files.walkFileTree(targetFile.toPath(), bearbeiter);
} else {
diff --git a/src/de/uhilger/fm/CopyMoveVisitor.java b/src/de/uhilger/fm/FileOpsVisitor.java
similarity index 64%
rename from src/de/uhilger/fm/CopyMoveVisitor.java
rename to src/de/uhilger/fm/FileOpsVisitor.java
index 07fea91..d6dfcb9 100644
--- a/src/de/uhilger/fm/CopyMoveVisitor.java
+++ b/src/de/uhilger/fm/FileOpsVisitor.java
@@ -26,13 +26,13 @@
import java.nio.file.attribute.BasicFileAttributes;
/**
- * Ein FileVisitor zum Verschieben oder Kopieren ganzer Ordnerstrukturen mit
+ * Ein FileVisitor zum Verschieben, Kopieren oder Loeschen ganzer Ordnerstrukturen mit
* Hilfe der Methode Files.walkFileTree von java.nio.
*
* @author Ulrich Hilger
* @version 1, 14. Mai 2021
*/
-public class CopyMoveVisitor extends FileHelper implements FileVisitor {
+public class FileOpsVisitor extends FileHelper implements FileVisitor {
private Path targetDir;
private int operation;
@@ -61,13 +61,19 @@
* Ordner ueberschrieben wird, indem am Ziel fuer einen bereits existierenden Ordner ein
* anderer Name mit laufender Nummer erzeugt wird.
*
+ * Invoked for a directory before entries in the directory are visited. If this method
+ * returns CONTINUE, then entries in the directory are visited. If this method returns
+ * SKIP_SUBTREE or SKIP_SIBLINGS then entries in the directory (and any descendants)
+ * will not be visited.
+ *
* @param dir Zielordner
* @param attrs die gewuenschten Attribute
* @return gibt stets FileVisitResult.CONTINUE zurueck
* @throws IOException wenn etwas schief geht
*/
@Override
- public FileVisitResult preVisitDirectory(Object dir, BasicFileAttributes attrs) throws IOException {
+ public FileVisitResult preVisitDirectory(Object dir, BasicFileAttributes attrs)
+ throws IOException {
if (operation != Eraser.OP_DELETE) {
if (dir instanceof Path) {
Path sourceDir = (Path) dir;
@@ -85,6 +91,16 @@
return FileVisitResult.CONTINUE;
}
+ /**
+ * Fuer jede Datei die gewuenschte Dateioperation ausführen
+ *
+ * Invoked for a file in a directory.
+ *
+ * @param file die zu bearbeitende Datei a reference to the file
+ * @param attrs the directory's basic attributes
+ * @return stets FileVisitResult.CONTINUE
+ * @throws IOException wenn etwas schief geht
+ */
@Override
public FileVisitResult visitFile(Object file, BasicFileAttributes attrs) throws IOException {
if(operation != Eraser.OP_DELETE) {
@@ -95,10 +111,8 @@
destFile = getNewFileName(destFile);
}
if (operation == Mover.OP_MOVE) {
- //logger.fine("move source: " + source.toString() + ", destFile: " + destFile.getAbsolutePath());
Files.move(source, destFile.toPath());
} else if (operation == Mover.OP_COPY) {
- //logger.fine("copy source: " + source.toString() + ", destFile: " + destFile.getAbsolutePath());
Files.copy(source, destFile.toPath());
}
}
@@ -108,11 +122,39 @@
return FileVisitResult.CONTINUE;
}
+ /**
+ * Bei diesem Visitor bleibt diese Methode ungenutzt, hier muessten noch Faelle
+ * behandelt werden, die zu einem Abbruch fuehren und ggf. ein Rollback realisiert werden.
+ *
+ * Invoked for a file that could not be visited. This method is invoked if the file's attributes
+ * could not be read, the file is a directory that could not be opened, and other reasons.
+ *
+ * @param file die Datei, bei der es zum Abbruch kam
+ * @param exc the I/O exception that prevented the file from being visited
+ * @return stets FileVisitResult.CONTINUE
+ * @throws IOException wenn etwas schief laeuft
+ */
@Override
public FileVisitResult visitFileFailed(Object file, IOException exc) throws IOException {
return FileVisitResult.CONTINUE;
}
+ /**
+ * Fuer jede Datei Schritte ausfuehren, wie sie sich nach einer Dateioperation ergeben.
+ * Hier wird beim Verschieben von Dateien das Quellverzeichnis geloescht, nachdem es zum
+ * Ziel uebertragen wurde.
+ *
+ * Invoked for a directory after entries in the directory, and all of their descendants,
+ * have been visited. This method is also invoked when iteration of the directory completes
+ * prematurely (by a visitFile method returning SKIP_SIBLINGS, or an I/O error when
+ * iterating over the directory).
+ *
+ * @param dir der fertig durchlaufene Quellordner
+ * @param exc null if the iteration of the directory completes without an error; otherwise
+ * the I/O exception that caused the iteration of the directory to complete prematurely
+ * @return
+ * @throws IOException
+ */
@Override
public FileVisitResult postVisitDirectory(Object dir, IOException exc) throws IOException {
if (operation != Eraser.OP_DELETE) {
diff --git a/src/de/uhilger/fm/Mover.java b/src/de/uhilger/fm/Mover.java
index 66986aa..e3adce5 100644
--- a/src/de/uhilger/fm/Mover.java
+++ b/src/de/uhilger/fm/Mover.java
@@ -59,7 +59,7 @@
//logger.fine("srcFile: " + srcFile);
if (srcFile.isDirectory()) {
//logger.fine("srcFile is directory.");
- CopyMoveVisitor bearbeiter = new CopyMoveVisitor();
+ FileOpsVisitor bearbeiter = new FileOpsVisitor();
bearbeiter.setTargetDir(targetDir.toPath());
bearbeiter.setOperation(operation);
Files.walkFileTree(srcFile.toPath(), bearbeiter);
--
Gitblit v1.9.3