shall we compress integer values

Hi All, Is this string is enough for compression using java compression library.String test="9841996166 0409884988743 070531 404410002847497";please help me
[184 byte] By [sebasmtech@java.devlopera] at [2007-11-27 8:16:16]
# 1
Hi sebasmtech.I think we need more information -- what exactly are you trying to achieve, and what is the significance of the String?
glennjia at 2007-7-12 20:01:09 > top of Java-index,Java Essentials,Java Programming...
# 2

> Hi All,

> Is this string is enough for compression

> using java compression library.

>

> String test="9841996166 0409884988743 070531

> 404410002847497";

I doubt it.

> please help me

Why don't you help yourself by trying to compress that String?

prometheuzza at 2007-7-12 20:01:09 > top of Java-index,Java Essentials,Java Programming...
# 3

Hi,

Thanks for your reply.i compress this string using java libraries.but it was not compressed properly.it exceeds the actual size.

String test="9841996166 0409884988743 070531 404410002847497"

Compressor comp=new Compressor();

comp.gzipCompress(test);

is it possible to compress this string?

sebasmtech@java.devlopera at 2007-7-12 20:01:09 > top of Java-index,Java Essentials,Java Programming...
# 4

> Hi,

> Thanks for your reply.i compress this string

> using java libraries.but it was not compressed

> properly.it exceeds the actual size.

>

> String test="9841996166 0409884988743 070531

> 404410002847497"

>

> Compressor comp=new Compressor();

>comp.gzipCompress(test);

> it possible to compress this string?

No.

prometheuzza at 2007-7-12 20:01:09 > top of Java-index,Java Essentials,Java Programming...
# 5
Hi prometheuzz,Could you tell me is there any other way to reduce the size of this string?
sebasmtech@java.devlopera at 2007-7-12 20:01:09 > top of Java-index,Java Essentials,Java Programming...
# 6
This string consumes the unbelievable amount of 94 raw bytes (overhead ignored). How much do you want to save?
quittea at 2007-7-12 20:01:09 > top of Java-index,Java Essentials,Java Programming...
# 7

> Hi prometheuzz,

> Could you tell me is there

> any other way to reduce the size of this string?

String test = "";

Seriously, you should re-read the answers in your previous post:

http://forum.java.sun.com/thread.jspa?threadID=5181300

especially reply #12 and #14. This is the same thing all over again.

prometheuzza at 2007-7-12 20:01:09 > top of Java-index,Java Essentials,Java Programming...
# 8

> it possible to compress this string?

Of course. There are hundreds of approaches that can be use. One simple approach is

String test="9841996166 0409884988743 070531 404410002847497";

if (!test.matches("[ 0-9]+"))

throw new IllegalArgumentException("Silly Billy");

System.out.println(test.length() + "\t" + test);

StringBuffer compressed = new StringBuffer();

compressed.append(test.charAt(0));

for (int i = 1; i < test.length(); i++)

{

if ((test.charAt(i-1) == test.charAt(i)) && (compressed.charAt(compressed.length()-1) < 256))

{

compressed.setLength(compressed.length()-1);

compressed.append((char)(test.charAt(i) + 256));

}

else

compressed.append(test.charAt(i));

}

System.out.println(compressed.length() + "\t" + compressed);

StringBuffer decompressed = new StringBuffer();

for (int i = 0; i < compressed.length(); i++)

{

if (compressed.charAt(i) < 256)

decompressed.append(compressed.charAt(i));

else

{

char ch = (char)(compressed.charAt(i) - 256);

decompressed.append(ch).append(ch);

}

}

System.out.println(decompressed.length() + "\t" + decompressed);

but I bet this is not what you want.

You need to read the replies in your previous thread on this topic.

sabre150a at 2007-7-12 20:01:09 > top of Java-index,Java Essentials,Java Programming...
# 9
There are ways to compress small data sets if you know what your data looks like, and/or if you know the character distribution.
kajbja at 2007-7-12 20:01:09 > top of Java-index,Java Essentials,Java Programming...
# 10
Hi sabre,Thanks for ur reply.when i add a character to my string ,String test="9841996166 0409884988743 070531 404410002847497 DJA01"it throws error.could you tell me how to compress the string.Thanks in Advance
sebasmtech@java.devlopera at 2007-7-12 20:01:09 > top of Java-index,Java Essentials,Java Programming...
# 11

> Hi sabre,

> Thanks for ur reply.when i add a

> character to my string ,

>

> String test="9841996166 0409884988743 070531

> 404410002847497 DJA01"

>

> it throws error.

I give in!

>

> could you tell me how to compress the

> string.

I give in!

>

> Thanks in Advance

You seem to be waiting for someone wave a magic wand. JUST READ THE RESPONSES IN YOUR OTHER THREADS ON THIS TOPIC. No thanks required because I am not going to help you further.

sabre150a at 2007-7-12 20:01:09 > top of Java-index,Java Essentials,Java Programming...
# 12

