Solved

compress and decompress string

Posted on 2011-03-09
7
550 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 92

Accepted Solution

by:
objects earned 251 total points
ID: 35080630
0
 
LVL 8

Assisted Solution

by:vsudip
vsudip earned 83 total points
ID: 35080653
0
 
LVL 92

Assisted Solution

by:objects
objects earned 251 total points
ID: 35080655
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 166 total points
ID: 35081201
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
ID: 35083203
I communicates with string-oriented.

thanks
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 166 total points
ID: 35083255
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
ID: 35089371
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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
The viewer will learn how to implement Singleton Design Pattern in Java.

695 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