Methods Summary |
---|
public void | close()Equivalent to flushing the stream.
flush();
removeBuffer();
|
public void | flush()Writes all remaining data in the buffer associated
with the current thread to the project.
BufferInfo bufferInfo = getBufferInfo();
if (bufferInfo.buffer.size() > 0) {
processFlush(bufferInfo.buffer);
}
|
private org.apache.tools.ant.DemuxOutputStream$BufferInfo | getBufferInfo()Returns the buffer associated with the current thread.
Thread current = Thread.currentThread();
BufferInfo bufferInfo = (BufferInfo) buffers.get(current);
if (bufferInfo == null) {
bufferInfo = new BufferInfo();
bufferInfo.buffer = new ByteArrayOutputStream(INTIAL_SIZE);
bufferInfo.crSeen = false;
buffers.put(current, bufferInfo);
}
return bufferInfo;
|
protected void | processBuffer(java.io.ByteArrayOutputStream buffer)Converts the buffer to a string and sends it to the project.
String output = buffer.toString();
project.demuxOutput(output, isErrorStream);
resetBufferInfo();
|
protected void | processFlush(java.io.ByteArrayOutputStream buffer)Converts the buffer to a string and sends it to the project.
String output = buffer.toString();
project.demuxFlush(output, isErrorStream);
resetBufferInfo();
|
private void | removeBuffer()Removes the buffer for the current thread.
Thread current = Thread.currentThread();
buffers.remove (current);
|
private void | resetBufferInfo()Resets the buffer for the current thread.
Thread current = Thread.currentThread();
BufferInfo bufferInfo = (BufferInfo) buffers.get(current);
try {
bufferInfo.buffer.close();
} catch (IOException e) {
// Shouldn't happen
}
bufferInfo.buffer = new ByteArrayOutputStream();
bufferInfo.crSeen = false;
|
public void | write(byte[] b, int off, int len)Write a block of characters to the output stream
// find the line breaks and pass other chars through in blocks
int offset = off;
int blockStartOffset = offset;
int remaining = len;
BufferInfo bufferInfo = getBufferInfo();
while (remaining > 0) {
while (remaining > 0 && b[offset] != LF && b[offset] != CR) {
offset++;
remaining--;
}
// either end of buffer or a line separator char
int blockLength = offset - blockStartOffset;
if (blockLength > 0) {
bufferInfo.buffer.write(b, blockStartOffset, blockLength);
}
while (remaining > 0 && (b[offset] == LF || b[offset] == CR)) {
write(b[offset]);
offset++;
remaining--;
}
blockStartOffset = offset;
}
|
public void | write(int cc)Writes the data to the buffer and flushes the buffer if a line
separator is detected or if the buffer has reached its maximum size.
final byte c = (byte) cc;
BufferInfo bufferInfo = getBufferInfo();
if (c == '\n") {
// LF is always end of line (i.e. CRLF or single LF)
bufferInfo.buffer.write(cc);
processBuffer(bufferInfo.buffer);
} else {
if (bufferInfo.crSeen) {
// CR without LF - send buffer then add char
processBuffer(bufferInfo.buffer);
}
// add into buffer
bufferInfo.buffer.write(cc);
}
bufferInfo.crSeen = (c == '\r");
if (!bufferInfo.crSeen && bufferInfo.buffer.size() > MAX_SIZE) {
processBuffer(bufferInfo.buffer);
}
|