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 java.nio.ByteBuffer |
buffer |
protected static int |
MIN_BUFFER_SIZE
Some minimum buffer size, particularly for longs and encoding UTF strings
efficiently.
|
bytesWritten, channel| Constructor and Description |
|---|
ChannelBufferUnsafeOutputStream(java.nio.channels.WritableByteChannel channel) |
ChannelBufferUnsafeOutputStream(java.nio.channels.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(java.nio.ByteBuffer buffer) |
java.nio.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(java.nio.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, isSocketToSameHost, setParkedThread, writeBuffer, writeBuffered, writeBufferNoWaitprotected java.nio.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(java.nio.channels.WritableByteChannel channel)
public ChannelBufferUnsafeOutputStream(java.nio.channels.WritableByteChannel channel,
int bufferSize)
public java.nio.ByteBuffer getInternalBuffer()
protected final void resetBufferPositions()
protected long allocateBuffer(int bufferSize)
public final void write(int b)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOExceptionprotected final void write_(byte[] b,
int off,
int len)
throws java.io.IOException
java.io.IOExceptionpublic final void write(@Nonnull
byte[] b)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOExceptionprotected final void putByte(byte b)
throws java.io.IOException
java.io.IOExceptionpublic final void write(@Nonnull
byte[] b,
int off,
int len)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOExceptionpublic final int write(java.nio.ByteBuffer src)
throws java.io.IOException
write in interface java.nio.channels.WritableByteChannelwrite in class OutputStreamChanneljava.io.IOExceptionpublic final void writeInt(int v)
throws java.io.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.java.io.IOException - if an I/O error occurs.DataOutput.writeInt(int)public final int position()
public void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.OutputStreamjava.io.IOExceptionpublic final boolean isOpen()
public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in interface java.nio.channels.Channelclose in class java.io.OutputStreamjava.io.IOExceptionprotected final void releaseBuffer()
public void closeChannel()
throws java.io.IOException
java.io.IOExceptionprotected void flushBufferBlocking(java.nio.ByteBuffer buffer)
throws java.io.IOException
java.io.IOExceptionprotected static long putInt(long addrPos,
int v)
Copyright © 2010-2015 Pivotal Software, Inc. All rights reserved.