01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.tools.ant.taskdefs;
20:
21: import java.io.FileOutputStream;
22: import java.io.IOException;
23: import java.util.zip.GZIPOutputStream;
24: import org.apache.tools.ant.BuildException;
25: import org.apache.tools.ant.util.FileUtils;
26:
27: /**
28: * Compresses a file with the GZIP algorithm. Normally used to compress
29: * non-compressed archives such as TAR files.
30: *
31: * @since Ant 1.1
32: *
33: * @ant.task category="packaging"
34: */
35:
36: public class GZip extends Pack {
37: /**
38: * perform the GZip compression operation.
39: */
40: protected void pack() {
41: GZIPOutputStream zOut = null;
42: try {
43: zOut = new GZIPOutputStream(new FileOutputStream(zipFile));
44: zipResource(getSrcResource(), zOut);
45: } catch (IOException ioe) {
46: String msg = "Problem creating gzip " + ioe.getMessage();
47: throw new BuildException(msg, ioe, getLocation());
48: } finally {
49: FileUtils.close(zOut);
50: }
51: }
52:
53: /**
54: * Whether this task can deal with non-file resources.
55: *
56: * <p>This implementation returns true only if this task is
57: * <gzip>. Any subclass of this class that also wants to
58: * support non-file resources needs to override this method. We
59: * need to do so for backwards compatibility reasons since we
60: * can't expect subclasses to support resources.</p>
61: * @return true if this case supports non file resources.
62: * @since Ant 1.7
63: */
64: protected boolean supportsNonFileResources() {
65: return getClass().equals(GZip.class);
66: }
67: }
|