code: public int occurrences(byte[] bytes) {
          if (bytes.length == 0) {
              return -1;
          }
          int occurrences = 0;
          int currentPos = -1;
          int offset = 0;
          while (offset < size()) {
              // search for the delimiter
              currentPos = indexOf(bytes, offset);
              if (currentPos < 0) {
                  break;
              }
              occurrences++;
              offset = currentPos + bytes.length;
          }
          return occurrences;
      }
docs: Counts the number of occurrences of the byte array in this
  <code>ByteBuffer</code>. This method will not overlap any bytes during its
  search. For example, if you're search for bytes of "AA" in a buffer containing "AAA", this
  method will only return a value of 1.
  @param bytes The byte[] to search for
  @return -1 if bytes is a length of zero, otherwise the number of occurrences.