code: public boolean fetch() throws IOException {
          if (limit == 0) {
              final int len = fin.read(buffer, 0, buffer.length);
              if (len >= 0) {
                  limit += len;
                  position = 0;
                  origin = 0;
  
                  /* More binlog to fetch */
                  return true;
              }
          } else if (origin == 0) {
              if (limit > buffer.length / 2) {
                  ensureCapacity(buffer.length + limit);
              }
              final int len = fin.read(buffer, limit, buffer.length - limit);
              if (len >= 0) {
                  limit += len;
  
                  /* More binlog to fetch */
                  return true;
              }
          } else if (limit > 0) {
              if (limit >= FormatDescriptionLogEvent.LOG_EVENT_HEADER_LEN) {
                  int lenPosition = position + 4 + 1 + 4;
                  long eventLen = ((long) (0xff & buffer[lenPosition++])) | ((long) (0xff & buffer[lenPosition++]) << 8)
                                  | ((long) (0xff & buffer[lenPosition++]) << 16)
                                  | ((long) (0xff & buffer[lenPosition++]) << 24);
  
                  if (limit >= eventLen) {
                      return true;
                  } else {
                      ensureCapacity((int) eventLen);
                  }
              }
  
              System.arraycopy(buffer, origin, buffer, 0, limit);
              position -= origin;
              origin = 0;
              final int len = fin.read(buffer, limit, buffer.length - limit);
              if (len >= 0) {
                  limit += len;
  
                  /* More binlog to fetch */
                  return true;
              }
          } else {
              /* Should not happen. */
              throw new IllegalArgumentException("Unexcepted limit: " + limit);
          }
  
          /* Reach binlog file end */
          return false;
      }
docs: {@inheritDoc}
  
  @see com.taobao.tddl.dbsync.binlog.LogFetcher#fetch()