Consume a port, which according to RFC 3261 is:

port = 1*DIGIT

@param buffer
@return the buffer containing only digits or null if there was none fun.
@throws IOException
548177
public static Buffer consumePort(final Buffer buffer) throws IOException {
        int count = 0;
        final int index = buffer.getReaderIndex();
        boolean done = false;
        while (!done && buffer.hasReadableBytes()) {
            if (isDigit(buffer.readByte())) {
                ++count;
            } else {
                done = true;
            }
        }

        buffer.setReaderIndex(index);
        if (count != 0) {
            return buffer.readBytes(count);
        }

        return null;
    }
1122583
int readAsciiByte() throws IOException {
        if (commPort != null && commPort.isOpen()) {
            byte[] buffer = new byte[1];
            int cnt = commPort.readBytes(buffer, 1);
            if (cnt != 1) {
                throw new IOException("Cannot read from serial port");
            }
            else if (buffer[0] == ':') {
                return ModbusASCIITransport.FRAME_START;
            }
            else if (buffer[0] == '\r' || buffer[0] == '\n') {
                return ModbusASCIITransport.FRAME_END;
            }
            else {
                logger.debug("Read From buffer: " + buffer[0] + " (" + String.format("%02X", buffer[0]) + ")");
                byte firstValue = buffer[0];
                cnt = commPort.readBytes(buffer, 1);
                if (cnt != 1) {
                    throw new IOException("Cannot read from serial port");
                }
                else {
                    logger.debug("Read From buffer: " + buffer[0] + " (" + String.format("%02X", buffer[0]) + ")");
                    int combinedValue = (Character.digit(firstValue, 16) << 4) + Character.digit(buffer[0], 16);
                    logger.debug("Returning combined value of: " + String.format("%02X", combinedValue));
                    return combinedValue;
                }
            }
        }
        else {
            throw new IOException("Comm port is not valid or not open");
        }
    }
447647
public static void getBytes(long address, byte[] buffer, int bufferOffset, int count)
    {
        if (buffer == null)
            throw new NullPointerException();
        else if (bufferOffset < 0 || count < 0 || count > buffer.length - bufferOffset)
            throw new IndexOutOfBoundsException();
        else if (count == 0)
            return;

        unsafe.copyMemory(null, address, buffer, BYTE_ARRAY_BASE_OFFSET + bufferOffset, count);
    }
851631
public final T readBuffer(byte[] buffer) {
        if (buffer == null) {
            throw new InvalidArgument("buffer", buffer);
        } else if (buffer.length != recordSize) {
            final String fmt = "invalid buffer (%d bytes, expected %d)";
            final String msg = format(fmt, buffer.length, recordSize);
            throw new InvalidArgument(msg);
        }
        return read(buffer);
    }
1190141
public static long memoryAddress(ByteBuffer buffer) {
        assert buffer.isDirect();
        if (PlatformDependent.hasUnsafe()) {
            return PlatformDependent.directBufferAddress(buffer);
        }
        return memoryAddress0(buffer);
    }
458144
public static void proxyPort(final int port) {
    final String portValue = Integer.toString(port);
    setProperty("http.proxyPort", portValue);
    setProperty("https.proxyPort", portValue);
  }
1032600
public static Object readObject(final int port) throws IOException, ClassNotFoundException
	{
		ServerSocket serverSocket = null;
		Socket clientSocket = null;
		Object objectToReturn = null;
		try
		{
			serverSocket = new ServerSocket(port);
			clientSocket = serverSocket.accept();
			objectToReturn = readObject(clientSocket);
		}
		catch (final IOException e)
		{
			throw e;
		}
		catch (final ClassNotFoundException e)
		{
			throw e;
		}
		finally
		{
			closeServerSocket(serverSocket);
		}
		return objectToReturn;
	}
840786
public Yoke listen(int port, @NotNull String address) {
        return listen(port, address, null);
    }
847314
public int read(byte []buf, int offset, int length) throws IOException
  {
    if (_stream != null)
      return _stream.read(buf, offset, length);
    else
      return -1;
  }
