Package org.jboss.util.stream
Class NotifyingBufferedInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- java.io.BufferedInputStream
-
- org.jboss.util.stream.NotifyingBufferedInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class NotifyingBufferedInputStream extends java.io.BufferedInputStream
A buffered input stream that notifies every "chunk"- Version:
- $Revision$
-
-
Field Summary
Fields Modifier and Type Field Description (package private) int
chunk
The number of bytes read 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 NotifyingBufferedInputStream(java.io.InputStream is, int size, int chunkSize, StreamListener listener)
Construct a notifying buffered inputstream.
-
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 appropriateint
read()
int
read(byte[] b, int off, int len)
void
setStreamListener(StreamListener listener)
-
Methods inherited from class java.io.BufferedInputStream
available, close, mark, markSupported, reset, skip
-
-
-
-
Field Detail
-
chunkSize
int chunkSize
The number of bytes between notifications
-
chunk
int chunk
The number of bytes read in the current chunk
-
listener
StreamListener listener
The listener notified every chunk
-
-
Constructor Detail
-
NotifyingBufferedInputStream
public NotifyingBufferedInputStream(java.io.InputStream is, int size, int chunkSize, StreamListener listener)
Construct a notifying buffered inputstream. The listener is notified once every chunk.- Parameters:
is
- the input stream to be bufferedsize
- the buffer sizechunkSize
- the chunk sizelistener
- the listener to notify- Throws:
java.lang.IllegalArgumentException
- for a size <= 0 or chunkSize <= size
-
-
Method Detail
-
setStreamListener
public void setStreamListener(StreamListener listener)
-
read
public int read() throws java.io.IOException
- Overrides:
read
in classjava.io.BufferedInputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
read
in classjava.io.BufferedInputStream
- 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 read
-
-