/** * Whether this class is able to read the given entry. * * <p>May return false if the current entry is a sparse file. */ public boolean canReadEntryData(ArchiveEntry ae) { if (ae instanceof TarArchiveEntry) { TarArchiveEntry te = (TarArchiveEntry) ae; return !te.isGNUSparse(); } return false; }
/** * Get the next entry in this tar archive. This will skip over any remaining data in the current * entry, if there is one, and place the input stream at the header of the next entry, and read * the header and instantiate a new TarEntry from the header bytes and return that entry. If there * are no more entries in the archive, null will be returned to indicate that the end of the * archive has been reached. * * @return The next TarEntry in the archive, or null. * @throws IOException on error */ public TarArchiveEntry getNextTarEntry() throws IOException { if (hasHitEOF) { return null; } if (currEntry != null) { long numToSkip = entrySize - entryOffset; while (numToSkip > 0) { long skipped = skip(numToSkip); if (skipped <= 0) { throw new RuntimeException("failed to skip current tar entry"); } numToSkip -= skipped; } readBuf = null; } byte[] headerBuf = getRecord(); if (hasHitEOF) { currEntry = null; return null; } currEntry = new TarArchiveEntry(headerBuf); entryOffset = 0; entrySize = currEntry.getSize(); if (currEntry.isGNULongNameEntry()) { // read in the name StringBuffer longName = new StringBuffer(); byte[] buf = new byte[SMALL_BUFFER_SIZE]; int length = 0; while ((length = read(buf)) >= 0) { longName.append(new String(buf, 0, length)); } getNextEntry(); if (currEntry == null) { // Bugzilla: 40334 // Malformed tar file - long entry name not followed by entry return null; } // remove trailing null terminator if (longName.length() > 0 && longName.charAt(longName.length() - 1) == 0) { longName.deleteCharAt(longName.length() - 1); } currEntry.setName(longName.toString()); } if (currEntry.isPaxHeader()) { // Process Pax headers paxHeaders(); } if (currEntry.isGNUSparse()) { // Process sparse files readGNUSparse(); } return currEntry; }