1 19 20 package org.apache.tools.ant.module.spi; 21 22 import java.io.IOException ; 23 import java.io.OutputStream ; 24 import java.net.URL ; 25 import org.openide.filesystems.FileObject; 26 27 34 @Deprecated 35 public abstract class AntOutputStream extends OutputStream { 36 37 38 private StringBuffer buffer = new StringBuffer (1000); 39 40 private boolean hadFirst = false; 41 42 @Override 43 final public void close() throws IOException { 44 flush (); 45 handleClose(); 46 } 47 48 54 protected void handleClose() throws IOException { 55 } 56 57 @Override 58 final public void flush() throws IOException { 59 flushLines (true); 60 } 61 62 @Override 63 final public void write(byte[] b) throws IOException { 64 write (b, 0, b.length); 65 } 66 67 @Override 68 final public void write(byte[] b, int offset, int length) throws IOException { 69 buffer.append (new String (b, offset, length)); 70 flushLines (false); 72 } 73 74 @Override 75 final public void write(int b) throws IOException { 76 buffer.append ((char) b); 77 if ((char) b == '\n') { 78 flushLines (false); 79 } 80 } 81 82 private void flushLines (boolean flushEverything) throws IOException { 83 MAIN: 86 while (true) { 87 int len = buffer.length (); 88 for (int i = 0; i < len; i++) { 89 if (buffer.charAt (i) == '\n') { 90 int end = i; 93 if (end > 0 && buffer.charAt (end - 1) == '\r') { 94 end--; 95 } 96 flushLine (buffer.substring (0, end)); 97 buffer.delete (0, i + 1); 98 continue MAIN; 99 } 100 } 101 break MAIN; 103 } 104 if (flushEverything) { 105 flushLine(buffer.substring (0, buffer.length())); 106 buffer.delete(0, buffer.length()); 107 } 108 } 109 110 private void flushLine (String l) throws IOException { 111 if (! hadFirst) { 113 hadFirst = true; 114 if (l.trim ().length () == 0) { 116 return; 117 } 118 } 119 writeLine(l); 120 } 121 122 137 @Deprecated 138 protected boolean writeLine(String line, URL file, int line1, int col1, int line2, int col2, String message) throws IOException { 139 return false; 140 } 141 142 153 @Deprecated 154 protected void writeLine(String line, FileObject file, int line1, int col1, int line2, int col2, String message) throws IOException { 155 throw new IllegalStateException ("writeLine(...URL...) must return true if writeLine(...FileObject...) is not implemented"); } 157 158 160 abstract protected void writeLine(String line) throws IOException ; 161 162 165 @Deprecated 166 protected String formatMessage(String fileName, String message, int line1, int col1, int line2, int col2) { 167 return message; 168 } 169 170 } 171 | Popular Tags |