@@ -53,7 +53,7 @@ public WARCResource(MetaData metaData, ResourceContainer container,
53
53
countingIS = new CountingInputStream (
54
54
ByteStreams .limit (response , length ));
55
55
} else {
56
- throw new ResourceParseException (null );
56
+ throw new ResourceParseException (new Exception ( "Zero or negative length: " + length ) );
57
57
}
58
58
try {
59
59
digIS = new DigestInputStream (countingIS ,
@@ -63,14 +63,18 @@ public WARCResource(MetaData metaData, ResourceContainer container,
63
63
}
64
64
}
65
65
66
+ @ Override
66
67
public InputStream getInputStream () {
67
68
return new EOFNotifyingInputStream (digIS , this );
68
69
}
69
70
71
+ @ Override
70
72
public void notifyEOF () throws IOException {
71
73
String digString = Base32 .encode (digIS .getMessageDigest ().digest ());
72
74
if (container .isCompressed ()) {
73
- metaData .putLong (PAYLOAD_LENGTH , countingIS .getCount ());
75
+ if (!metaData .has (PAYLOAD_LENGTH ) || countingIS .getCount () != metaData .getLong (PAYLOAD_LENGTH )) {
76
+ metaData .putLong (PAYLOAD_LENGTH , countingIS .getCount ());
77
+ }
74
78
metaData .putLong (PAYLOAD_SLOP_BYTES , StreamCopy .readToEOF (response ));
75
79
metaData .putString (PAYLOAD_DIGEST , "sha1:" +digString );
76
80
} else {
@@ -81,13 +85,17 @@ public void notifyEOF() throws IOException {
81
85
(PushBackOneByteInputStream ) raw ;
82
86
long numNewlines = StreamCopy .skipChars (pb1bis , CR_NL_CHARS );
83
87
if (numNewlines > 0 ) {
84
- metaData .putLong (PAYLOAD_LENGTH , countingIS .getCount ());
88
+ long payloadLength = countingIS .getCount ();
89
+ if (!metaData .has (PAYLOAD_LENGTH ) || payloadLength != metaData .getLong (PAYLOAD_LENGTH )) {
90
+ metaData .putLong (PAYLOAD_LENGTH , payloadLength );
91
+ }
85
92
metaData .putLong (PAYLOAD_SLOP_BYTES , numNewlines );
86
93
metaData .putString (PAYLOAD_DIGEST , "sha1:" +digString );
87
94
}
88
95
}
89
96
}
90
97
}
98
+
91
99
public MetaData getEnvelopeMetaData () {
92
100
return envelope ;
93
101
}
0 commit comments