Compress A String to be sent over a stream

Does anyone have an example of compressing a String , send it over an OutputStream and read the stream with An InputStream at the other end and decompresss the stream into a String again ? ** *Not FileStream stuff


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Send the String in the usual way but chain in DeflaterOutputStream/InflaterInputStream
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

spunogAuthor Commented:
This is my question: Does anyone have any examples of compressing a string and sending it over a stream (using a socket or whatever) and then reading it in and decompressing it at the other end ?

String s = "Hello  World";
PrintWriter out = new PrintWriter(new OutputStreamWriter(new DeflaterOutputStream(sock.getOutputStream())));


String s = null;
BufferedReader in = new BufferedReader(new InputStreamReader(new InflaterInputStream(sock.getInputStream())));
s = in.readLine();

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
spunogAuthor Commented:
Thanks CEHJ , So the compression/decompression is done behind the scenes and no other lines are needed ?
>>So the compression/decompression is done behind the scenes and no other lines are needed ?
Oops - yes you're right
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.