Read OK_Packet.

@param buffer  current buffer
@param results result object
@see <a href="https://mariadb.com/kb/en/mariadb/ok_packet/">OK_Packet</a>
324148
private void readOkPacket(Buffer buffer, Results results) {
    buffer.skipByte(); //fieldCount
    final long updateCount = buffer.getLengthEncodedNumeric();
    final long insertId = buffer.getLengthEncodedNumeric();

    serverStatus = buffer.readShort();
    hasWarnings = (buffer.readShort() > 0);

    if ((serverStatus & ServerStatus.SERVER_SESSION_STATE_CHANGED) != 0) {
      handleStateChange(buffer, results);
    }

    results.addStats(updateCount, insertId, hasMoreResults());
  }
743266
public int readFrom(ByteBuffer src, long destOffset) {
        if (src.remaining() + destOffset >= size())
            throw new BufferOverflowException();
        int readLen = src.remaining();
        ByteBuffer b = toDirectByteBuffer(destOffset, readLen);
        b.position(0);
        b.put(src);
        return readLen;
    }
813805
private void readResults() throws IOException, ParseException {
		factory.setFile(file);
		results = factory.createObjects(evalueThreshold);
	}
154743
@Override
    public byte[] read(ScanBuffer buffer) {
        int length = getLength(buffer);
        if (length<0) return null;
        return buffer.getBytes(length);
    }
1246971
private void readLocalInfilePacket(Buffer buffer, Results results) throws SQLException {

    int seq = 2;
    buffer.getLengthEncodedNumeric(); //field pos
    String fileName = buffer.readStringNullEnd(StandardCharsets.UTF_8);
    try {
      // Server request the local file (LOCAL DATA LOCAL INFILE)
      // We do accept general URLs, too. If the localInfileStream is
      // set, use that.
      InputStream is;
      writer.startPacket(seq);
      if (localInfileInputStream == null) {

        if (!getUrlParser().getOptions().allowLocalInfile) {
          writer.writeEmptyPacket();
          reader.getPacket(true);
          throw new SQLException(
              "Usage of LOCAL INFILE is disabled. To use it enable it via the connection property allowLocalInfile=true",
              FEATURE_NOT_SUPPORTED.getSqlState(), -1);
        }

        //validate all defined interceptors
        ServiceLoader<LocalInfileInterceptor> loader = ServiceLoader
            .load(LocalInfileInterceptor.class);
        for (LocalInfileInterceptor interceptor : loader) {
          if (!interceptor.validate(fileName)) {
            writer.writeEmptyPacket();
            reader.getPacket(true);
            throw new SQLException("LOCAL DATA LOCAL INFILE request to send local file named \""
                + fileName + "\" not validated by interceptor \"" + interceptor.getClass().getName()
                + "\"");
          }
        }

        try {
          URL url = new URL(fileName);
          is = url.openStream();
        } catch (IOException ioe) {
          try {
            is = new FileInputStream(fileName);
          } catch (FileNotFoundException f) {
            writer.writeEmptyPacket();
            reader.getPacket(true);
            throw new SQLException("Could not send file : " + f.getMessage(), "22000", -1, f);
          }
        }
      } else {
        is = localInfileInputStream;
        localInfileInputStream = null;
      }

      try {

        byte[] buf = new byte[8192];
        int len;
        while ((len = is.read(buf)) > 0) {
          writer.startPacket(seq++);
          writer.write(buf, 0, len);
          writer.flush();
        }
        writer.writeEmptyPacket();

      } catch (IOException ioe) {
        throw handleIoException(ioe);
      } finally {
        is.close();
      }

      getResult(results);

    } catch (IOException e) {
      throw handleIoException(e);
    }
  }
164048
private void readQueryResult(InH3 hIn, HeadersAmp headers)
      throws IOException
  {
    ServiceRefAmp serviceRef = readToAddress(hIn);
  
    long id = hIn.readLong();

    QueryRefAmp queryRef = serviceRef.removeQueryRef(id);
  
    if (queryRef != null) {
      ClassLoader loader = queryRef.getClassLoader();

      Thread thread = Thread.currentThread();
      thread.setContextClassLoader(loader);
      // XXX: _serializer.setClassLoader(loader);
    }
    else {
      // XX: _serializer.setClassLoader(null);
    }

    Object value = hIn.readObject();

    if (log.isLoggable(_logLevel)) {
      log.log(_logLevel, "query-result-r " + value + " (in " + this + ")"
              + "\n  {id:" + id + ", to:" + serviceRef + "," + headers + "}");
    }

    if (queryRef != null) {
      queryRef.complete(headers, value);
    }
    else if (log.isLoggable(Level.WARNING)) {
      log.warning("query-result qid=" + id + " for service " + serviceRef +
                  " does not match any known queries.\n" + headers);
    }
  }
698947
public static void printBuffer(byte[] buffer, String msg) {
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < buffer.length; i++) {
            if (i % 20 == 0) {
                sb.append("\n\t");
            }
            sb.append(String.format("%02x", buffer[i]));
        }

        logger.info("{}: {}", msg, sb.toString());
    }
