简体   繁体   English

用Java下载和存储带有校验和信息的文件

[英]Downloading and storing files with checksum information in Java

We are building a service to front fetching remote static files to our android app. 我们正在构建一项服务,以将远程静态文件前端获取到我们的android应用。 The service will give a readout of the current md5 checksum of a file. 该服务将读取文件的当前md5校验和。 The concept is that we retain the static file on the device until the checksum changes. 概念是我们将静态文件保留在设备上,直到校验和更改为止。 When the file changes, the service will return a different checksum and this is the trigger for the device to download the file again. 文件更改时,服务将返回不同的校验和,这是设备再次下载文件的触发器。

I was thinking of just laying the downloaded files down in the file system with a .md5 file next to each one. 我当时想只是将下载的文件放到文件系统中,每个文件旁边都有一个.md5文件。 When the code starts up, I'd go over all the files and make a map of file_name (known to be unique) to checksum. 代码启动时,我将遍历所有文件,并为filesum_name(已知是唯一的)创建一个映射到校验和。 Then on requests for a file I'd check the remote service (whose response would only be checked every few minutes) and compare the result against that in the map. 然后,在请求文件时,我将检查远程服务(其响应仅每隔几分钟检查一次),并将结果与​​地图中的结果进行比较。

The more I thought about this, the more I thought someone must have already done it. 我对这一点的思考越多,我就越认为某人一定已经做到了。 So before I put time into this I was wondering if there was a project out there doing this. 因此,在我花时间讨论之前,我想知道是否有一个项目在执行此操作。 I did some searching but could not find any. 我进行了一些搜索,但找不到任何内容。

Yes, it's built into HTTP. 是的,它内置在HTTP中。 You can use conditional requests and cache files based on ETags, Last-Modified, etc. If you are looking for a library that implements your particular caching scheme, it's a bit unlikely that one exists. 您可以使用基于ETag的条件请求和缓存文件,最后修改等,如果你正在寻找一个实现您的特定缓存方案库,这是一个有点不太可能,一个存在。 Write one and share it on GitHub :) 写一个并在GitHub上分享:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM