code: public static Collection<ByteBuffer> split(final ByteBuffer buffer,
              final int chunkSize) {
          final Collection<ByteBuffer> buffers = new LinkedList<ByteBuffer>();
          final int limit = buffer.limit();
  
          int totalSent = 0;
          while ((totalSent + chunkSize) < limit) {
              LOG.trace("Setting limit to: " + (totalSent + chunkSize));
              buffer.limit(totalSent + chunkSize);
              buffers.add(createBuffer(buffer));
              totalSent += chunkSize;
          }
  
          // Send any remaining bytes.
          buffer.limit(limit);
          buffers.add(createBuffer(buffer));
          return buffers;
      }
docs: Splits the specified <code>ByteBuffer</code> into smaller
  <code>ByteBuffer</code>s of the specified size. The remaining bytes in
  the buffer must be greater than the chunk size. This method will create
  smaller buffers of the specified size until there are fewer remaining
  bytes than the chunk size, when it will simply add a buffer the same size
  as the number of bytes remaining.
  
  @param buffer
  The <code>ByteBuffer</code> to split.
  @param chunkSize
  The size of the smaller buffers to create.
  @return A <code>Collection</code> of <code>ByteBuffer</code>s of the
  specified size. The final buffer in the <code>Collection</code>
  will have a size > 0 and <= the chunk size.