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: package org.apache.tools.ant.types.resources;
19:
20: import java.io.InputStream;
21: import java.io.IOException;
22: import java.io.OutputStream;
23: import java.util.zip.GZIPInputStream;
24: import java.util.zip.GZIPOutputStream;
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(
45: org.apache.tools.ant.types.ResourceCollection other) {
46: super (other);
47: }
48:
49: /**
50: * Decompress on the fly using java.util.zip.GZIPInputStream.
51: * @param in the stream to wrap.
52: * @return the wrapped stream.
53: * @throws IOException if there is a problem.
54: */
55: protected InputStream wrapStream(InputStream in) throws IOException {
56: return new GZIPInputStream(in);
57: }
58:
59: /**
60: * Compress on the fly using java.util.zip.GZIPOutStream.
61: * @param out the stream to wrap.
62: * @return the wrapped stream.
63: * @throws IOException if there is a problem.
64: */
65: protected OutputStream wrapStream(OutputStream out)
66: throws IOException {
67: return new GZIPOutputStream(out);
68: }
69:
70: /**
71: * Get the name of the compression method.
72: * @return the string "GZip".
73: */
74: protected String getCompressionName() {
75: return "GZip";
76: }
77: }
|