/** * Decompress the GZIP compressed data (returning null on error). * @throws IOException if uncompressed is over 40 KB, * or on a decompression error * @return null if orig is null */ public static byte[] decompress(byte orig[]) throws IOException { return (orig != null ? decompress(orig, 0, orig.length) : null); }
/** * pull the unencrypted AND DECOMPRESSED data */ @Override public byte[] receiveMessage(int msgId) throws I2PSessionException { byte compressed[] = super.receiveMessage(msgId); if (compressed == null) { _log.error("Error: message " + msgId + " already received!"); return null; } // future - check magic number to see whether to decompress if (SHOULD_DECOMPRESS) { try { return DataHelper.decompress(compressed); } catch (IOException ioe) { //throw new I2PSessionException("Error decompressing message", ioe); if (_log.shouldWarn()) _log.warn("Error decompressing message", ioe); return null; } } return compressed; }
@Test public void testCompress() throws Exception{ Random r = new Random(); for (int size = 0; size < 32*1024; size+=32){ // Original had size++, changed value because // speed was a problem. -Comwiz byte data[] = new byte[size]; r.nextBytes(data); byte compressed[] = DataHelper.compress(data); byte decompressed[] = DataHelper.decompress(compressed); assertTrue(DataHelper.eq(data, decompressed)); } }
byte decompressed[] = DataHelper.decompress(data, curIndex, compressedSize); _dbEntry.readBytes(new ByteArrayInputStream(decompressed)); } catch (DataFormatException dfe) {