code: private static void writeTokenLength(ByteArrayOutputStream baos, int tokenLength) {
          if (tokenLength < 128) {
              baos.write((byte) tokenLength);
          } else if (tokenLength < (1 << 8)) {
              baos.write((byte) 0x081);
              baos.write((byte) tokenLength);
          } else if (tokenLength < (1 << 16)) {
              baos.write((byte) 0x082);
              baos.write((byte) (tokenLength >> 8));
              baos.write((byte) tokenLength);
          } else if (tokenLength < (1 << 24)) {
              baos.write((byte) 0x083);
              baos.write((byte) (tokenLength >> 16));
              baos.write((byte) (tokenLength >> 8));
              baos.write((byte) tokenLength);
          } else {
              baos.write((byte) 0x084);
              baos.write((byte) (tokenLength >> 24));
              baos.write((byte) (tokenLength >> 16));
              baos.write((byte) (tokenLength >> 8));
              baos.write((byte) tokenLength);
          }
      }
docs: /*
  Write the token length in the same way as in tWAS to ensure compatibility.