This discussion is archived
5 Replies Latest reply: Jul 27, 2012 8:58 PM by EJP RSS

Any standard method for reducing size packet

user10070648 Newbie
Currently Being Moderated
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)


hope your advice
  • 1. Re: Any standard method for reducing size packet
    EJP Guru
    Currently Being Moderated
    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
    baftos Expert
    Currently Being Moderated
    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
    sabre150 Expert
    Currently Being Moderated
    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
    952211 Newbie
    Currently Being Moderated
    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;
                   b = b.subtract(BigInteger.valueOf(Long.valueOf(r))).divide(radix);
              }
              System.out.println("example.length = " + example.length());
              System.out.println("st.length = " + st.length() );
         }
    }
  • 5. Re: Any standard method for reducing size packet
    EJP Guru
    Currently Being Moderated
    It's base 256; it can be done in one line; your code doesn't work; String is not a container for binary data; and the question has already been answered.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points