code: private TlvHeader readHeader() throws IOException {
          int firstByte = in.read();
          if (firstByte < 0) {
              // no data to read
              throw new EOFException();
          }
          boolean tlv16 = (firstByte & TLV16_FLAG) != 0;
          boolean nonCritical = (firstByte & NON_CRITICAL_FLAG) != 0;
          boolean forward = (firstByte & FORWARD_FLAG) != 0;
  
          int type = firstByte & TYPE_MASK;
          int length;
          if (tlv16) {
              int typeLSB = in.readUnsignedByte();
              type = (type << BYTE_BITS) | typeLSB;
              length = in.readUnsignedShort();
          } else {
              length = in.readUnsignedByte();
          }
          if (type > TYPE_MASK && !tlv16) {
              throw new IOException("Invalid TLV header. TLV type > 0x1f but TLV8 encoding is used");
          }
          if (length > BYTE_MAX && !tlv16) {
              throw new IOException("Invalid TLV header. TLV length > 0xff but TLV8 encoding is used");
          }
          return new TlvHeader(tlv16, nonCritical, forward, type, length);
      }
docs: Reads the TLV header form input stream. Reads two (TLV8 encoding is used) or four (TLV16 encoding is used) bytes
  from underlying stream.
  
  @return Instance of {@link TlvHeader}, always present.
  
  @throws IOException
  when reading from underlying stream fails.