public class ChannelBufferUnsafeInputStream extends InputStreamChannel
ChannelBufferInputStream
using internal unsafe class (~30% in raw read calls). Use this only when
UnsafeHolder.getDirectByteBufferAddressMethod() returns non-null.
Alternatively use UnsafeHolder.newChannelBufferInputStream(java.nio.channels.ReadableByteChannel, int) method to
create either this or ChannelBufferInputStream depending on
availability.
Note that the close() method of this class does not closing the underlying channel.
| Modifier and Type | Field and Description |
|---|---|
protected long |
addrLimit |
protected long |
addrPosition
Actual buffer position (+baseAddress) accounting is done by this.
|
protected long |
baseAddress |
protected ByteBuffer |
buffer |
protected static sun.misc.Unsafe |
unsafe |
channel, PARK_NANOS, PARK_NANOS_MAX, parkedThread| Constructor and Description |
|---|
ChannelBufferUnsafeInputStream(ReadableByteChannel channel) |
ChannelBufferUnsafeInputStream(ReadableByteChannel channel,
int bufferSize) |
| Modifier and Type | Method and Description |
|---|---|
protected ByteBuffer |
allocateBuffer(int bufferSize) |
int |
available() |
void |
close() |
protected int |
getInt(long addrPos) |
boolean |
isOpen() |
int |
read() |
int |
read(byte[] buf) |
int |
read(byte[] buf,
int off,
int len)
/**
|
int |
read(ByteBuffer dst) |
int |
readInt()
Reads four input bytes and returns an
int value. |
protected int |
refillBuffer(ByteBuffer channelBuffer,
int tryReadBytes,
String eofMessage) |
protected void |
resetBufferPositions() |
getParkedThread, getUnderlyingChannel, readBuffered, readFrame, readFrameFragment, readIntoBuffer, readIntoBufferNonBlocking, resetAndCopyLeftOverBytesmark, markSupported, reset, skipprotected final ByteBuffer buffer
protected final long baseAddress
protected long addrPosition
protected long addrLimit
protected static final sun.misc.Unsafe unsafe
public ChannelBufferUnsafeInputStream(ReadableByteChannel channel) throws IOException
IOExceptionpublic ChannelBufferUnsafeInputStream(ReadableByteChannel channel, int bufferSize) throws IOException
IOExceptionprotected final void resetBufferPositions()
protected ByteBuffer allocateBuffer(int bufferSize)
public final int read()
throws IOException
read in class InputStreamIOExceptionpublic final int read(byte[] buf)
throws IOException
read in class InputStreamIOExceptionpublic final int read(ByteBuffer dst) throws IOException
read in interface ReadableByteChannelread in class InputStreamChannelIOExceptionpublic final int read(byte[] buf,
int off,
int len)
throws IOException
read in class InputStreamIOExceptionpublic final int readInt()
throws IOException
int value. Let
a-d be the first through fourth bytes read. The value returned
is:
(((a & 0xff) << 24) | ((b & 0xff) << 16) |
((c & 0xff) << 8) | (d & 0xff))
This method is suitable for reading bytes written by the
writeInt method of interface DataOutput.readInt in class InputStreamChannelint value read.EOFException - if this stream reaches the end before reading all the bytes.IOException - if an I/O error occurs.protected final int getInt(long addrPos)
public final int available()
throws IOException
available in class InputStreamIOExceptionprotected int refillBuffer(ByteBuffer channelBuffer, int tryReadBytes, String eofMessage) throws IOException
refillBuffer in class InputStreamChannelIOExceptionpublic final boolean isOpen()
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in interface Channelclose in class InputStreamIOExceptionCopyright © 2010-2015 Pivotal Software, Inc. All rights reserved.