zoukankan      html  css  js  c++  java
  • 下载文件的一致性验证之MD5值校验

    前几天写脚本遇到下载功能校验,一时间不到怎么校验好?

    于是请教大神,大神给出方案如下:

     先去了解一下你们的产品针对这个下载功能有没有做什么功能设计。。。然后再针对这些功能设计去设计测试用例。。。比如断点续传有没有,有没有压缩,有没有加密,下载过程中对不同网速有没有控制。。。如果什么功能都没有,那么测试用例就可以简单一点。。。如果有特殊功能,那么就复杂一点
    我验证的是上传到服务器的文件和从服务器下载下来的文件是否一致,结果就用了这个md5值得校验,解决了问题
    代码如下:
    /**
         * 获取文件的MD5值
         *
         * @param filePath
         * @throws Exception
         */
        public String getMd5(String filePath) throws Exception {
            File file1 = new File(filePath);
            FileInputStream fis = new FileInputStream(file1);
            String md5 = DigestUtils.md5Hex(IOUtils.toByteArray(fis));
            IOUtils.closeQuietly(fis);
            logger.info("p2_MD5:" + md5);
            return md5;
        }
    
        /**
         * 文件MD5值校验是否一致
         *
         * @param filePath1
         * @param filePath2
         * @return
         * @throws Exception
         */
        public Boolean compareFile(String filePath1, String filePath2) throws Exception {
            //获取第一个文件的MD5值
            String p1_md5 = getMd5(filePath1);
            //获取第二个文件的MD5值
            String p2_md5 = getMd5(filePath1);
            if (p2_md5.equals(p1_md5)) {
                return true;
            } else {
                return false;
            }
        }
  • 相关阅读:
    Leetcode Spiral Matrix
    Leetcode Sqrt(x)
    Leetcode Pow(x,n)
    Leetcode Rotate Image
    Leetcode Multiply Strings
    Leetcode Length of Last Word
    Topcoder SRM 626 DIV2 SumOfPower
    Topcoder SRM 626 DIV2 FixedDiceGameDiv2
    Leetcode Largest Rectangle in Histogram
    Leetcode Set Matrix Zeroes
  • 原文地址:https://www.cnblogs.com/longronglang/p/8308958.html
Copyright © 2011-2022 走看看