public class ChannelBufferUnsafeOutputStream extends OutputStreamChannel
ChannelBufferOutputStream
using internal unsafe class (~30% in raw single byte write calls). Use this
only when UnsafeHolder.getDirectByteBufferAddressMethod() returns
non-null. Alternatively use UnsafeHolder.newChannelBufferOutputStream(java.nio.channels.WritableByteChannel, int)
method to create either this or ChannelBufferOutputStream depending
on availability.
NOTE: THIS CLASS IS NOT THREAD-SAFE BY DESIGN. IF IT IS USED CONCURRENTLY BY MULTIPLE THREADS THEN BAD THINGS CAN HAPPEN DUE TO UNSAFE MEMORY WRITES.
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 int |
MIN_BUFFER_SIZE
Some minimum buffer size, particularly for longs and encoding UTF strings
efficiently.
|
protected static sun.misc.Unsafe |
unsafe |
channel, PARK_NANOS, PARK_NANOS_MAX, parkedThread| Constructor and Description |
|---|
ChannelBufferUnsafeOutputStream(WritableByteChannel channel) |
ChannelBufferUnsafeOutputStream(WritableByteChannel channel,
int bufferSize) |
| Modifier and Type | Method and Description |
|---|---|
protected ByteBuffer |
allocateBuffer(int bufferSize) |
void |
close() |
void |
flush() |
protected void |
flushBufferBlocking(ByteBuffer buffer) |
protected boolean |
flushBufferNonBlocking(ByteBuffer buffer,
boolean isChannelBuffer) |
boolean |
isOpen() |
protected void |
resetBufferPositions() |
protected void |
write_(byte[] b,
int off,
int len) |
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
int |
write(ByteBuffer src) |
void |
write(int b) |
getParkedThread, getUnderlyingChannel, writeBuffer, writeBuffered, writeBufferNonBlockingprotected final ByteBuffer buffer
protected final long baseAddress
protected long addrPosition
protected long addrLimit
protected static final sun.misc.Unsafe unsafe
protected static final int MIN_BUFFER_SIZE
ChannelBufferUnsafeDataOutputStream.writeUTF(String) carefully.public ChannelBufferUnsafeOutputStream(WritableByteChannel channel) throws IOException
IOExceptionpublic ChannelBufferUnsafeOutputStream(WritableByteChannel channel, int bufferSize) throws IOException
IOExceptionprotected final void resetBufferPositions()
protected ByteBuffer allocateBuffer(int bufferSize)
public final void write(int b)
throws IOException
write in class OutputStreamIOExceptionprotected final void write_(byte[] b,
int off,
int len)
throws IOException
IOExceptionpublic final void write(byte[] b)
throws IOException
write in class OutputStreamIOExceptionpublic final void write(byte[] b,
int off,
int len)
throws IOException
write in class OutputStreamIOExceptionpublic final int write(ByteBuffer src) throws IOException
write in interface WritableByteChannelwrite in class OutputStreamChannelIOExceptionpublic void flush()
throws IOException
flush in interface Flushableflush in class OutputStreamIOExceptionpublic final boolean isOpen()
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in interface Channelclose in class OutputStreamIOExceptionprotected void flushBufferBlocking(ByteBuffer buffer) throws IOException
IOExceptionprotected boolean flushBufferNonBlocking(ByteBuffer buffer, boolean isChannelBuffer) throws IOException
flushBufferNonBlocking in class OutputStreamChannelIOExceptionCopyright © 2010-2015 Pivotal Software, Inc. All rights reserved.