* ArchiveReader

better logging of caught/recovery-attempted IOException
* GZIPMemberInputStream
    handling of previously-unrecognized case in pre-JDK6u23: attempt at read() exhausts inflater with no new bytes available (previous nonzero-length read had not indicated inflater finished)
This commit is contained in:
gojomo
2011-02-24 19:22:50 +00:00
parent bb07080e02
commit 9fef4f1f26
2 changed files with 25 additions and 4 deletions
@@ -460,9 +460,9 @@ public abstract class ArchiveReader implements ArchiveFileConstants, Iterable<Ar
}
// If not strict, try going again. We might be able to skip
// over the bad record.
logger.warning("Trying skip of failed record cleanup of " +
logger.log(Level.WARNING,"Trying skip of failed record cleanup of " +
currentRecord.getHeader().toString() + ": " +
e.getMessage());
e.getMessage(), e);
}
return innerHasNext();
}
@@ -22,6 +22,7 @@ import java.io.InputStream;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.zip.GZIPInputStream;
import java.util.zip.Inflater;
import com.google.common.io.CountingInputStream;
@@ -96,12 +97,13 @@ public class GZIPMembersInputStream extends GZIPInputStream {
@Override
public int read(byte[] buf, int off, int len) throws IOException {
if (inf.finished()) {
// note read past member boundary
boolean wasFinishedOnEntry = inf.finished();
if (wasFinishedOnEntry) {
if(memberNumber>=holdAtMemberNumber) {
// only advance if allowed
return -1;
}
// note read past member boundary
memberNumber++;
currentMemberStart = currentMemberEnd;
currentMemberEnd = -1;
@@ -113,6 +115,12 @@ public class GZIPMembersInputStream extends GZIPInputStream {
// this read has exactly completed an underlying member
currentMemberEnd = ((CountingInputStream)in).getCount()-(inf.getRemaining()-8);
}
if(inf.finished() && !wasFinishedOnEntry && currentMemberEnd<0) {
// a previous nonzero read truly finished the member, without reporting so
// so now return a zero-read, with member-complete indicator
currentMemberEnd = ((CountingInputStream)in).getCount()-(inf.getRemaining()-8);
return 0;
}
int n = inf.getRemaining();
if(n==0) {
// no need to retain previous mark; won't need to backup for next member
@@ -122,8 +130,12 @@ public class GZIPMembersInputStream extends GZIPInputStream {
// WORKAROUND FOR JDK6u22 and earlier, when GzipOutputStream
// gave persistent EOF after first member. Forward past the
// boundary, enabling continuing reading.
// long at1 = ((CountingInputStream)in).getCount();
in.reset();
// long at2 = ((CountingInputStream)in).getCount();
in.skip(currentMemberStart-((CountingInputStream)in).getCount());
// long at3 = ((CountingInputStream)in).getCount();
// System.out.println(at1+","+at2+","+at3+":"+retVal);
startNewMember();
return this.read(buf, off, len);
}
@@ -240,6 +252,15 @@ public class GZIPMembersInputStream extends GZIPInputStream {
holdAtMemberNumber++;
}
}
/**
* Helpful for testing/debugging
*
* @return Inflater
*/
public Inflater getInflater() {
return inf;
}
/**
* Get an Iterator-ish interface to each member in turn. Has the effect of