views:

936

answers:

3

I have looked online with mixed results, but is there a way to programmatically extract a zip file on the BB? Very basic my app will display different encrypted file types, and those files are delivered in a zip file. My idea was to have the user browse to the file on their SDCard, select it, and I extract what i need as a stream from the file. is this possible?

+1  A: 

Use GZIPInputStream

Example:

 try
 {
  InputStream inputStream = httpConnection.openInputStream();
  GZIPInputStream gzis = new GZIPInputStream(inputStream);
  StringBuffer sb = new StringBuffer();

  char c;
  while ((c = (char)gzis.read()) != -1)
  {
   sb.append(c);
  }

  String data = sb.toString();

  gzis.close();
 }
 catch(IOException ioe)
 {
 }
Byron Whitlock
Thanks for the code sample. I will give it a try. Still gathering ideas and researching but this code looks similar to my windows/mac apps that use Java 1.5 (just no ZipEntry and ZipFile classes in BB to use)
KKlucznik
+1  A: 

Just two things:

  • In BB API there are only GZip and ZLib support, and no multiple files compression support, so it's not possible to compress several files and extract only one of them.
  • Up to my experience, such functionality will fly on simulator, but may be really performance-killing on real device

See How to retrieve data from a attached zip file in Blackberry application?

PS Actually you can implement custom multi-entries stream and parse it after decompress, but that seems to be useless, if you want this archive format to be supported in other applications.

Max Gontar
Thanks for the info. I did not know it only supported these types, and looking into them, you are absolutely right. cannot extract one file and would be very inefficient. do you know of any third party libraries that can be added to a BB app to perform this type of extraction?
KKlucznik
Your welcome! I haven't heard of alternatives. I would suggest you to search for j2me compression libraries, opensource preferred.
Max Gontar
A: 

Hello, I have a problem like this: I just want to extract a .zip file. Can we use the GZipInputStream to extract it or GZipInputStream is only for .gz file. Any hel would be great!

yeap