code: private static int readTokenLength(ByteArrayInputStream bais) {
          int tokenLength = 0;
          byte lengthMarker = (byte) bais.read();
  
          if (lengthMarker == (byte) 0x081) {
              int firstByte = bais.read();
              tokenLength = firstByte;
          } else if (lengthMarker == (byte) 0x082) {
              int secondByte = bais.read();
              int firstByte = bais.read();
              tokenLength = (secondByte << 8) + firstByte;
          } else if (lengthMarker == (byte) 0x083) {
              int thirdByte = bais.read();
              int secondByte = bais.read();
              int firstByte = bais.read();
              tokenLength = (thirdByte << 16) + (secondByte << 8) + firstByte;
          } else if (lengthMarker == (byte) 0x084) {
              int fourthByte = bais.read();
              int thirdByte = bais.read();
              int secondByte = bais.read();
              int firstByte = bais.read();
              tokenLength = (fourthByte << 24) + (thirdByte << 16) + (secondByte << 8) + firstByte;
          } else {
              // If not one of the markers above, this is the actual length.
              tokenLength = lengthMarker;
          }
  
          return tokenLength;
      }
docs: /*
  WARNING: The stream must have read up to the token length.
  Read token length the same way as tWAS to ensure compatibility.
  tWAS encodes lengths greater than 128 using a marker followed by 1, 2, 3, or 4 bytes.