1 18 19 package org.apache.tools.ant.taskdefs; 20 21 import java.io.FileOutputStream ; 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import java.util.zip.GZIPInputStream ; 25 import org.apache.tools.ant.BuildException; 26 import org.apache.tools.ant.util.FileUtils; 27 28 37 38 public class GUnzip extends Unpack { 39 40 private static final String DEFAULT_EXTENSION = ".gz"; 41 42 46 protected String getDefaultExtension() { 47 return DEFAULT_EXTENSION; 48 } 49 50 53 protected void extract() { 54 if (source.lastModified() > dest.lastModified()) { 55 log("Expanding " + source.getAbsolutePath() + " to " 56 + dest.getAbsolutePath()); 57 58 FileOutputStream out = null; 59 GZIPInputStream zIn = null; 60 InputStream fis = null; 61 try { 62 out = new FileOutputStream (dest); 63 fis = srcResource.getInputStream(); 64 zIn = new GZIPInputStream (fis); 65 byte[] buffer = new byte[8 * 1024]; 66 int count = 0; 67 do { 68 out.write(buffer, 0, count); 69 count = zIn.read(buffer, 0, buffer.length); 70 } while (count != -1); 71 } catch (IOException ioe) { 72 String msg = "Problem expanding gzip " + ioe.getMessage(); 73 throw new BuildException(msg, ioe, getLocation()); 74 } finally { 75 FileUtils.close(fis); 76 FileUtils.close(out); 77 FileUtils.close(zIn); 78 } 79 } 80 } 81 82 93 protected boolean supportsNonFileResources() { 94 return getClass().equals(GUnzip.class); 95 } 96 } 97 | Popular Tags |