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.

BZip2.java 2.5 kB

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