Class ManagedBufferReader
- All Implemented Interfaces:
Closeable,AutoCloseable,Readable,InputConsumer
Reader that provides the data from the ManagedBuffers
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 TypeMethodDescriptionSets the charset to be used iffeed(ManagedBuffer)is invoked withManagedBuffer<ByteBuffer>.voidclose()Note that this is the
Reader’sclosemethod.<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.intread(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, transferToMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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
nullas 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:
feedin interfaceInputConsumer- Parameters:
buffer- the buffer- Throws:
IOException- Signals that an I/O exception has occurred.
-
close
Note that this is the
Reader’sclosemethod.In order to close the feed, call
feed(ManagedBuffer)withnullas argument.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classReader- Throws:
IOException
-
read
- Specified by:
readin classReader- Throws:
IOException
-
charset(Charset)instead