How to implement buffered / batch FileChannel in Java?

This does not look trivial, especially for a buffered FileChannel for reading / writing. Is there anything, anything, something like opensource, somewhere on which I can base my implementation?


To be understood by those who did not understand:

FileChannel is doing OS level buffering and I want to do Java level buffering. Read here to understand: FileChannel # force and buffering


@Peter I want to write a huge file to disk from a stream of quick messages. Buffering and dosing is the way to go. So I want to execute the package in Java and then call FileChannel.write.

0
source share
3

FileChannel ByteBuffers, . ByteBuffer ByteBuffer, , .

FileChannel

FileChannel , . , FileChannel , .

Java

, .;) .

+3

BufferedOutputStream a FileOutputStream. , , ByteBuffer FileChannel, , .

: , , :

  • . , , . , Java .
  • . , , . . , , .
  • Java C, JNI. , Java. , , Java, ByteBuffer ( , ), . JNI ByteBuffer, .
  • fwrite, , C .
  • . , .

, , , , .

FileChannel force(), , №5. , , fsync , . , .

: , IO, , .

+3

I would have two threads, the producer thread created ByteBuffers and added them to the tail in the queue, the consumer thread each time removed some ByteBuffers from the queue head and called fileChannel.write (ByteBuffer []).

-1
source

Source: https://habr.com/ru/post/1677820/


All Articles