> 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?
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?
> 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.
> 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.
> 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.
> 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.
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.
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
> 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.
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));
}
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.
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.