Code example for BufferOverflowException

0
 
    try 
    { 
      if (buffer.remaining() < b.length())
      { 
        throw new BufferOverflowException();
      } 
 
      final int pos = buffer.position();
      buffer.put(b.getBackingArray(), 0, b.length());
      buffer.limit(buffer.position());
      buffer.position(pos);
    } 
    finally 
    { 
      if (b.capacity() > MAX_BUFFER_LENGTH)
      { 
        b.setCapacity(MAX_BUFFER_LENGTH);
      } 
      b.clear();
    }