-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7872a56
Showing
14 changed files
with
922 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# 项目排除路径 | ||
/out/ | ||
/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.example</groupId> | ||
<artifactId>filescan</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>cn.hutool</groupId> | ||
<artifactId>hutool-core</artifactId> | ||
<version>5.7.9</version> | ||
</dependency> | ||
|
||
<!--POI--> | ||
<!--<dependency> | ||
<groupId>cn.hutool</groupId> | ||
<artifactId>hutool-poi</artifactId> | ||
<version>5.7.9</version> | ||
</dependency>--> | ||
<dependency> | ||
<groupId>org.apache.poi</groupId> | ||
<artifactId>poi-ooxml</artifactId> | ||
<version>4.1.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.poi</groupId> | ||
<artifactId>poi-scratchpad</artifactId> | ||
<version>4.1.2</version> | ||
</dependency> | ||
|
||
<!--PDF--> | ||
<dependency> | ||
<groupId>org.apache.pdfbox</groupId> | ||
<artifactId>pdfbox</artifactId> | ||
<version>2.0.24</version> | ||
</dependency> | ||
|
||
|
||
<!--<dependency> | ||
<groupId>cn.hutool</groupId> | ||
<artifactId>hutool-dfa</artifactId> | ||
<version>5.7.9</version> | ||
</dependency>--> | ||
|
||
<!--LOG--> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>1.2.5</version> | ||
</dependency> | ||
|
||
<!--TEST--> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>5.7.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
|
||
<build> | ||
<defaultGoal>clean package</defaultGoal> | ||
<plugins> | ||
<!-- java编译插件 --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<addClasspath>true</addClasspath> | ||
<classpathPrefix>lib/</classpathPrefix> | ||
<mainClass>cnpat/filescan/Program.java</mainClass> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>copy</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>copy-dependencies</goal> | ||
</goals> | ||
<configuration> | ||
<outputDirectory>${project.build.directory}/lib</outputDirectory> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package cnpat.filescan; | ||
|
||
public class CheckResult { | ||
public static Integer Ignore=5; | ||
public static Integer Info=10; | ||
public static Integer Warn = 20; | ||
public static Integer Error = 30; | ||
public static Integer Unmacth = 0; | ||
public static String CheckPointZhongYang="中央文件"; | ||
public static String CheckPointSecret="国家秘密"; | ||
public static String CheckContentFileName="文件名称"; | ||
public static String CheckContentFileContent="文件内容"; | ||
/** | ||
* 匹配结果,匹配成功>0, 越重要值越大 | ||
*/ | ||
private Integer result; | ||
/** | ||
* 检查点:中共中央文件 or 国家秘密 | ||
*/ | ||
private String checkPoint; | ||
/** | ||
* 匹配的内容 | ||
*/ | ||
private String checkMessage; | ||
/** | ||
* 检查的内容:文件名 or 文件内容 | ||
*/ | ||
private String checkContent; | ||
|
||
public Integer getResult() { | ||
return result; | ||
} | ||
public void setResult(Integer result) { | ||
this.result = result; | ||
} | ||
public String getCheckPoint() { | ||
return checkPoint; | ||
} | ||
public void setCheckPoint(String checkPoint) { | ||
this.checkPoint = checkPoint; | ||
} | ||
public String getCheckMessage() { | ||
return checkMessage; | ||
} | ||
public void setCheckMessage(String checkMessage) { | ||
this.checkMessage = checkMessage; | ||
} | ||
public String getCheckContent() { | ||
return checkContent; | ||
} | ||
public void setCheckContent(String checkContent) { | ||
this.checkContent = checkContent; | ||
} | ||
|
||
public CheckResult() { | ||
} | ||
|
||
public CheckResult(Integer result) { | ||
this.result = result; | ||
} | ||
|
||
public CheckResult(Integer result, String checkPoint, String checkMessage, String checkContent) { | ||
this.result = result; | ||
this.checkPoint = checkPoint; | ||
this.checkMessage = checkMessage; | ||
this.checkContent = checkContent; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CheckResult [result=" + result + ", checkPoint=" + checkPoint | ||
+ ", checkContent=" + checkContent + "]" + ", checkMessage=" + checkMessage; | ||
} | ||
|
||
public boolean isRisk() { | ||
Integer result = getResult(); | ||
return result != null && result > 1; | ||
} | ||
|
||
public static final CheckResult PASS = new CheckResult(0); | ||
public static final CheckResult IGNORE = new CheckResult(Ignore,CheckPointSecret,CheckContentFileContent,"null"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package cnpat.filescan; | ||
|
||
import cn.hutool.core.io.FileUtil; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.swing.filechooser.FileSystemView; | ||
import java.io.File; | ||
import java.io.FileFilter; | ||
import java.io.IOException; | ||
import java.nio.file.*; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class DiskWalker { | ||
|
||
final Logger log = LoggerFactory.getLogger(this.getClass()); | ||
|
||
/** | ||
* 磁盘类型 | ||
* http://www.cfan.com.cn/2021/0608/135249.shtml | ||
*/ | ||
private final static List<String> whiteType = Collections.singletonList("本地磁盘"); | ||
|
||
public List<File> walkPath(File path) { | ||
return loopFiles(path.toPath(), -1, null); | ||
} | ||
|
||
public List<File> getRoots() { | ||
File[] roots = File.listRoots(); | ||
FileSystemView sys = FileSystemView.getFileSystemView(); | ||
return Arrays.stream(roots) | ||
// .peek(f -> System.out.println(sys.getSystemTypeDescription(f))) | ||
.filter(f -> whiteType.contains(sys.getSystemTypeDescription(f))) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public List<File> loopFiles(Path path, int maxDepth, FileFilter fileFilter) { | ||
final List<File> fileList = new ArrayList<>(); | ||
if (null == path || !Files.exists(path)) { | ||
return fileList; | ||
} else if (!FileUtil.isDirectory(path)) { | ||
final File file = path.toFile(); | ||
if (null == fileFilter || fileFilter.accept(file)) { | ||
fileList.add(file); | ||
} | ||
return fileList; | ||
} | ||
FileUtil.walkFiles(path, maxDepth, new SimpleFileVisitor<Path>() { | ||
@Override | ||
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) { | ||
final File file = path.toFile(); | ||
if (null == fileFilter || fileFilter.accept(file)) { | ||
fileList.add(file); | ||
} | ||
return FileVisitResult.CONTINUE; | ||
} | ||
@Override | ||
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { | ||
try { | ||
return super.visitFileFailed(file, exc); | ||
} catch (AccessDeniedException ade) { | ||
log.error("Unable to access files in:" + file); | ||
return FileVisitResult.CONTINUE; | ||
} | ||
} | ||
}); | ||
return fileList; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.