Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于计算本地文件的CRC64 #63

Closed
lalinking opened this issue May 14, 2020 · 2 comments
Closed

关于计算本地文件的CRC64 #63

lalinking opened this issue May 14, 2020 · 2 comments

Comments

@lalinking
Copy link

lalinking commented May 14, 2020

再次打扰:

  1. 使用sdk内置的CRC64类计算出来的值始终不对,请问是不是我哪个地方有错?
  2. 对于crc64功能上线以前的文件不能返回crc64值”,我在官网没看到这个功能是什么时候上线的,方便在这告知一下这个时间点吗?我们公司用cos已经蛮多年了,需要确认一下这个上线时间。
   public static String getCRC64FromFile(File file) throws IOException {
        final CRC64 total = new CRC64();
        try (FileInputStream stream = new FileInputStream(file)) {
            final byte[] b = new byte[1024 * 1024];
            while (true) {
                final int read = stream.read(b);
                if (read <= 0) {
                    break;
                }
                total.update(b, read);
            }
        }
        return String.valueOf(total.getValue());
    }
@lalinking
Copy link
Author

今天又验证了一下,用5M的文件计算得到正确值,用10M的就是错误值,得到一个负数。
应该是哪个变量超出范围了吧

@lalinking
Copy link
Author

已经解决,不能String.valueOf。
java8 中用 Long.toUnsignedString

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant