handle decompress error by propogating the IOE (thanks nickster for bug report)

This commit is contained in:
jrandom
2004-06-13 19:30:31 +00:00
committed by zzz
parent fed8369a5f
commit 95c33e88ed
2 changed files with 22 additions and 21 deletions

View File

@ -10,6 +10,7 @@ package net.i2p.client;
*/ */
import java.io.InputStream; import java.io.InputStream;
import java.io.IOException;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
@ -86,11 +87,16 @@ class I2PSessionImpl2 extends I2PSessionImpl {
*/ */
public byte[] receiveMessage(int msgId) throws I2PSessionException { public byte[] receiveMessage(int msgId) throws I2PSessionException {
byte compressed[] = super.receiveMessage(msgId); byte compressed[] = super.receiveMessage(msgId);
if (SHOULD_COMPRESS) if (SHOULD_COMPRESS) {
try {
return DataHelper.decompress(compressed); return DataHelper.decompress(compressed);
else } catch (IOException ioe) {
throw new I2PSessionException("Error decompressing message", ioe);
}
} else {
return compressed; return compressed;
} }
}
private boolean sendBestEffort(Destination dest, byte payload[], SessionKey keyUsed, Set tagsSent) private boolean sendBestEffort(Destination dest, byte payload[], SessionKey keyUsed, Set tagsSent)
throws I2PSessionException { throws I2PSessionException {

View File

@ -552,9 +552,8 @@ public class DataHelper {
} }
/** decompress the GZIP compressed data (returning null on error) */ /** decompress the GZIP compressed data (returning null on error) */
public static byte[] decompress(byte orig[]) { public static byte[] decompress(byte orig[]) throws IOException {
if ((orig == null) || (orig.length <= 0)) return orig; if ((orig == null) || (orig.length <= 0)) return orig;
try {
GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(orig), orig.length); GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(orig), orig.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream(orig.length * 2); ByteArrayOutputStream baos = new ByteArrayOutputStream(orig.length * 2);
byte buf[] = new byte[4 * 1024]; byte buf[] = new byte[4 * 1024];
@ -568,9 +567,5 @@ public class DataHelper {
// _log.debug("Decompression of " + orig.length + " into " + rv.length + " (or " + 100.0d // _log.debug("Decompression of " + orig.length + " into " + rv.length + " (or " + 100.0d
// * (((double) rv.length) / ((double) orig.length)) + "% savings)"); // * (((double) rv.length) / ((double) orig.length)) + "% savings)");
return rv; return rv;
} catch (IOException ioe) {
//_log.error("Error decompressing?", ioe);
return null;
}
} }
} }