import cn.reghao.tnb.file.app.zdisk.model.vo.FileTree; import cn.reghao.tnb.oss.api.constant.ObjectType; import net.sourceforge.tess4j.Tesseract; import org.junit.jupiter.api.Test; import org.mockito.junit.MockitoJUnitRunner; import java.io.File; import java.io.IOException; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.TreeMap; import java.util.stream.Collectors; public class DiskUnitTest { void walkDir(Path path) throws IOException { Files.walkFileTree(path, new FileVisitor() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { File dir1 = dir.toFile(); process(dir1); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { File file1 = file.toFile(); process(file1); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); } List fileTreeList = new ArrayList<>(); private void process(File file) { String basePath = dir.getAbsolutePath(); String absolutePath = file.getAbsolutePath(); String path = absolutePath.replace(basePath, ""); String pid = file.getParent().replace(basePath, ""); if (path.equals("")) { pid = "0"; } else if (pid.equals("")) { pid = "/"; } int fileType = ObjectType.Image.getCode(); if (file.isDirectory()) { fileType = ObjectType.Dir.getCode(); } String fileId = absolutePath.replace(basePath, ""); FileTree fileTree = new FileTree(pid, fileId, fileType); fileTreeList.add(fileTree); } String baseDir = "/home/reghao/Downloads/"; File dir = new File(baseDir); Map> getTreeMap() throws IOException { Path path = Paths.get(dir.getAbsolutePath()); walkDir(path); Map> pidGroup = fileTreeList.stream() .collect(Collectors.groupingBy(FileTree::getPid)); return new TreeMap<>(pidGroup); } public void treeTest() throws Exception { /*Map> pidTreeMap = getTreeMap(); pidTreeMap.forEach((key, list) -> { String pid = key; for (FileTree fileTree : list) { String fileId = fileTree.getFileId(); } }); System.out.println("main-thread goto sleep...");*/ } @Test public void ocrTest() throws Exception { Tesseract tess = new Tesseract(); // 字库位置 tess.setDatapath("/home/reghao/Downloads/tess"); // 中英文混合 tess.setLanguage("eng+chi_sim"); //tess.setLanguage("chi_sim"); // tess.setLanguage("eng"); String imagePath = "/home/reghao/Downloads/1620438.png"; String result = tess.doOCR(new File(imagePath)); System.out.println(result); } }