Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
Posts: 4
Registered: ‎06-21-2010
My Device: 9500
My Carrier: vodafone

Re: GZIPInputStream Problem

hi peter

 

i try to  unzip the data in text file but it throws IoExcetion so please check the code i add below and tell me it has any problem with this code.

 

 

InputStream inputStream = getClass().getResourceAsStream("/Compressed_text.txt");
byte[] b = IOUtilities.streamToBytes(inputStream);
ByteArrayInputStream b1 = new ByteArrayInputStream(b);
GZIPInputStream gin = new GZIPInputStream(b1);
byte[] bytes = IOUtilities.streamToBytes(gin);
DataBuffer db = new DataBuffer();
db.setData(bytes, 0, bytes.length);
string2     = new String(db.getArray());

 

and the data stored in file is:

 

S4wAAB+LCAAAAAAABADtvQdgHEmWJSYvbcp7f0r1StfgdKEIgGATJNiQQBDswYjN5pLsHWlHIymrKoHKZVZlXWYWQMztnbz33nvvvffee++997o7nU4n99//P1xmZAFs9s5K2smeIYCqyB8/fnwfPyIev8ivnmZt9jpvj37jJE0fv8mbtlhe8B/055NXv/+TV1/+Xr//2dOj3b29h4/veh/YJse//4vjL06P/pF/EP+l8sP8hzf0e9v+VP7+4vjN8av0+Hn67Pj58esztNRvPMjHT5++On39WoELNPOZB9B89PSrJ8cKqdfq9z85e/P7HO3yGPhX983rN8dvvnp99Pvwd/qH997zs9MXbzDkvZ3d3d17BwLCfuqh+/rbX75645NDMPY+9pD2PmVaCN6xtr//q9OXr1534fqfemC9Tz2wsba//8tvf/ni9PffPdrBwyDNJ902e702e16bZ8e/t/c9/nLfPT1+g8n44uwNkW/nwfbO3vbe/Tc7O4/4f5/s7D/S17yG3sycPn/2+z97fvy5mRz7t2vz1WuajS+fnh49FAa1f3tNXj79/d+c0dgJhYPtnXvbO5/GULDN3JS+OPk25nifJ1L/0G/PXv/+Xxy/+r1O37BInL46evH4bu8zlqq7vlhtlrFPbyFjG8XqhLA8fX4baUp/7sVp52DvoZA+Ik4+z0o/NzL8ri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ISN0rFjgzqh7pq8H5S8bNngpjem6Ri5xYCEbb52RUEURAfKAg3+Ww78v4GQVCe+dkTBBH4G5bF/l/M4L1QhNakdn6WQpEfrnj8bLD1PUFkM1vfPoF9/Pws/fLJ6dnTs8187gP6uUtZ7+3s7t67Nxik/JBY9AGv8vwcr9wSi+5+wyu34tfs30KNa9Lo+PiHp87vvUcC+Aae/+Krbx+/eHH8NP3Ol189Pf32TYx/I9N/J8rwhss/MGbYfXjvU5WZG2MGwfTGaOGWkcJtF2fmAm6jzRBbPCyQD7zvuwIp34UC+Z7rsgfbuzs/a3lemZ0bBPaABfbhz7HAfvGdH6LACl1uLbC3ENovviChPX7+U19+9eRW5uoWsvvFlwL2Z1WE9+89+FlZsiHkFfGoLFvhe6A+4rD8dZr0RPBTsbk3WMWfvbWU21nFA6DwvlbxdmspD99DyL79QxQy4ashIXvynHX9gEjpt8NSZF/fIEAWyM+S7Dzc35G5v0l2LLI3io1F+SYLqA1vNoEW4uZ82d6uODF9OYRg3duLreaEQvZwG9HJ13E9X9wsZLcyZBsweD9D9rMiDpvXaZ48f7lRHPjbTeKgr28UBwXysyYOu0Lsm8VBkb2FOCjKN4sDN7yNOCjEqDj8rPAkqf5vgCf/3+NcPb77Ir96mrXZ67w9+n8AvTWzCEuMAAA=

 

 

 

 

so please tell me if any issue with data or in code.

 

Thanks IN advanced.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: GZIPInputStream Problem

That data looks like it has been Base 64 encoded, however I tried Base64 decoding it and did not get a gzipped file.  The file does not appear to be a zip archive either.  Can you tell us what processing was done on the PC before you added the file to your project?

Trusted Contributor
Posts: 227
Registered: ‎12-16-2009
My Device: 9530,8900,9000
My Carrier: Airtel,Docomo

Re: GZIPInputStream Problem

[ Edited ]

Hi Peter,

I am surprising that if i debug then gives the correct result but if i not debug then it gives this error.. what you think? what issue will be there?

 

Lathiya Himanshu
Highlighted
Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: GZIPInputStream Problem

I agree with Peter that this looks like base64 data. It also looks like it has 4 bytes of extra data (4b 8c 00 00) before the start of the gzip file data after base64 decoding. I don't know what those 4 bytes are, but when I stripped them out and then ran the remainder through zcat, I got a nice XML file (it started <NewDataSet>).

 

Your code is also doing a lot of unnecessary copying of bytes. Try this instead:

 

InputStream inputStream = getClass().getResourceAsStream("/Compressed_text.txt");
Base64InputStream b64 = new Base64InputStream(inputStream);
b64.skip(4L);
GZIPInputStream gin = new GZIPInputStream(b64);
byte[] bytes = IOUtilities.streamToBytes(gin);
gin.close();
String xml = new String(bytes, "UTF-8");

 

Give what it took to correctly decode the file, I am amazed that your code works when debugging.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.