5 Replies Latest reply on Jul 28, 2012 3:58 AM by EJP

# Any standard method for reducing size packet

Dear ALL,

Is there anyway to reduce the size of data packet ? (At least 1/3)

Example :

Actual packet to be sent = 479343646359649593274942343294389636564395 (Length = 50)

After encoding = some encoded data (Length around 15)

After decoding at server level = 479343646359649593274942343294389636564395 (Length = 50)

• ###### 1. Re: Any standard method for reducing size packet
It depends on what content you're sending. If it's binary and uses all the possible 256 byte values in a well-distributed way it won't compress well. If it's character data, run it through a GIPOutputStream at the sender and a GZIPInputStream at the receiver: you should see some worthwhile compression, at the cost of some CPU and time of course.
• ###### 2. Re: Any standard method for reducing size packet
Why? Is your exemple of 50 bytes before compression typical? If yes, I would not bother, but you may have reasons that you did not share with us.
• ###### 3. Re: Any standard method for reducing size packet
Your example shows your data as having only decimal digits. If this is always the case then you can convert 50 decimal digits to a BigInteger and then convert the BigInteger to 21 bytes.
• ###### 4. Re: Any standard method for reducing size packet
Hello,

If we consider that your data is numeric [0-9], then your can convert it like this (to obtain effectively 21 bytes). This conversion is "only" a transformation from decimal base to "255-base"

Regards,

Bruno

code :*

public class TestOZB {

public static void main(String[] args) {
String example = "99999999999999999999999999999999999999999999999999";
BigInteger b = new BigInteger(example);
BigInteger radix = BigInteger.valueOf(255L);
String st = "";
while(b.compareTo(BigInteger.ZERO) == 1) {
int r = b.remainder(radix).intValue();
st = ((char)r)+st;