Problem in compressing data stream using socket.

V

Vijay

Hi ..

I had a requirement to have a add-on to the existing clinet - server
module .

The requirement is to compress the data before sending and decompress
it before receiving . The rest will be the original code .

Since , the client and server keeps talking always there was a problem
when i tried the ZLib & GZipInput/GZIPOutput streams .

After writing the output channels they close the underlying streams .
So my socket gets closed .

Now Iam trying out the BZIP Implementaion , and face a strange problem
...

The code is

/** Used to decompress the stream and put the data into a byte
array-
*This gets the input stream from the socket , decompress it and
writes it
*into an byte array .
*/

public byte[] decompressData(InputStream in){
Logger.writeLog(" In de-compression module 1 socket Closed is "+
nmsclientsoc.isClosed());
byte[] bytDecompressed = new byte[1];

try {
StringBuffer sbuf = new StringBuffer();
BufferedInputStream bis = new BufferedInputStream(in);

int b = bis.read();
if(b != 'B'){
return bytDecompressed;
}
b = bis.read();
if(b != 'Z'){
return bytDecompressed;
}
CBZip2InputStream bzis = new CBZip2InputStream(bis);
int ch = bzis.read();
while(ch != -1) {
sbuf.append((char)ch);
ch = bzis.read();
}//end of while
String sTemp = sbuf.toString();
bytDecompressed = new byte[sTemp.length()];
bytDecompressed = sTemp.getBytes();
Logger.writeLog("The decompressed data is : " + sTemp);
} catch(IOException e) {
Logger.writeLog("The exception is : " + e.getMessage());
}//end of catch
Logger.writeLog("### In de-compression module 2 socket Closed is
"+ nmsclientsoc.isClosed());
return bytDecompressed;
}//end of method decompressData

And now , the socke is not closed , but i get a NullPointerException
for the
CBZip2InputStream , everytime it gets a call ..

Please any idea / inputs ..

Veritas,
Vijay.M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,000
Messages
2,570,252
Members
46,848
Latest member
CristineKo

Latest Threads

Top