public class ChannelBufferUnsafeOutputStream extends OutputStreamChannel
ChannelBufferOutputStream
using internal unsafe class (~30% in raw single byte write calls).
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 close 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.
|
bytesWritten, channel, PARK_NANOS_MAX, parkedThread| Constructor and Description |
|---|
ChannelBufferUnsafeOutputStream(WritableByteChannel channel) |
ChannelBufferUnsafeOutputStream(WritableByteChannel channel,
int bufferSize) |
| Modifier and Type | Method and Description |
|---|---|
protected long |
allocateBuffer(int bufferSize) |
void |
close() |
void |
closeChannel()
Close the underlying channel in addition to flushing/clearing the buffer.
|
void |
flush() |
protected void |
flushBufferBlocking(ByteBuffer buffer) |
ByteBuffer |
getInternalBuffer()
Get handle to the underlying ByteBuffer.
|
boolean |
isOpen() |
int |
position() |
protected void |
putByte(byte b) |
protected static long |
putInt(long addrPos,
int v)
Write an integer in big-endian format on given off-heap address.
|
protected void |
releaseBuffer() |
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) |
void |
writeInt(int v)
Writes an
int value, which is comprised of four bytes,
to the output stream in big-endian format
compatible with DataOutput.writeInt(int). |
flushBufferNonBlockingBase, getBytesWritten, getParkedThread, getParkNanosMax, getUnderlyingChannel, writeBuffer, writeBuffered, writeBufferNonBlockingprotected ByteBuffer buffer
protected final long baseAddress
protected long addrPosition
protected long addrLimit
protected static final int MIN_BUFFER_SIZE
ChannelBufferUnsafeDataOutputStream.writeUTF(String) carefully.public ChannelBufferUnsafeOutputStream(WritableByteChannel channel)
public ChannelBufferUnsafeOutputStream(WritableByteChannel channel, int bufferSize)
public ByteBuffer getInternalBuffer()
protected final void resetBufferPositions()
protected long 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(@Nonnull byte[] b) throws IOException
write in class OutputStreamIOExceptionprotected final void putByte(byte b)
throws IOException
IOExceptionpublic final void write(@Nonnull 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 final void writeInt(int v)
throws IOException
int value, which is comprised of four bytes,
to the output stream in big-endian format
compatible with DataOutput.writeInt(int).writeInt in class OutputStreamChannelv - the int value to be written.IOException - if an I/O error occurs.DataOutput.writeInt(int)public final int position()
public 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 final void releaseBuffer()
public void closeChannel()
throws IOException
IOExceptionprotected void flushBufferBlocking(ByteBuffer buffer) throws IOException
IOExceptionprotected static long putInt(long addrPos,
int v)
Copyright © 2010-2015 Pivotal Software, Inc. All rights reserved.