1. /*
  2. * Copyright 2001-2002,2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.ant.taskdefs;
  18. import java.io.BufferedOutputStream;
  19. import java.io.FileOutputStream;
  20. import java.io.IOException;
  21. import org.apache.tools.ant.BuildException;
  22. import org.apache.tools.bzip2.CBZip2OutputStream;
  23. /**
  24. * Compresses a file with the BZIP2 algorithm. Normally used to compress
  25. * non-compressed archives such as TAR files.
  26. *
  27. *
  28. * @since Ant 1.5
  29. *
  30. * @ant.task category="packaging"
  31. */
  32. public class BZip2 extends Pack {
  33. protected void pack() {
  34. CBZip2OutputStream zOut = null;
  35. try {
  36. BufferedOutputStream bos =
  37. new BufferedOutputStream(new FileOutputStream(zipFile));
  38. bos.write('B');
  39. bos.write('Z');
  40. zOut = new CBZip2OutputStream(bos);
  41. zipFile(source, zOut);
  42. } catch (IOException ioe) {
  43. String msg = "Problem creating bzip2 " + ioe.getMessage();
  44. throw new BuildException(msg, ioe, getLocation());
  45. } finally {
  46. if (zOut != null) {
  47. try {
  48. // close up
  49. zOut.close();
  50. } catch (IOException e) {
  51. //ignore
  52. }
  53. }
  54. }
  55. }
  56. }