| 27 | } |
| 28 | |
| 29 | public void handleRead(SocketChannel channel) throws Exception { |
| 30 | int count = -1; |
| 31 | while ((count = channel.read(inBuf)) > 0) { |
| 32 | System.out.println(myIndex + ": read " + count); |
| 33 | } |
| 34 | inBuf.flip(); |
| 35 | fos.write(inBuf.array(), inBuf.arrayOffset()+inBuf.position(), inBuf.remaining()); |
| 36 | inBuf.position(inBuf.limit()); |
| 37 | if (count < 0) { |
| 38 | System.out.println(myIndex + ": Closing channel"); |
| 39 | fos.close(); |
| 40 | channel.close(); |
| 41 | } |
| 42 | // dumpByteBuffer(myIndex, inBuf); |
| 43 | inBuf.compact(); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | public void runMainLoop() throws Exception { |