Package org.jboss.util.stream
Class NotifyingBufferedOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- java.io.BufferedOutputStream
-
- org.jboss.util.stream.NotifyingBufferedOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class NotifyingBufferedOutputStream extends java.io.BufferedOutputStream
A buffered output stream that notifies every "chunk"- Version:
- $Revision$
-
-
Field Summary
Fields Modifier and Type Field Description (package private) int
chunk
The number of bytes written in the current chunk(package private) int
chunkSize
The number of bytes between notifications(package private) StreamListener
listener
The listener notified every chunk
-
Constructor Summary
Constructors Constructor Description NotifyingBufferedOutputStream(java.io.OutputStream os, int size, int chunkSize, StreamListener listener)
Construct a notifying buffered outputstream.
The listener is notified once every chunk.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkNotification(int result)
Checks whether a notification is required and notifies as appropriatevoid
setStreamListener(StreamListener listener)
void
write(byte[] b, int off, int len)
void
write(int b)
-
-
-
Field Detail
-
chunkSize
int chunkSize
The number of bytes between notifications
-
chunk
int chunk
The number of bytes written in the current chunk
-
listener
StreamListener listener
The listener notified every chunk
-
-
Constructor Detail
-
NotifyingBufferedOutputStream
public NotifyingBufferedOutputStream(java.io.OutputStream os, int size, int chunkSize, StreamListener listener)
Construct a notifying buffered outputstream.
The listener is notified once every chunk.- Parameters:
os
- the output stream to be bufferedsize
- the buffer sizechunkSize
- the chunk sizelistener
-- Throws:
java.lang.IllegalArgumentException
- for a size <= 0 or chunkSize <= size or a null listener
-
-
Method Detail
-
setStreamListener
public void setStreamListener(StreamListener listener)
-
write
public void write(int b) throws java.io.IOException
- Overrides:
write
in classjava.io.BufferedOutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
write
in classjava.io.BufferedOutputStream
- Throws:
java.io.IOException
-
checkNotification
public void checkNotification(int result)
Checks whether a notification is required and notifies as appropriate- Parameters:
result
- the number of bytes written
-
-