KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > portlet > util > AbstractUnzipper


1 package com.opensymphony.webwork.portlet.util;
2
3 import org.apache.log4j.Category;
4
5 import java.io.*;
6 import java.util.zip.ZipEntry JavaDoc;
7
8 public abstract class AbstractUnzipper implements Unzipper {
9
10     protected static Category log;
11
12     private static final int BUFFER_SIZE = 10240;
13
14     protected File destDir;
15
16     static {
17         log = Category.getInstance(com.opensymphony.webwork.portlet.util.FileUnzipper.class);
18     }
19
20     public abstract File unzipFileInArchive(String JavaDoc s) throws Exception JavaDoc;
21
22     public abstract void unzip() throws Exception JavaDoc;
23
24     public AbstractUnzipper() {
25     }
26
27     protected File saveEntry(InputStream is, ZipEntry JavaDoc entry) throws Exception JavaDoc {
28         File file = new File(destDir, entry.getName());
29         if (entry.isDirectory()) {
30             file.mkdirs();
31         } else {
32             File dir = new File(file.getParent());
33             dir.mkdirs();
34             FileOutputStream fos = new FileOutputStream(file);
35             pump(is, fos);
36             fos.flush();
37             fos.close();
38         }
39         return file;
40     }
41
42     private static void pump(InputStream is, OutputStream os) throws IOException {
43         byte buffer[] = new byte[10240];
44         int lengthRead;
45         while ((lengthRead = is.read(buffer)) >= 0) os.write(buffer, 0, lengthRead);
46     }
47
48 }
49
50
Popular Tags