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.BufferedOutputStream;
22: import java.io.FileOutputStream;
23: import java.io.IOException;
24: import org.apache.tools.ant.BuildException;
25: import org.apache.tools.ant.util.FileUtils;
26: import org.apache.tools.bzip2.CBZip2OutputStream;
27:
28: /**
29: * Compresses a file with the BZIP2 algorithm. Normally used to compress
30: * non-compressed archives such as TAR files.
31: *
32: * @since Ant 1.5
33: *
34: * @ant.task category="packaging"
35: */
36:
37: public class BZip2 extends Pack {
38: /**
39: * Compress the zipFile.
40: */
41: protected void pack() {
42: CBZip2OutputStream zOut = null;
43: try {
44: BufferedOutputStream bos = new BufferedOutputStream(
45: new FileOutputStream(zipFile));
46: bos.write('B');
47: bos.write('Z');
48: zOut = new CBZip2OutputStream(bos);
49: zipResource(getSrcResource(), zOut);
50: } catch (IOException ioe) {
51: String msg = "Problem creating bzip2 " + ioe.getMessage();
52: throw new BuildException(msg, ioe, getLocation());
53: } finally {
54: FileUtils.close(zOut);
55: }
56: }
57:
58: /**
59: * Whether this task can deal with non-file resources.
60: *
61: * <p>This implementation returns true only if this task is
62: * <bzip2>. Any subclass of this class that also wants to
63: * support non-file resources needs to override this method. We
64: * need to do so for backwards compatibility reasons since we
65: * can't expect subclasses to support resources.</p>
66: * @return true if this task support non file resources.
67: * @since Ant 1.7
68: */
69: protected boolean supportsNonFileResources() {
70: return getClass().equals(BZip2.class);
71: }
72: }
|