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,10 +87,15 @@ 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) {
return DataHelper.decompress(compressed); try {
else return DataHelper.decompress(compressed);
} 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)

View File

@ -552,25 +552,20 @@ 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]; while (true) {
while (true) { int read = in.read(buf);
int read = in.read(buf); if (read == -1) break;
if (read == -1) break; baos.write(buf, 0, read);
baos.write(buf, 0, read);
}
byte rv[] = baos.toByteArray();
//if (_log.shouldLog(Log.DEBUG))
// _log.debug("Decompression of " + orig.length + " into " + rv.length + " (or " + 100.0d
// * (((double) rv.length) / ((double) orig.length)) + "% savings)");
return rv;
} catch (IOException ioe) {
//_log.error("Error decompressing?", ioe);
return null;
} }
byte rv[] = baos.toByteArray();
//if (_log.shouldLog(Log.DEBUG))
// _log.debug("Decompression of " + orig.length + " into " + rv.length + " (or " + 100.0d
// * (((double) rv.length) / ((double) orig.length)) + "% savings)");
return rv;
} }
} }