268676
public function consumeFrame(Buffer $buffer)
    {
        // not enough data
        if ($buffer->getLength() < 7) {
            return null;
        }

        $type = $buffer->readUint8(0);
        $channel = $buffer->readUint16(1);
        $payloadSize = $buffer->readUint32(3);
        $payloadOffset = 7; // type:uint8=>1 + channel:uint16=>2 + payloadSize:uint32=>4 ==> 7

        // not enough data
        if ($buffer->getLength() < $payloadOffset + $payloadSize + 1 /* frame end byte */) {
            return null;
        }

        $buffer->consume(7);
        $payload = $buffer->consume($payloadSize);
        $frameEnd = $buffer->consumeUint8();

        if ($frameEnd !== Constants::FRAME_END) {
            throw new ProtocolException(sprintf("Frame end byte invalid - expected 0x%02x, got 0x%02x.", Constants::FRAME_END, $frameEnd));
        }

        $frameBuffer = new Buffer($payload);

        if ($type === Constants::FRAME_METHOD) {
            $frame = $this->consumeMethodFrame($frameBuffer);

        } elseif ($type === Constants::FRAME_HEADER) {
            // see https://github.com/pika/pika/blob/master/pika/spec.py class BasicProperties
            $frame = new ContentHeaderFrame();
            $frame->classId = $frameBuffer->consumeUint16();
            $frame->weight = $frameBuffer->consumeUint16();
            $frame->bodySize = $frameBuffer->consumeUint64();
            $frame->flags = $flags = $frameBuffer->consumeUint16();

            if ($flags & ContentHeaderFrame::FLAG_CONTENT_TYPE) {
                $frame->contentType = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

            if ($flags & ContentHeaderFrame::FLAG_CONTENT_ENCODING) {
                $frame->contentEncoding = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

            if ($flags & ContentHeaderFrame::FLAG_HEADERS) {
                $frame->headers = $this->consumeTable($frameBuffer);
            }

            if ($flags & ContentHeaderFrame::FLAG_DELIVERY_MODE) {
                $frame->deliveryMode = $frameBuffer->consumeUint8();
            }

            if ($flags & ContentHeaderFrame::FLAG_PRIORITY) {
                $frame->priority = $frameBuffer->consumeUint8();
            }

            if ($flags & ContentHeaderFrame::FLAG_CORRELATION_ID) {
                $frame->correlationId = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

            if ($flags & ContentHeaderFrame::FLAG_REPLY_TO) {
                $frame->replyTo = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

            if ($flags & ContentHeaderFrame::FLAG_EXPIRATION) {
                $frame->expiration = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

            if ($flags & ContentHeaderFrame::FLAG_MESSAGE_ID) {
                $frame->messageId = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

            if ($flags & ContentHeaderFrame::FLAG_TIMESTAMP) {
                $frame->timestamp = $this->consumeTimestamp($frameBuffer);
            }

            if ($flags & ContentHeaderFrame::FLAG_TYPE) {
                $frame->typeHeader = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

            if ($flags & ContentHeaderFrame::FLAG_USER_ID) {
                $frame->userId = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

            if ($flags & ContentHeaderFrame::FLAG_APP_ID) {
                $frame->appId = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

            if ($flags & ContentHeaderFrame::FLAG_CLUSTER_ID) {
                $frame->clusterId = $frameBuffer->consume($frameBuffer->consumeUint8());
            }

        } elseif ($type === Constants::FRAME_BODY) {
            $frame = new ContentBodyFrame();
            $frame->payload = $frameBuffer->consume($frameBuffer->getLength());

        } elseif ($type === Constants::FRAME_HEARTBEAT) {
            $frame = new HeartbeatFrame();
            if (!$frameBuffer->isEmpty()) {
                throw new ProtocolException("Heartbeat frame must be empty.");
            }

        } else {
            throw new ProtocolException("Unhandled frame type '{$type}'.");
        }

        if (!$frameBuffer->isEmpty()) {
            throw new ProtocolException("Frame buffer not entirely consumed.");
        }

        /** @var AbstractFrame $frame */
        $frame->type = $type;
        $frame->channel = $channel;
        $frame->payloadSize = $payloadSize;
        // DO NOT CALL! ContentBodyFrame uses payload for body
        // $frame->setPayload($payload);

        return $frame;
    }
28218
public void read(ByteBuffer buffer) {
        Persistables.persistable(streamableNoBuffers()).read(buffer);

        final int n = getNumDataBuffers();
        int lengthsPosition = buffer.position();
        buffer.position(buffer.position() + 2 * n); // skip positions
        for (int i = 0; i < n; i++) {
            final int size = buffer.getShort(lengthsPosition) & 0xFFFF; // big-endian
            lengthsPosition += 2;

            final ByteBuffer b1 = Persistables.slice(buffer, size);
            setDataBuffer(i, b1);
        }
    }
962106
public int readFrom(InputStream stream) throws IOException {
        int bytesRead = stream.read(buffer);
        if (bytesRead < 0) {
            bytesInBuffer = 0;
        } else {
            bytesInBuffer = bytesRead;
        }
        return bytesRead;
    }
736695
public void setPort(int port)
    {
        if (_address == null || _address.getHostName() == null)
            _address= new InetSocketAddress(port);
        else
            _address= new InetSocketAddress(_address.getHostName(), port);
    }
596203
public int read(final byte[] buffer) throws IOException {
    // Note that GWT will throw a JavascriptException rather than a NullPointerException if we
    // skip this check and the buffer array is null. This way we ensure that this implementation
    // behaves in the same way as the classes that are emulated.
    if (buffer == null) {
      throw new NullPointerException();
    }
    return this.read(buffer, 0, buffer.length);
  }
659247
public static int readSingleByte(InputStream in) throws IOException {
        byte[] buffer = new byte[1];
        int result = in.read(buffer, 0, 1);
        return (result != -1) ? buffer[0] & 0xff : -1;
    }
552387
public int read(long offset) throws IOException {
    int b;
    if (maxBufferSize <= 0) {
      // old-school (no buffer optimization)
      b = input.read();
    } else {
      checkBuffer(offset);
      b = buffer[(int) (offset - bufferOffset)];
    }
    if (b < 0) return 256+b;
    return b;
  }
162482
protected int readByte() throws IOException {
        if (commPort != null && commPort.isOpen()) {
            byte[] buffer = new byte[1];
            int cnt = commPort.readBytes(buffer, 1);
            if (cnt != 1) {
                throw new IOException("Cannot read from serial port");
            }
            else {
                return buffer[0] & 0xff;
            }
        }
        else {
            throw new IOException("Comm port is not valid or not open");
        }
    }