1. /*
  2. * Copyright 2000,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.IOException;
  19. import java.io.OutputStream;
  20. import org.apache.tools.ant.Task;
  21. /**
  22. * Redirects text written to a stream thru the standard
  23. * ant logging mechanism. This class is useful for integrating
  24. * with tools that write to System.out and System.err. For example,
  25. * the following will cause all text written to System.out to be
  26. * logged with "info" priority:
  27. * <pre>System.setOut(new PrintStream(new TaskOutputStream(project, Project.MSG_INFO)));</pre>
  28. *
  29. * <p><strong>As of Ant 1.2, this class is considered to be dead code
  30. * by the Ant developers and is unmaintained. Don't use
  31. * it.</strong></p>
  32. *
  33. * @deprecated use LogOutputStream instead.
  34. */
  35. public class TaskOutputStream extends OutputStream {
  36. private Task task;
  37. private StringBuffer line;
  38. private int msgOutputLevel;
  39. /**
  40. * Constructs a new JavacOutputStream with the given project
  41. * as the output source for messages.
  42. */
  43. TaskOutputStream(Task task, int msgOutputLevel) {
  44. System.err.println("As of Ant 1.2 released in October 2000, the "
  45. + "TaskOutputStream class");
  46. System.err.println("is considered to be dead code by the Ant "
  47. + "developers and is unmaintained.");
  48. System.err.println("Don\'t use it!");
  49. this.task = task;
  50. this.msgOutputLevel = msgOutputLevel;
  51. line = new StringBuffer();
  52. }
  53. /**
  54. * Write a character to the output stream. This method looks
  55. * to make sure that there isn't an error being reported and
  56. * will flush each line of input out to the project's log stream.
  57. */
  58. public void write(int c) throws IOException {
  59. char cc = (char) c;
  60. if (cc == '\r' || cc == '\n') {
  61. // line feed
  62. if (line.length() > 0) {
  63. processLine();
  64. }
  65. } else {
  66. line.append(cc);
  67. }
  68. }
  69. /**
  70. * Processes a line of input and determines if an error occurred.
  71. */
  72. private void processLine() {
  73. String s = line.toString();
  74. task.log(s, msgOutputLevel);
  75. line = new StringBuffer();
  76. }
  77. }