code: private void handleNegotiation() throws IOException {
          if (telnetCommand.contains(new String(new byte[] { TERMINAL_TYPE }))) {
              //  IAC SB TERMINAL_TYPE IS XXX IAC SE
              boolean isSuccess = false;
              clientTerminalType = telnetCommand.substring(4, telnetCommand.length() - 2);
              for (String terminalType : terminalTypeMapping.keySet()) {
                  if (clientTerminalType.contains(terminalType)) {
                      isSuccess = true;
                      clientTerminalType = terminalType;
                      echoPrompt();
                      break;
                  }
              }
              if (!isSuccess) {
                  socketChannel.write(ByteBuffer.wrap("TerminalType negotiate failed.".getBytes()));
                  throw new RuntimeException("TerminalType negotiate failed.");
              }
          }
      }
docs: Handle negotiation of terminal type