KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > resources > GZipResource


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 package org.apache.tools.ant.types.resources;
19
20 import java.io.InputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.io.OutputStream JavaDoc;
23 import java.util.zip.GZIPInputStream JavaDoc;
24 import java.util.zip.GZIPOutputStream JavaDoc;
25
26 /**
27  * A GZip compressed resource.
28  *
29  * <p>Wraps around another resource, delegates all quries to that
30  * other resource but uncompresses/compresses streams on the fly.</p>
31  *
32  * @since Ant 1.7
33  */

34 public class GZipResource extends CompressedResource {
35
36     /** A no-arg constructor */
37     public GZipResource() {
38     }
39
40     /**
41      * Constructor with another resource to wrap.
42      * @param other the resource to wrap.
43      */

44     public GZipResource(org.apache.tools.ant.types.ResourceCollection other) {
45         super(other);
46     }
47
48     /**
49      * Decompress on the fly using java.util.zip.GZIPInputStream.
50      * @param in the stream to wrap.
51      * @return the wrapped stream.
52      * @throws IOException if there is a problem.
53      */

54     protected InputStream JavaDoc wrapStream(InputStream JavaDoc in) throws IOException JavaDoc {
55         return new GZIPInputStream JavaDoc(in);
56     }
57
58     /**
59      * Compress on the fly using java.util.zip.GZIPOutStream.
60      * @param out the stream to wrap.
61      * @return the wrapped stream.
62      * @throws IOException if there is a problem.
63      */

64      protected OutputStream JavaDoc wrapStream(OutputStream JavaDoc out) throws IOException JavaDoc {
65         return new GZIPOutputStream JavaDoc(out);
66     }
67
68     /**
69      * Get the name of the compression method.
70      * @return the string "GZip".
71      */

72     protected String JavaDoc getCompressionName() {
73         return "GZip";
74     }
75 }
76
Popular Tags