In MINA TRUNK, we've added support so that you can do IoSession.write(File) or IoSession.write(FileChannel) and it will use FileChannel.transferTo() to send the file to the remote host. This should be faster then reading the file manually because FileChannel.transferTo() can do zero-copy read/writes (it uses sendfile on Linux and other Unix platforms that support sendfile).
Look at this issues for more details: https://issues.apache.org/jira/browse/DIRMINA-218 It's new functionality that still needs additional testing and benchmarking. We currently don't have support for SSL or compression either (or any other IoFilter that mutates the ByteBuffer for that matter). If you wanted to look into that approach, I would appreciate the feedback. -Mike On Sun, 2007-08-05 at 23:05 -0700, leafsax wrote: > Hi, > I was trying to use MINA to transfer files between machines. It was pretty > good when I was trying to send some small files, but when the requests were > larger, (a file > 100M), I could not send the file correctly. Since I could > not send the file in just one ByteBuffer, I read some of the file and send, > then read the rest of the file and send. But, the file received is not equal > to the file sent by the server. The file length is correct, but the contents > were interleaved. > > The following is the code to send file in server side: > private void sendFile(IoSession session, String fileName) throws > FileNotFoundException { > byte[] buffer = new byte[1024]; > DataInputStream dis = new DataInputStream(new > FileInputStream(fileName)); > int bytesRead = 0; > try { > System.out.println("send file"); > while ((bytesRead = dis.read(buffer, 0, 1024)) > 0) { > session.write(ByteBuffer.wrap(buffer, 0, > bytesRead)); > } > } catch (IOException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > } > Some questions: > Is there any misuse of session and request in the code above? > Is there any good suggestions to do file or large request transfer in MINA? >