When you do a generic compression the compression alorithm has to figure out a alphabet and coresponding codes and include it in the compressed file. When the string isn't much longer than the alphabet that generally means the results are bigger than the input.

If you know the complete set from which permitted characters are drawn then you can use a fixed encoding scheme, and achieve compression on a short string.

malcolmmca at 2007-7-12 20:01:09 > top of Java-index,Java Essentials,Java Programming...
# 13

use a long data type array to store this string. convert the first 18 characters to a long integer value then store it in the array. Then take next 18 characters, convert and store it in the next index of array. like that store the entire string as a block of 18 characters in long Array.

18 characters requires 36 bytes of memory. but a Long requires only 8 bytes. so your data will compress one forth.

Message was edited by:

PremKumarU

PremKumarUa at 2007-7-12 20:01:09 > top of Java-index,Java Essentials,Java Programming...
# 14

> use a long data type array to store this string.

> convert the first 18 characters to a long integer

> value then store it in the array. Then take next 18

> characters, convert and store it in the next index of

> array. like that store the entire string as a block

> of 18 characters in long Array.

> 18 characters requires 36 bytes of memory. but a Long

> requires only 8 bytes. so your data will compress one

> forth.

>

> Message was edited by:

> PremKumarU

The OP also wants to be able to compress strings with normal characters.

kajbja at 2007-7-12 20:01:09 > top of Java-index,Java Essentials,Java Programming...
# 15
Hi Sabre,You Misunderstood me.i am a newbie to java.i searched lot of forums for the past 6 days but not able to acheive compression .but your idea workout for me.
sebasmtech@java.devlopera at 2007-7-21 22:34:47 > top of Java-index,Java Essentials,Java Programming...
# 16
Hi premkumar,Good Idea u have given.
sebasmtech@java.devlopera at 2007-7-21 22:34:47 > top of Java-index,Java Essentials,Java Programming...
# 17
Hi Premkumar, i have whitespace in my string (ie) String test="98400000000 984000";it compress but when i store it didnt perform well.do u know any other idea?
sebasmtech@java.devlopera at 2007-7-21 22:34:47 > top of Java-index,Java Essentials,Java Programming...
# 18
If you have just spaces and digits, you can back each digit into half a byte (a nybble) with, say, 0xf as the space.
malcolmmca at 2007-7-21 22:34:47 > top of Java-index,Java Essentials,Java Programming...
# 19

Hi malcolm,

here is my code could you please check is it good for the string

String test="9840000000 984000000 070601 089876";

now it compress 48 to 34 bits is it possible to compress still more

using the code

for (int i = 1; i < inputData.length(); i++)

{

if ((inputData.charAt(i-1) == inputData.charAt(i)) && (compressed.charAt(compressed.length()-1) <10000))

{

compressed.setLength(compressed.length()-1);

compressed.append((char)(inputData.charAt(i) + 10000));

}

else

compressed.append(inputData.charAt(i));

}

sebasmtech@java.devlopera at 2007-7-21 22:34:47 > top of Java-index,Java Essentials,Java Programming...
# 20
> Hi malcolm,> here is my code could you> please check is it good for the string> > String test="9840000000 984000000 070601 089876";> > now it compress 48 to 34 bits ...Do you think that String is 34 bits?
prometheuzza at 2007-7-21 22:34:47 > top of Java-index,Java Essentials,Java Programming...
# 21
why in the name of the lord does anyone want to do this?what is wrong with the zip package for compression?
mkoryaka at 2007-7-21 22:34:47 > top of Java-index,Java Essentials,Java Programming...
# 22

compressed.charAt(compressed.length()-1) <10000))

This would almost always return true. I don't believe that code compresses anything that is uncompessable.

It might make more sense if you had

(compressed.charAt(compressed.length()-1) <0x10000))

and this method would only compress if you had duplicates in a row, and make it worse if there were none.

robtafta at 2007-7-21 22:34:47 > top of Java-index,Java Essentials,Java Programming...
# 23
Hi Robtaft,This code exceeds the actual size.is this string performs compression else throws actual size.zip compression technology double the actual size.could you give suggestion to compress in a best way
sebasmtech@java.devlopera at 2007-7-21 22:34:47 > top of Java-index,Java Essentials,Java Programming...
# 24

Dear sebasmtech@java.devloper,

What in the ****?

This is about enough of these shenanigans. One thread was more then enough. Two is excessive.

Now listen very carefully.

YOU ARE ASKING FOR THE IMPOSSIBLE

Did you understand that?

Good. Now, let's move on shall we? Why are you having the mistaken impression that you want to do this? What problem are you trying to solve exactly. DO NOT say that you want to compress a string. Nobody gives a ****. Tell us why you want to compress the String.

That's your real problem and if it is a problem needs to be addressed with a solution that will actually work. Unlike your solution which will never work and it has been explained to you repeatedly why it will not work. So there is no point in discussing it any more.

So no more threads or posts about String compression from you please. Just tell us what problem you are actually trying to solve.

cotton.ma at 2007-7-21 22:34:47 > top of Java-index,Java Essentials,Java Programming...