Author: toad
Date: 2007-04-13 16:41:48 +0000 (Fri, 13 Apr 2007)
New Revision: 12643
Added:
trunk/freenet/src/freenet/keys/TooBigException.java
Modified:
trunk/freenet/src/freenet/client/async/SimpleSingleFileFetcher.java
trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
trunk/freenet/src/freenet/keys/Key.java
Log:
Accurately report when data is too big when decoding.
Modified: trunk/freenet/src/freenet/client/async/SimpleSingleFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SimpleSingleFileFetcher.java
2007-04-13 16:38:36 UTC (rev 12642)
+++ trunk/freenet/src/freenet/client/async/SimpleSingleFileFetcher.java
2007-04-13 16:41:48 UTC (rev 12643)
@@ -12,6 +12,7 @@
import freenet.keys.ClientKey;
import freenet.keys.ClientKeyBlock;
import freenet.keys.KeyDecodeException;
+import freenet.keys.TooBigException;
import freenet.node.LowLevelGetException;
import freenet.support.Logger;
import freenet.support.api.Bucket;
@@ -131,6 +132,9 @@
Logger.minor(this, "Decode failure: "+e1, e1);
onFailure(new
FetchException(FetchException.BLOCK_DECODE_ERROR, e1.getMessage()));
return null;
+ } catch (TooBigException e) {
+ onFailure(new FetchException(FetchException.TOO_BIG,
e));
+ return null;
} catch (IOException e) {
Logger.error(this, "Could not capture data - disk
full?: "+e, e);
onFailure(new
FetchException(FetchException.BUCKET_ERROR, e));
Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
2007-04-13 16:38:36 UTC (rev 12642)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcherSubSegment.java
2007-04-13 16:41:48 UTC (rev 12643)
@@ -8,6 +8,7 @@
import freenet.keys.ClientKey;
import freenet.keys.ClientKeyBlock;
import freenet.keys.KeyDecodeException;
+import freenet.keys.TooBigException;
import freenet.node.LowLevelGetException;
import freenet.node.SendableGet;
import freenet.support.Logger;
@@ -184,6 +185,9 @@
Logger.minor(this, "Decode failure: "+e1, e1);
onFailure(new
FetchException(FetchException.BLOCK_DECODE_ERROR, e1.getMessage()), token);
return null;
+ } catch (TooBigException e) {
+ onFailure(new FetchException(FetchException.TOO_BIG,
e.getMessage()), token);
+ return null;
} catch (IOException e) {
Logger.error(this, "Could not capture data - disk
full?: "+e, e);
onFailure(new
FetchException(FetchException.BUCKET_ERROR, e), token);
Modified: trunk/freenet/src/freenet/keys/Key.java
===================================================================
--- trunk/freenet/src/freenet/keys/Key.java 2007-04-13 16:38:36 UTC (rev
12642)
+++ trunk/freenet/src/freenet/keys/Key.java 2007-04-13 16:41:48 UTC (rev
12643)
@@ -119,13 +119,13 @@
len = ((((((output[0] & 0xff) << 8) + (output[1] & 0xff)) << 8)
+ (output[2] & 0xff)) << 8) +
(output[3] & 0xff);
if(len > maxLength)
- throw new CHKDecodeException("Invalid precompressed size:
"+len);
+ throw new TooBigException("Invalid precompressed size: "+len);
Compressor decompressor =
Compressor.getCompressionAlgorithmByMetadataID(compressionAlgorithm);
Bucket inputBucket = new SimpleReadOnlyArrayBucket(output,
shortLength?2:4, outputLength-(shortLength?2:4));
try {
return decompressor.decompress(inputBucket, bf,
maxLength, -1, null);
} catch (CompressionOutputSizeException e) {
- throw new CHKDecodeException("Too big");
+ throw new TooBigException("Too big");
}
} else {
return BucketTools.makeImmutableBucket(bf, output,
outputLength);
@@ -155,11 +155,11 @@
byte[] cbuf = null;
if(alreadyCompressedCodec >= 0) {
if(sourceData.size() > maxCompressedDataLength)
- throw new KeyEncodeException("Too big
(precompressed)");
+ throw new TooBigException("Too big
(precompressed)");
compressionAlgorithm = alreadyCompressedCodec;
cbuf = BucketTools.toByteArray(sourceData);
if(sourceLength > MAX_LENGTH_BEFORE_COMPRESSION)
- throw new CHKEncodeException("Too big");
+ throw new TooBigException("Too big");
} else {
if (sourceData.size() > maxCompressedDataLength) {
// Determine the best algorithm
Added: trunk/freenet/src/freenet/keys/TooBigException.java
===================================================================
--- trunk/freenet/src/freenet/keys/TooBigException.java
(rev 0)
+++ trunk/freenet/src/freenet/keys/TooBigException.java 2007-04-13 16:41:48 UTC
(rev 12643)
@@ -0,0 +1,11 @@
+package freenet.keys;
+
+import java.io.IOException;
+
+public class TooBigException extends IOException {
+
+ public TooBigException(String msg) {
+ super(msg);
+ }
+
+}