You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

GZip.java 2.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.taskdefs;
  19. import java.io.FileOutputStream;
  20. import java.io.IOException;
  21. import java.util.zip.GZIPOutputStream;
  22. import org.apache.tools.ant.BuildException;
  23. import org.apache.tools.ant.util.FileUtils;
  24. /**
  25. * Compresses a file with the GZIP algorithm. Normally used to compress
  26. * non-compressed archives such as TAR files.
  27. *
  28. * @since Ant 1.1
  29. *
  30. * @ant.task category="packaging"
  31. */
  32. public class GZip extends Pack {
  33. /**
  34. * perform the GZip compression operation.
  35. */
  36. protected void pack() {
  37. GZIPOutputStream zOut = null;
  38. try {
  39. zOut = new GZIPOutputStream(new FileOutputStream(zipFile));
  40. zipResource(getSrcResource(), zOut);
  41. } catch (IOException ioe) {
  42. String msg = "Problem creating gzip " + ioe.getMessage();
  43. throw new BuildException(msg, ioe, getLocation());
  44. } finally {
  45. FileUtils.close(zOut);
  46. }
  47. }
  48. /**
  49. * Whether this task can deal with non-file resources.
  50. *
  51. * <p>This implementation returns true only if this task is
  52. * &lt;gzip&gt;. Any subclass of this class that also wants to
  53. * support non-file resources needs to override this method. We
  54. * need to do so for backwards compatibility reasons since we
  55. * can't expect subclasses to support resources.</p>
  56. * @return true if this case supports non file resources.
  57. * @since Ant 1.7
  58. */
  59. protected boolean supportsNonFileResources() {
  60. return getClass().equals(GZip.class);
  61. }
  62. }