KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > BZip2


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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
22 import java.io.BufferedOutputStream JavaDoc;
23 import java.io.FileOutputStream JavaDoc;
24 import java.io.IOException JavaDoc;
25 import org.apache.tools.ant.BuildException;
26 import org.apache.tools.ant.util.FileUtils;
27 import org.apache.tools.bzip2.CBZip2OutputStream;
28
29 /**
30  * Compresses a file with the BZIP2 algorithm. Normally used to compress
31  * non-compressed archives such as TAR files.
32  *
33  * @since Ant 1.5
34  *
35  * @ant.task category="packaging"
36  */

37
38 public class BZip2 extends Pack {
39     /**
40      * Compress the zipFile.
41      */

42     protected void pack() {
43         CBZip2OutputStream zOut = null;
44         try {
45             BufferedOutputStream JavaDoc bos =
46                 new BufferedOutputStream JavaDoc(new FileOutputStream JavaDoc(zipFile));
47             bos.write('B');
48             bos.write('Z');
49             zOut = new CBZip2OutputStream(bos);
50             zipResource(getSrcResource(), zOut);
51         } catch (IOException JavaDoc ioe) {
52             String JavaDoc msg = "Problem creating bzip2 " + ioe.getMessage();
53             throw new BuildException(msg, ioe, getLocation());
54         } finally {
55             FileUtils.close(zOut);
56         }
57     }
58
59     /**
60      * Whether this task can deal with non-file resources.
61      *
62      * <p>This implementation returns true only if this task is
63      * &lt;bzip2&gt;. Any subclass of this class that also wants to
64      * support non-file resources needs to override this method. We
65      * need to do so for backwards compatibility reasons since we
66      * can't expect subclasses to support resources.</p>
67      * @return true if this task support non file resources.
68      * @since Ant 1.7
69      */

70     protected boolean supportsNonFileResources() {
71         return getClass().equals(BZip2.class);
72     }
73 }
74
Popular Tags