|
@@ -0,0 +1,63 @@
|
|
|
+package com.hw.admin.system.listener;
|
|
|
+
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.io.monitor.FileAlterationListener;
|
|
|
+import org.apache.commons.io.monitor.FileAlterationObserver;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class FileListener implements FileAlterationListener {
|
|
|
+ @Override
|
|
|
+ public void onStart(FileAlterationObserver fileAlterationObserver) {
|
|
|
+ File directory = fileAlterationObserver.getDirectory();
|
|
|
+ log.info("开始监听..." + directory);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDirectoryCreate(File file) {
|
|
|
+ String name = file.getName();
|
|
|
+ log.info("目录被创建了..." + name);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDirectoryChange(File file) {
|
|
|
+ String name = file.getName();
|
|
|
+ log.info("目录被修改了..." + name);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDirectoryDelete(File file) {
|
|
|
+ String name = file.getName();
|
|
|
+ log.info("目录被删除了..." + name);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFileCreate(File file) {
|
|
|
+ String name = file.getName();
|
|
|
+ String path = file.getPath();
|
|
|
+ log.info("文件被创建了..." + name);
|
|
|
+ log.info("文件是..." + path);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFileChange(File file) {
|
|
|
+ String name = file.getName();
|
|
|
+ log.info("文件被修改了..." + name);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFileDelete(File file) {
|
|
|
+ String name = file.getName();
|
|
|
+ log.info("文件被删除了..." + name);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onStop(FileAlterationObserver fileAlterationObserver) {
|
|
|
+ File file = fileAlterationObserver.getDirectory();
|
|
|
+ String name = file.getName();
|
|
|
+ log.info("结束监听..." + name);
|
|
|
+ }
|
|
|
+}
|