5 Replies Latest reply: Jul 27, 2012 10:58 PM by EJP RSS

    Any standard method for reducing size packet

    user10070648
      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
          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
            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
              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
                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
                  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.