Solved

compress and decompress string

Posted on 2011-03-09
7
543 Views
Last Modified: 2012-05-11
I have a String encoded Base64 , and I need it to be compressed for sending the Socket.

and receiving it from socket want it to be decompress as before , the string encoded Base64 .

How can I make it??
0
Comment
Question by:gamjaradio
7 Comments
 
LVL 92

Accepted Solution

by:
objects earned 251 total points
Comment Utility
0
 
LVL 8

Assisted Solution

by:vsudip
vsudip earned 83 total points
Comment Utility
0
 
LVL 92

Assisted Solution

by:objects
objects earned 251 total points
Comment Utility
you can do something like this (where out is where you want to write the compressed data):

GZIPOutputStream gos = new GZIPOutputStream(out);
gos.write(string.getBytes("UTF8");
gos.close();

0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 166 total points
Comment Utility
Why is the String encoded as Base64? Doing that inflates the size of what it was originally. The purpose of it is to render binary content able to be handled as a String.
When you compress it in the  manner suggested above, you will again get binary content, which will probably be larger than it was originally.
Are you communcations string-oriented, or binary-oriented?
0
 

Author Comment

by:gamjaradio
Comment Utility
I communicates with string-oriented.

thanks
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 166 total points
Comment Utility
In that case, you should either:

a. get the byte array before it gets Base64-encoded and compress that, then Base64 encode
b. Base64-decode then apply a. above

If you can post an example Base64 string, preferably attached as a file, then we can give it a try
0
 
LVL 92

Assisted Solution

by:objects
objects earned 251 total points
Comment Utility
the code I posted above will encode your string for you.
Do the reverse to decode it

let me know if you have any problems
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now