329347
def read(self):
        
        """
        # Read until we have a \0 in our buffer.
        while b'\0' not in self._recv_buffer:
            self._recv_buffer += yield From(_read_chunk_from_socket(self.socket))

        # Split on the first separator.
        pos = self._recv_buffer.index(b'\0')

        packet = self._recv_buffer[:pos]
        self._recv_buffer = self._recv_buffer[pos + 1:]

        raise Return(packet)
469517
protected final synchronized int readData(final long startPos, final byte[] buffer, final int offset,
                                        final int len)
            throws IOException {
        seek(startPos);
        return read(buffer, offset, len);
    }
92888
function readNextRow()
  {
    // if we have a row buffer, process it
    if (rowBuffer)
    {
      processRowBuffer();
    }
    else
    {
      // subscribe to the result stream's 'data' and 'close' events
      resultStream.on('data', onResultStreamData);
      resultStream.on('close', onResultStreamClose);

      // issue a request to fetch the next chunk in the result stream
      resultStream.read();
    }
  }
446947
public void setBuffer(final String buffer) {
        initRandomBuffer();
        byteBufferAry = Arrays.copyOf(buffer.getBytes(), MAX_PACKETBUFFER_LENGTH);
    }
752432
private void readPacket(Results results) throws SQLException {
    Buffer buffer;
    try {
      buffer = reader.getPacket(true);
    } catch (IOException e) {
      throw handleIoException(e);
    }

    switch (buffer.getByteAt(0)) {

      //*********************************************************************************************************
      //* OK response
      //*********************************************************************************************************
      case OK:
        readOkPacket(buffer, results);
        break;

      //*********************************************************************************************************
      //* ERROR response
      //*********************************************************************************************************
      case ERROR:
        throw readErrorPacket(buffer, results);

        //*********************************************************************************************************
        //* LOCAL INFILE response
        //*********************************************************************************************************
      case LOCAL_INFILE:
        readLocalInfilePacket(buffer, results);
        break;

      //*********************************************************************************************************
      //* ResultSet
      //*********************************************************************************************************
      default:
        readResultSet(buffer, results);
        break;

    }

  }
988184
@SuppressWarnings("unchecked")
  private <T> T readByClass(BufferInput<?> buffer) {
    String name = buffer.readUTF8();
    if (whitelistRequired.get())
      throw new SerializationException("cannot deserialize unregistered type: " + name);

    Class<T> type = (Class<T>) types.get(name);
    if (type == null) {
      try {
        type = (Class<T>) Class.forName(name);
        if (type == null)
          throw new SerializationException("cannot deserialize: unknown type");
        types.put(name, type);
      } catch (ClassNotFoundException e) {
        throw new SerializationException("object class not found: " + name, e);
      }
    }

    TypeSerializer<T> serializer = getSerializer(type);
    if (serializer == null)
      throw new SerializationException("cannot deserialize unregistered type: " + name);

    return serializer.read(type, buffer, this);
  }
16630
@Override
  public URIParsedResult parse(Result result) {
    String rawText = getMassagedText(result);
    // We specifically handle the odd "URL" scheme here for simplicity and add "URI" for fun
    // Assume anything starting this way really means to be a URI
    if (rawText.startsWith("URL:") || rawText.startsWith("URI:")) {
      return new URIParsedResult(rawText.substring(4).trim(), null);
    }
    rawText = rawText.trim();
    if (!isBasicallyValidURI(rawText) || isPossiblyMaliciousURI(rawText)) {
      return null;
    }
    return new URIParsedResult(rawText, null);
  }
19840
public int read( char[] cbuf, int off, int len ) throws IOException
    {
        //check the buffer queue
        int size = queue.size();
        if ( size > 0 ) {
            //TODO
            //int num = size <= len ? size : len;
            //System.arraycopy(src, srcPos, dest, destPos, length)
            throw new IOException("Method not implemented yet");
        }
        
        return reader.read(cbuf, off, len);
    }
1047526
@Override
	public int read(byte[] b, int off, int len) throws IOException
    {
        if (len == 0)
            return 0;
        
        int totalRead = 0;
        do
        {
            int amount = readBufferedOrAvailable(b,off+totalRead,len-totalRead);
            if (amount <= 0)
                return (totalRead == 0) ? amount : totalRead;
            totalRead += amount;
            
            // Did we get enough ?
            if (totalRead >= len)
                break;
        }
        while (in.available() > 0);
        
        return totalRead;
    }
82592
def read
      buffer = []

      loop do
        char = @serial.getbyte
        fail(ReadTimeout) if char.nil?

        buffer << char

        fail(BadPacket, 'invalid header') if buffer.size == 2 && buffer != [0xA5, 0xA5]

        break if buffer[-2, 2] == [0x0A, 0x0D]

        fail(BadPacket, 'packet too big') if buffer.size > 256
      end

      header = [buffer.shift, buffer.shift]
      fail(BadPacket, 'invalid header') unless header == [0xA5, 0xA5]

      src = buffer.shift
      dst = buffer.shift

      ctrl = buffer.shift
      func = buffer.shift

      size = buffer.shift

      # TODO: My unit seems to return the wrong size here (Maybe we should have an option if not all units do this)
      size -= 2 if [ctrl, func] == Jfy::Codes::QUERY_SET_INFO_RESP

      data = buffer.take(size)
      buffer = buffer.drop(size)

      checksum = [buffer.shift, buffer.shift]
      ender = [buffer.shift, buffer.shift]

      packet = Packet.new([ctrl, func], data, :src => src, :dst => dst)
      p packet if @debug

      fail(BadPacket, 'invalid checksum') if checksum != packet.checksum &&
                                             [ctrl, func] != Jfy::Codes::QUERY_SET_INFO_RESP

      fail(BadPacket, 'invalid ender') unless ender == [0x0A, 0x0D]

      packet
    end