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.

TaskOutputStream.java 3.1 kB

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