public static long calculateFileSizeInPath(File path) {
        long size = 0;
        try {
            if (!path.exists() || Files.isSymbolicLink(path.toPath())) {
                return 0;
            }
            if (path.isFile()) {
                return path.length();
            }
            if (path.isDirectory()) {
                File[] files = path.listFiles();
                if (files != null && files.length > 0) {
                    for (File file : files) {
                        long fileSize = calculateFileSizeInPath(file);
                        if (fileSize == -1) return -1;
                        size += fileSize;
                    }
                }
            }
        } catch (Exception e) {
            log.error("calculate all file size in: {} error", path.getAbsolutePath(), e);
            return -1;
        }
        return size;
    }
@Test
    public void testCalculateFileSizeInPath() throws Exception {
        /**
         * testCalculateFileSizeInPath
         *  - file_0
         *  - dir_1
         *      - file_1_0
         *      - file_1_1
         *      - dir_1_2
         *          - file_1_2_0
         *  - dir_2
         */
        File baseFile = tempDir.getRoot();

        // test empty path
        assertEquals(0, UtilAll.calculateFileSizeInPath(baseFile));

        File file0 = new File(baseFile, "file_0");
        assertTrue(file0.createNewFile());
        writeFixedBytesToFile(file0, 1313);

        assertEquals(1313, UtilAll.calculateFileSizeInPath(baseFile));

        // build a file tree like above
        File dir1 = new File(baseFile, "dir_1");
        dir1.mkdirs();
        File file10 = new File(dir1, "file_1_0");
        File file11 = new File(dir1, "file_1_1");
        File dir12 = new File(dir1, "dir_1_2");
        dir12.mkdirs();
        File file120 = new File(dir12, "file_1_2_0");
        File dir2 = new File(baseFile, "dir_2");
        dir2.mkdirs();

        // write all file with 1313 bytes data
        assertTrue(file10.createNewFile());
        writeFixedBytesToFile(file10, 1313);
        assertTrue(file11.createNewFile());
        writeFixedBytesToFile(file11, 1313);
        assertTrue(file120.createNewFile());
        writeFixedBytesToFile(file120, 1313);

        assertEquals(1313 * 4, UtilAll.calculateFileSizeInPath(baseFile));
    }