Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

compress and decompress string

Posted on 2011-03-09
7
Medium Priority
?
552 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 1004 total points
ID: 35080630
0
 
LVL 8

Assisted Solution

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

Assisted Solution

by:objects
objects earned 1004 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
Technology Partners: 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 664 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 664 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 1004 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

609 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