On Mar 2, 2009, at 2:03 PM, Benjamin WATINE - Logixys wrote:
Thomas Harning Jr. a écrit :
For very large files, I would suggest taking advantage of IoBuffers
wrapping NIO buffers that are MemMapped views of the file. If you run
into a file that cannot be memmapped and for the case where the file
needs to be sent in chunks... I would setup a filter/codec that
progressively sends out chunks as completion events are made.
As an aside, does anyone know if Java provides for emulating MemMapped files when the underlying OS says no (ex: certain filesystems in Linux
don't implement memmapping)

First, sorry for the late answer, I didn't find time to work on it before.

So you mean that just using IoBuffer (in direct mode I suppose) will do the job ? Great news ! But I'm not familiar with java buffers. So I'm trying to send a simple file to a server, and write it back to a file.

The client side (that send the file) seems to work fine, but I don't know how to implement the server side (that receive the stream, and write it to fs using IoBuffer.

My code on the client side :

 FileInputStream fis = new FileInputStream(path);
 FileChannel fc = fis.getChannel();
 ByteBuffer fb = ByteBuffer.allocate( 1024 * 15 );
 fc.read(fb);
 fb.flip();
 IoBuffer fiob = IoBuffer.wrap(fb);
 session.write(fiob);

Is it a good way to do this ?
I was intending that you use the file in memory-mapped fashion and directly send that out. That way you don't have to manually pipe the data from file to buffer to Mina.

MappedByteBuffer is what you'd want to use.  Example call would be:
MappedByteBuffer fb = fc.map(FileChannel.MapMode.READ_ONLY, 0, length-of-file); /* If file longer than address space, map it progressively */

Not 100% sure how we'd handle writing this out and managing file freeing... my guess is that you'd have to add some sort of on-sent event.


For the server, in the handler.messageReceived() function, I try to cast the message to an IoBuffer, but it's probably not a good way. It returns cast error from String (why ?) to IoBuffer. How can I do this ? A ByteBuffer that I wrap in a IoBuffer ? A piece of code showing this would be greatly appreciated :)
Haven't written either of these code items yet... its on the roadmap for a product I'm working on... but way down the line.


Thanks Emmanuel for the pointer to FtpServer, but it's too heavy for my project. I need a very simple filetransfer implementation.

Reply via email to