Package org.bluezoo.util
Class BufferingByteChannel
java.lang.Object
org.bluezoo.util.BufferingByteChannel
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,Channel,WritableByteChannel
A
WritableByteChannel decorator that buffers writes into a
fixed-size ByteBuffer before flushing to the underlying channel.
This reduces the number of blocking I/O syscalls when writing to
file-backed channels by accumulating small writes and flushing them
as larger chunks. The buffer is flushed automatically when full, or
explicitly via flush().
This is a pure NIO implementation with no InputStream or
OutputStream involvement.
- Author:
- Chris Burdess
-
Constructor Summary
ConstructorsConstructorDescriptionBufferingByteChannel(WritableByteChannel delegate, int bufferSize) Creates a buffering channel that wraps the given delegate. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidflush()booleanisOpen()intwrite(ByteBuffer src)
-
Constructor Details
-
BufferingByteChannel
Creates a buffering channel that wraps the given delegate.- Parameters:
delegate- the underlying channel to write tobufferSize- the buffer size in bytes
-
-
Method Details
-
write
- Specified by:
writein interfaceWritableByteChannel- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Throws:
IOException
-
isOpen
public boolean isOpen() -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-