Class ManagedBufferReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Readable
,InputConsumer
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
-
Method Summary
Modifier and TypeMethodDescriptionSets the charset to be used iffeed(ManagedBuffer)
is invoked withManagedBuffer<ByteBuffer>
.void
close()
Note that this is the
Reader
’sclose
method.<W extends Buffer>
voidfeed
(ManagedBuffer<W> buffer) Feed data to the reader.Sets the charset to be used iffeed(ManagedBuffer)
is invoked withManagedBuffer<ByteBuffer>
to the charset specified as system propertynative.encoding
.int
read
(char[] cbuf, int off, int len) setCharset
(Charset charset) Deprecated.Methods inherited from class java.io.Reader
mark, markSupported, nullReader, read, read, read, ready, reset, skip, transferTo
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.jgrapes.io.util.InputConsumer
feed
-
Constructor Details
-
ManagedBufferReader
public ManagedBufferReader()
-
-
Method Details
-
charset
Sets the charset to be used iffeed(ManagedBuffer)
is invoked withManagedBuffer<ByteBuffer>
.Defaults to UTF-8. Must be set before the first invocation of
feed(ManagedBuffer)
.- Parameters:
charset
- the charset- Returns:
- the managed buffer reader
-
setCharset
Deprecated.Usecharset(Charset)
insteadSets the charset to be used iffeed(ManagedBuffer)
is invoked withManagedBuffer<ByteBuffer>
.Defaults to UTF-8. Must be set before the first invocation of
feed(ManagedBuffer)
.- Parameters:
charset
- the charset- Returns:
- the managed buffer reader
-
nativeCharset
Sets the charset to be used iffeed(ManagedBuffer)
is invoked withManagedBuffer<ByteBuffer>
to the charset specified as system propertynative.encoding
.If this property does not specify a valid charset,
Charset.defaultCharset()
is used.Must be invoked before the first invocation of
feed(ManagedBuffer)
.- Returns:
- the managed buffer reader
-
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)
therefore return -1.- Specified by:
feed
in interfaceInputConsumer
- 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
-
charset(Charset)
instead