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.OutputStream
A stream that can be listened to.
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]
buffer
The buffered bytes.protected int
len
The currently used length of the buffer.protected java.util.List
listeners
The listeners.protected byte[]
newline
The code(s) of the newline character.protected java.io.OutputStream
out
The super output stream.protected java.lang.String
type
The 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 void
addLineListener(IChangeListener listener)
Add a line listener.void
close()
Close the streams.void
flush()
Flush the streams.protected void
generateEvent()
Generate an event for a line and flush the buffer.void
removeLineListener(IChangeListener listener)
Remove a line listener.void
write(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.IOException
Write a byte to the stream.- Specified by:
write
in classjava.io.OutputStream
- Parameters:
b
- The byte.- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
Close the streams.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
Flush the streams.- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in 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.
-
-