Package org.jppf.io
Class ChannelInputSource
java.lang.Object
org.jppf.io.ChannelInputSource
- All Implemented Interfaces:
Closeable,AutoCloseable,InputSource,IO
- Direct Known Subclasses:
FileInputSource
Input source backed by a
ReadableByteChannel.- Author:
- Laurent Cohen
-
Field Summary
FieldsFields inherited from interface org.jppf.io.IO
CHECK_LOW_MEMORY, EMPTY_BYTES, FREE_MEM_TO_SIZE_RATIO, GC_ON_DISK_OVERFLOW, LENGTH_BUFFER_POOL, LENGTH_BUFFER_POOL_SIZE, LOW_MEMORY_THRESHOLD, SOCKET_BUFFER_SIZE, SOCKET_KEEPALIVE, SOCKET_TCP_NODELAY, TEMP_BUFFER_POOL, TEMP_BUFFER_POOL_SIZE, TEMP_BUFFER_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionChannelInputSource(ReadableByteChannel channel) Initialize this input source with the specifiedSocketWrapper. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()This method does nothing.intread(byte[] data, int offset, int len) Read data from this input source into an array of bytes.intread(ByteBuffer data) Read data from this input source into a byte buffer.intreadInt()Read an int value from this input source.intskip(int n) Skipnbytes of data form this input source.toString()
-
Field Details
-
channel
The backingReadableByteChannel.
-
-
Constructor Details
-
ChannelInputSource
Initialize this input source with the specifiedSocketWrapper.- Parameters:
channel- the backingSocketWrapper.
-
-
Method Details
-
read
Read data from this input source into an array of bytes.- Specified by:
readin interfaceInputSource- Parameters:
data- the buffer into which to write.offset- the position in the buffer where to start storing the data.len- the size in bytes of the data to read.- Returns:
- the number of bytes actually read, or -1 if end of stream was reached.
- Throws:
Exception- if an IO error occurs.
-
read
Read data from this input source into a byte buffer.Implementation details:
We read the data by small chunks of maxIO.TEMP_BUFFER_SIZEbytes wrapped in a direct ByteBuffer, to work around the fact that Sun NIO implementation of SocketChannelImpl.read() attempts to allocate a direct buffer of the requested data size (i.e.data.remaining() in our case), if the destination ByteBuffer is not direct.
This implementation can result in a "OutOfMemoryError: Direct buffer space" when the size of the data to read is too large.
See Sun Bug ID: 4879883 for details.- Specified by:
readin interfaceInputSource- Parameters:
data- the buffer into which to write.- Returns:
- the number of bytes actually read, or -1 if end of stream was reached.
- Throws:
Exception- if an IO error occurs.
-
readInt
Read an int value from this input source.- Specified by:
readIntin interfaceInputSource- Returns:
- the value read, or -1 if an end of file condition was reached.
- Throws:
Exception- if an IO error occurs.
-
skip
Skipnbytes of data form this input source.- Specified by:
skipin interfaceInputSource- Parameters:
n- the number of bytes to skip.- Returns:
- the number of bytes actually skipped.
- Throws:
Exception- if an IO error occurs.
-
close
This method does nothing.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if an IO error occurs.
-
toString
-