I have researched this issue for quite some time on google and stackoverflow. Unfortunately, I can't seem to find any resources that seem to address this issue. Admittedly, my search-fu isn't the best; any help, examples, or pointers to relevant resources will be very much appreciated.

The following code is my method for listing the archive contents from a TarArchiveInputStream:

public static List<String> tarListDir(InputStream incoming) 
    throws Exception {
    TarArchiveInputStream tarInput = new TarArchiveInputStream(incoming);
    TarArchiveEntry entry = null;
    List<String> ouah = new ArrayList<String>();

    try {
        while ((entry = tarInput.getNextTarEntry()) != null) {
            if (!entry.isFile()) {
                continue;
            }

            ouah.add(entry.getName());

            if (RecScan.verbose || RecScan.debugging) {
                if (entry.isFile()) {
                    System.out.print("file: \t");
                } else if (entry.isDirectory()) {
                    System.out.print("dir: \t");
                } else {
                    System.out.print("wut: \t");
                }

                System.out.println(ouah.get(ouah.size() - 1));
            }

        }
    } catch (Exception e) {
        tarInput.close();
        throw new Exception("Closed w/exception: " + e.getMessage());
    }

    if (RecScan.verbose || RecScan.debugging) {
        System.out.println("Closing tarInput normally");
    }
    tarInput.close();

    return ouah;
}

As mentioned above, I am hoping to obtain the List of entries in the archive. Unfortunately, it appears that the method is only obtaining a random amount of directory entries. This number varies, per-archive (testing with 4 different ones), from 0 entries to 12 entries. The exception that is being thrown is an IOException, Stream Closed to be specific.

I'm not very well versed in the Apache Commons Compress libraries (obviously), and I don't really know any hex editors well enough to dig around in the archive to see if there's something non-POSIX that it's stumbling over. I would think that the entry.isFile() conditional would avoid that complication, though.

As I mentioned, any help or resources greatly appreciated! TIA!

EDIT: Though the code there (in the first comment's post reference) seemed to boil down basically to the same as what I was using, I did actually cut out my code and use what was there, virtually verbatim. Still got the exact same error: Stream Closed. I did manage to find something that may hold a clue; I tried swapping out the BufferedInputStream wrapping of the original InputStream that I handed off. This caused the Stream Closed error immediately, vs. the BufferedInputStream closing after a bit of the archive listing. Definitely still looking for hints.

0

There are 0 best solutions below