final class ByteBufferWriter
extends java.lang.Object
ByteBuffer
s to OutputStream
s.Modifier and Type | Field and Description |
---|---|
private static java.lang.ThreadLocal<java.lang.ref.SoftReference<byte[]>> |
BUFFER
Keeping a soft reference to a thread-local buffer.
|
private static float |
BUFFER_REALLOCATION_THRESHOLD
The fraction of the requested buffer size under which the buffer will be reallocated.
|
private static long |
CHANNEL_FIELD_OFFSET |
private static java.lang.Class<?> |
FILE_OUTPUT_STREAM_CLASS
This is a hack for GAE, where
FileOutputStream is unavailable. |
private static int |
MAX_CACHED_BUFFER_SIZE
Maximum size for a cached buffer.
|
private static int |
MIN_CACHED_BUFFER_SIZE
Minimum size for a cached buffer.
|
Modifier | Constructor and Description |
---|---|
private |
ByteBufferWriter() |
Modifier and Type | Method and Description |
---|---|
(package private) static void |
clearCachedBuffer()
For testing purposes only.
|
private static byte[] |
getBuffer() |
private static long |
getChannelFieldOffset(java.lang.Class<?> clazz) |
private static byte[] |
getOrCreateBuffer(int requestedSize) |
private static boolean |
needToReallocate(int requestedSize,
int bufferLength) |
private static java.lang.Class<?> |
safeGetClass(java.lang.String className) |
private static void |
setBuffer(byte[] value) |
(package private) static void |
write(java.nio.ByteBuffer buffer,
java.io.OutputStream output)
Writes the remaining content of the buffer to the given stream.
|
private static boolean |
writeToChannel(java.nio.ByteBuffer buffer,
java.io.OutputStream output) |
private static final int MIN_CACHED_BUFFER_SIZE
private static final int MAX_CACHED_BUFFER_SIZE
private static final float BUFFER_REALLOCATION_THRESHOLD
private static final java.lang.ThreadLocal<java.lang.ref.SoftReference<byte[]>> BUFFER
ByteBuffer
to an OutputStream
when no zero-copy alternative was available.
Using a "soft" reference since VMs may keep this reference around longer than "weak"
(e.g. HotSpot will maintain soft references until memory pressure warrants collection).private static final java.lang.Class<?> FILE_OUTPUT_STREAM_CLASS
FileOutputStream
is unavailable.private static final long CHANNEL_FIELD_OFFSET
static void clearCachedBuffer()
static void write(java.nio.ByteBuffer buffer, java.io.OutputStream output) throws java.io.IOException
position
will remain unchanged by this method.java.io.IOException
private static byte[] getOrCreateBuffer(int requestedSize)
private static boolean needToReallocate(int requestedSize, int bufferLength)
private static byte[] getBuffer()
private static void setBuffer(byte[] value)
private static boolean writeToChannel(java.nio.ByteBuffer buffer, java.io.OutputStream output) throws java.io.IOException
java.io.IOException
private static java.lang.Class<?> safeGetClass(java.lang.String className)
private static long getChannelFieldOffset(java.lang.Class<?> clazz)