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

DelegatingOutputStream.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*******************************************************************************
  2. * Copyright (c) 2005 IBM Corporation and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v 2.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  7. *
  8. * Contributors:
  9. * Matthew Webster - initial implementation
  10. *******************************************************************************/
  11. package org.aspectj.tools.ajc;
  12. import java.io.IOException;
  13. import java.io.OutputStream;
  14. import java.util.LinkedList;
  15. import java.util.List;
  16. public class DelegatingOutputStream extends OutputStream {
  17. private boolean verbose = true;
  18. private OutputStream target;
  19. private List delegates;
  20. public DelegatingOutputStream (OutputStream os) {
  21. this.target = os;
  22. this.delegates = new LinkedList();
  23. }
  24. public void close() throws IOException {
  25. target.close();
  26. for (Object o : delegates) {
  27. OutputStream delegate = (OutputStream) o;
  28. delegate.close();
  29. }
  30. }
  31. public void flush() throws IOException {
  32. target.flush();
  33. for (Object o : delegates) {
  34. OutputStream delegate = (OutputStream) o;
  35. delegate.flush();
  36. }
  37. }
  38. public void write(byte[] b, int off, int len) throws IOException {
  39. if (verbose) target.write(b, off, len);
  40. for (Object o : delegates) {
  41. OutputStream delegate = (OutputStream) o;
  42. delegate.write(b, off, len);
  43. }
  44. }
  45. public void write(byte[] b) throws IOException {
  46. if (verbose) target.write(b);
  47. for (Object o : delegates) {
  48. OutputStream delegate = (OutputStream) o;
  49. delegate.write(b);
  50. }
  51. }
  52. public void write(int b) throws IOException {
  53. if (verbose) target.write(b);
  54. for (Object o : delegates) {
  55. OutputStream delegate = (OutputStream) o;
  56. delegate.write(b);
  57. }
  58. }
  59. public boolean add (OutputStream delegate) {
  60. return delegates.add(delegate);
  61. }
  62. public boolean remove (OutputStream delegate) {
  63. return delegates.remove(delegate);
  64. }
  65. public boolean isVerbose() {
  66. return verbose;
  67. }
  68. public void setVerbose(boolean verbose) {
  69. this.verbose = verbose;
  70. }
  71. }