• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Create a ZLib archive using java 1.5

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I need some help on ZLib archive file. The code is as follows,
// get all the files from the drive
File f = new File("C:\\DA_SRC\\DA_Temp\\C");
String fileList[] = f.list();
File zipFile = new File(f.getAbsolutePath() + "\\Test.zip");
System.out.println(f.getAbsolutePath() + f.getCanonicalPath());
FileOutputStream fos = new FileOutputStream(zipFile);
ByteArrayOutputStream baos = new ByteArrayOutputStream();

Deflater def = new Deflater(Deflater.DEFAULT_COMPRESSION);

DeflaterOutputStream out = new DeflaterOutputStream(baos,def);

int bytesRead;
byte[] buffer = new byte[1024];

BufferedInputStream bis = null;
for (int i = 0; i< fileList.length; i++)
{
String name = fileList[i];
File file = new File(f.getAbsolutePath() + "\\" + name);
System.out.println(file.getName());
// Reset to beginning of input stream
bis = new BufferedInputStream(new FileInputStream(file));

while ((bytesRead = bis.read(buffer)) != -1)
{
System.out.println("aaaa");
out.write(buffer, 0, bytesRead);
}
bis.close();
}
out.finish();
out.close();
baos.writeTo(fos);
fos.close();
baos.close();
}

This code is creating a package, but I am not sure if that package is correct or not.
I need the following information.

Am I creating a valid Zlib file or not...
If the package is valid, then is there any tool to extract that file apart from the java.util.zip package.

PLease advice me on this...
Thanks
Raj
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/UseCodeTags
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic