title: java NIO file upload, packet loss
body: <p>Code first</p>
  <pre class="lang-java prettyprint-override"><code>ByteBuffer readBuffer = ByteBuffer.allocate(requestSize);// here is 1024*1024*1024 = 1G
  readBuffer.clear();
  
  SocketChannel socketChannel = (SocketChannel) selectionKey.channel();
  
  while (socketChannel.read(readBuffer)&gt; 0) {}
  
  /* Get request message */
  readBuffer.flip();
  byte[] bytes = new byte[readBuffer.limit()];
  readBuffer.get(bytes);
  </code></pre>
  <p>As shown in the code above, the capacity of the buffer ByteBuffer is set to 1G, but uploading a file of about 30M often results in packet loss, resulting in incomplete files, and then an error is reported during formData parsing.</p>
  <p>If the capacity of this buffer is much larger than the file, there is no problem at all, but I cannot set the buffer too large, otherwise the heap will overflow.</p>
  <p>Please give pointers to those who are familiar with NIO</p>