1. /*
  2. * Copyright 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.cvslib;
  18. import java.io.ByteArrayOutputStream;
  19. import java.io.IOException;
  20. import org.apache.tools.ant.BuildException;
  21. import org.apache.tools.ant.taskdefs.PumpStreamHandler;
  22. /**
  23. * A dummy stream handler that just passes stuff to the parser.
  24. *
  25. * @version $Revision: 1.13.2.4 $ $Date: 2004/03/09 17:01:40 $
  26. */
  27. class RedirectingStreamHandler
  28. extends PumpStreamHandler {
  29. RedirectingStreamHandler(final ChangeLogParser parser) {
  30. super(new RedirectingOutputStream(parser),
  31. new ByteArrayOutputStream());
  32. }
  33. String getErrors() {
  34. try {
  35. final ByteArrayOutputStream error
  36. = (ByteArrayOutputStream) getErr();
  37. return error.toString("ASCII");
  38. } catch (final Exception e) {
  39. return null;
  40. }
  41. }
  42. public void stop() {
  43. super.stop();
  44. try {
  45. getErr().close();
  46. getOut().close();
  47. } catch (final IOException e) {
  48. // plain impossible
  49. throw new BuildException(e);
  50. }
  51. }
  52. }