Package jadex.commons
Class ListenableStream
- java.lang.Object
-
- java.io.OutputStream
-
- jadex.commons.ListenableStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class ListenableStream extends java.io.OutputStreamA stream that can be listened to.
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]bufferThe buffered bytes.protected intlenThe currently used length of the buffer.protected java.util.ListlistenersThe listeners.protected byte[]newlineThe code(s) of the newline character.protected java.io.OutputStreamoutThe super output stream.protected java.lang.StringtypeThe event type to be generated.
-
Constructor Summary
Constructors Constructor Description ListenableStream(java.io.OutputStream out, java.lang.String type)Create a new stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLineListener(IChangeListener listener)Add a line listener.voidclose()Close the streams.voidflush()Flush the streams.protected voidgenerateEvent()Generate an event for a line and flush the buffer.voidremoveLineListener(IChangeListener listener)Remove a line listener.voidwrite(int b)Write a byte to the stream.
-
-
-
Field Detail
-
out
protected java.io.OutputStream out
The super output stream.
-
type
protected java.lang.String type
The event type to be generated.
-
buffer
protected byte[] buffer
The buffered bytes.
-
len
protected int len
The currently used length of the buffer.
-
listeners
protected java.util.List listeners
The listeners.
-
newline
protected byte[] newline
The code(s) of the newline character.
-
-
Method Detail
-
write
public void write(int b) throws java.io.IOExceptionWrite a byte to the stream.- Specified by:
writein classjava.io.OutputStream- Parameters:
b- The byte.- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionClose the streams.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOExceptionFlush the streams.- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException
-
addLineListener
public void addLineListener(IChangeListener listener)
Add a line listener.
-
removeLineListener
public void removeLineListener(IChangeListener listener)
Remove a line listener.
-
generateEvent
protected void generateEvent()
Generate an event for a line and flush the buffer.
-
-