code: void addTokensFromFile(final UserGroupInformation ugi) throws IOException {
      LOG.log(Level.FINE, "Reading security tokens from file: {0}", this.securityTokensFile);
  
      try (final FileInputStream stream = new FileInputStream(securityTokensFile)) {
        final BinaryDecoder decoder = decoderFactory.binaryDecoder(stream, null);
  
        while (!decoder.isEnd()) {
          final SecurityToken token = tokenDatumReader.read(null, decoder);
  
          final Token<TokenIdentifier> yarnToken = new Token<>(
              token.getKey().array(),
              token.getPassword().array(),
              new Text(token.getKind().toString()),
              new Text(token.getService().toString()));
  
          LOG.log(Level.FINE, "addToken for {0}", yarnToken.getKind());
  
          ugi.addToken(yarnToken);
        }
      }
    }
docs: Read tokens from a file and add them to the user's credentials.
  @param ugi user's credentials to add tokens to.
  @throws IOException if there are errors in reading the tokens' file.