Package org.jgrapes.io.util
Class ManagedBufferReader
java.lang.Object
java.io.Reader
org.jgrapes.io.util.ManagedBufferReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Readable
A
Reader
that provides the data from the ManagedBuffer
s
fed to it to a consumer.This class is intended to be used as a pipe between two threads.
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Note that this is the
Reader
’sclose
method.void
feed
(ManagedBuffer<CharBuffer> buffer) Feed data to the reader.int
read
(char[] cbuf, int off, int len) Methods inherited from class java.io.Reader
mark, markSupported, nullReader, read, read, read, ready, reset, skip, transferTo
-
Constructor Details
-
ManagedBufferReader
public ManagedBufferReader()
-
-
Method Details
-
feed
Feed data to the reader.The call blocks while data from a previous invocation has not been fully read. The buffer passed as argument is locked (see
ManagedBuffer.lockBuffer()
) until all data has been read.Calling this method with
null
as argument closes the feed. After consuming any data still available from a previous invocation, further calls toread(char[], int, int)
return -1.- Parameters:
buffer
- the buffer- Throws:
IOException
- Signals that an I/O exception has occurred.
-
close
Note that this is the
Reader
’sclose
method.In order to close the feed, call
feed(ManagedBuffer)
withnull
as argument.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classReader
- Throws:
IOException
-
read
- Specified by:
read
in classReader
- Throws:
IOException
-