Top Description Inners Fields Constructors Methods
org.apache.tools.ant

public Class DemuxOutputStream

extends OutputStream
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .IOException, .OutputStream, java.util.WeakHashMap, org.apache.tools.ant.util.FileUtils

Logs content written by a thread and forwards the buffers onto the project object which will forward the content to the appropriate task.
Since
1.4

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
DemuxOutputStream.BufferInfo

A data class to store information about a buffer.

Field Summary

Modifier and TypeField and Description
private WeakHashMap<Thread, DemuxOutputStream.BufferInfo>
buffers

Mapping from thread to buffer (Thread to BufferInfo).

private static final int
CR

Carriage return

private static final int
INITIAL_SIZE

Initial buffer size.

private boolean
isErrorStream

Whether or not this stream represents an error stream.

private static final int
LF

Linefeed

private static final int
MAX_SIZE

Maximum buffer size.

private Project
project

The project to send output to.

Constructor Summary

AccessConstructor and Description
public
DemuxOutputStream(Project
The project instance for which output is being demultiplexed. Must not be null.
project
,
boolean
true if this is the error string, otherwise a normal output stream. This is passed to the project so it knows which stream it is receiving.
isErrorStream
)

Creates a new instance of this class.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Equivalent to flushing the stream.
public void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Writes all remaining data in the buffer associated with the current thread to the project.
private DemuxOutputStream.BufferInfo

Returns:

a BufferInfo for the current thread to write data to
getBufferInfo
()

Returns the buffer associated with the current thread.

protected void
processBuffer(ByteArrayOutputStream
the ByteArrayOutputStream used to collect the output until a line separator is seen.
buffer
)

Converts the buffer to a string and sends it to the project.

protected void
processFlush(ByteArrayOutputStream
the ByteArrayOutputStream used to collect the output until a line separator is seen.
buffer
)

Converts the buffer to a string and sends it to the project.

private void
removeBuffer()

Removes the buffer for the current thread.

private void
resetBufferInfo()

Resets the buffer for the current thread.

public void
write(int
data to log (byte).
cc
)

Implements abstract java.io.OutputStream.write.

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.
public void
write(byte[]
the array containing the data
b
,
int
the offset into the array where data starts
off
,
int
the length of block
len
)

Overrides java.io.OutputStream.write.

Write a block of characters to the output stream
Inherited from java.io.OutputStream:
nullOutputStreamwrite

Field Detail

buffersback to summary
private WeakHashMap<Thread, DemuxOutputStream.BufferInfo> buffers

Mapping from thread to buffer (Thread to BufferInfo).

CRback to summary
private static final int CR

Carriage return

INITIAL_SIZEback to summary
private static final int INITIAL_SIZE

Initial buffer size.

isErrorStreamback to summary
private boolean isErrorStream

Whether or not this stream represents an error stream.

LFback to summary
private static final int LF

Linefeed

MAX_SIZEback to summary
private static final int MAX_SIZE

Maximum buffer size.

projectback to summary
private Project project

The project to send output to.

Constructor Detail

DemuxOutputStreamback to summary
public DemuxOutputStream(Project project, boolean isErrorStream)

Creates a new instance of this class.

Parameters
project:Project

The project instance for which output is being demultiplexed. Must not be null.

isErrorStream:boolean

true if this is the error string, otherwise a normal output stream. This is passed to the project so it knows which stream it is receiving.

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Equivalent to flushing the stream.

Annotations
@Override
Exceptions
IOException:
if there is a problem closing the stream.
See Also
flush
flushback to summary
public void flush() throws IOException

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Writes all remaining data in the buffer associated with the current thread to the project.

Annotations
@Override
Exceptions
IOException:
if there is a problem flushing the stream.
getBufferInfoback to summary
private DemuxOutputStream.BufferInfo getBufferInfo()

Returns the buffer associated with the current thread.

Returns:DemuxOutputStream.BufferInfo

a BufferInfo for the current thread to write data to

processBufferback to summary
protected void processBuffer(ByteArrayOutputStream buffer)

Converts the buffer to a string and sends it to the project.

Parameters
buffer:ByteArrayOutputStream

the ByteArrayOutputStream used to collect the output until a line separator is seen.

See Also
Project#demuxOutput(String, boolean)
processFlushback to summary
protected void processFlush(ByteArrayOutputStream buffer)

Converts the buffer to a string and sends it to the project.

Parameters
buffer:ByteArrayOutputStream

the ByteArrayOutputStream used to collect the output until a line separator is seen.

See Also
Project#demuxOutput(String, boolean)
removeBufferback to summary
private void removeBuffer()

Removes the buffer for the current thread.

resetBufferInfoback to summary
private void resetBufferInfo()

Resets the buffer for the current thread.

writeback to summary
public void write(int cc) throws IOException

Implements abstract java.io.OutputStream.write.

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.

Parameters
cc:int

data to log (byte).

Annotations
@Override
Exceptions
IOException:
if the data cannot be written to the stream
writeback to summary
public void write(byte[] b, int off, int len) throws IOException

Overrides java.io.OutputStream.write.

Write a block of characters to the output stream

Parameters
b:byte[]

the array containing the data

off:int

the offset into the array where data starts

len:int

the length of block

Annotations
@Override
Exceptions
IOException:
if the data cannot be written into the stream.
org.apache.tools.ant back to summary

private Class DemuxOutputStream.BufferInfo

extends Object
Class Inheritance

A data class to store information about a buffer. Such information is stored on a per-thread basis.

Field Summary

Modifier and TypeField and Description
private ByteArrayOutputStream
buffer

The per-thread output stream.

private boolean
crSeen

Indicates we have just seen a carriage return.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferback to summary
private ByteArrayOutputStream buffer

The per-thread output stream.

crSeenback to summary
private boolean crSeen

Indicates we have just seen a carriage return. It may be part of a crlf pair or a single cr invoking processBuffer twice.

Constructor Detail

BufferInfoback to summary
private BufferInfo()