Solved

compress and decompress string

Posted on 2011-03-09
7
548 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
Independent Software Vendors: 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

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!

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

749 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