How to extract a single file from a remote archive file?

前端 未结 4 1369
广开言路
广开言路 2020-12-05 20:29

Given

  1. URL of an archive (e.g. a zip file)
  2. Full name (including path) of a file inside that archive

I\'m looking for a way (preferably i

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 20:49

    Contrary to the other answers here, I'd like to point out that ZIP entries are compressed individually, so (in theory) you don't need to download anything more than the directory and the entry itself. The server would need to support the Range HTTP header for this to work.

    The standard Java API only supports reading ZIP files from local files and input streams. As far as I know there's no provision for reading from random access remote files.

    Since you're using TrueZip, I recommend implementing de.schlichtherle.io.rof.ReadOnlyFile using Apache HTTP Client and creating a de.schlichtherle.util.zip.ZipFile with that.

    This won't provide any advantage for compressed TAR archives since the entire archive is compressed together (beyond just using an InputStream and killing it when you have your entry).

提交回复
热议问题