public class ChannelBufferUnsafeInputStream extends InputStreamChannel
ChannelBufferInputStream
using internal unsafe class (~30% in raw read calls).
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 java.nio.ByteBuffer |
buffer |
bytesRead, channel| Constructor and Description |
|---|
ChannelBufferUnsafeInputStream(java.nio.channels.ReadableByteChannel channel) |
ChannelBufferUnsafeInputStream(java.nio.channels.ReadableByteChannel channel,
int bufferSize) |
| Modifier and Type | Method and Description |
|---|---|
protected java.nio.ByteBuffer |
allocateBuffer(int bufferSize) |
int |
available() |
void |
close() |
boolean |
isOpen() |
int |
read() |
int |
read(byte[] buf) |
int |
read(byte[] buf,
int off,
int len) |
int |
read(java.nio.ByteBuffer dst) |
int |
readInt()
Reads four input bytes and returns an
int value. |
protected int |
refillBuffer(java.nio.ByteBuffer channelBuffer,
int tryReadBytes,
java.lang.String eofMessage) |
protected void |
resetBufferPositions() |
getBytesRead, getParkedThread, getParkNanosMax, getUnderlyingChannel, readBuffered, readFrame, readFrameFragment, readIntoBuffer, readIntoBufferNoWait, refillBufferBase, resetAndCopyLeftOverBytes, setParkedThreadprotected java.nio.ByteBuffer buffer
protected final long baseAddress
protected long addrPosition
protected long addrLimit
public ChannelBufferUnsafeInputStream(java.nio.channels.ReadableByteChannel channel)
public ChannelBufferUnsafeInputStream(java.nio.channels.ReadableByteChannel channel,
int bufferSize)
protected final void resetBufferPositions()
protected java.nio.ByteBuffer allocateBuffer(int bufferSize)
public final int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic final int read(@Nonnull
byte[] buf)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic final int read(@Nonnull
byte[] buf,
int off,
int len)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic final int read(java.nio.ByteBuffer dst)
throws java.io.IOException
read in interface java.nio.channels.ReadableByteChannelread in class InputStreamChanneljava.io.IOExceptionpublic final int readInt()
throws java.io.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.java.io.EOFException - if this stream reaches the end before reading all the bytes.java.io.IOException - if an I/O error occurs.public final int available()
available in class java.io.InputStreamprotected int refillBuffer(java.nio.ByteBuffer channelBuffer,
int tryReadBytes,
java.lang.String eofMessage)
throws java.io.IOException
refillBuffer in class InputStreamChanneljava.io.IOExceptionpublic final boolean isOpen()
public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in interface java.nio.channels.Channelclose in class java.io.InputStreamCopyright © 2010-2015 Pivotal Software, Inc. All rights reserved.