Class TarFile

  • All Implemented Interfaces:
    ArchiveFile
    Direct Known Subclasses:
    BZip2TarFile, GZipTarFile, SnappyTarFile, XZTarFile, ZstdTarFile

    public class TarFile
    extends Object
    implements ArchiveFile

    Implementation of ArchiveFile for tar files.

    Compared to ZipFile, this one should be used with some care, due to the nature of a tar file: While a zip file contains a catalog, a tar file does not. In other words, the only way to read a tar file in a performant manner is by iterating over it from the beginning to the end. If you try to open another entry than the "next" entry, then you force to skip entries, until the requested entry is found. This may require to reread the entire file!

    In other words, the recommended use of this class is to use getEntries() and invoke getInputStream(TarArchiveEntry) only for the current entry. Basically, this is to handle it like TarArchiveInputStream.

    The advantage of this class is that you may write code for the ArchiveFile, which is valid for both tar files and zip files.