Example usage for org.apache.hadoop.security.token TokenIdentifier readFields

List of usage examples for org.apache.hadoop.security.token TokenIdentifier readFields

Introduction

In this page you can find the example usage for org.apache.hadoop.security.token TokenIdentifier readFields.

Prototype

void readFields(DataInput in) throws IOException;

Source Link

Document

Deserialize the fields of this object from in.

Usage

From source file:org.apache.giraph.comm.netty.handler.SaslServerHandler.java

License:Apache License

/**
 * Get the token identifier object, or null if it could not be constructed
 * (because the class could not be loaded, for example).
 * Hadoop 2.0.0 (and older Hadoop2 versions? (verify)) need this.
 * Hadoop 2.0.1 and newer have a Token.decodeIdentifier() method and do not
 * need this. Might want to create a munge flag to distinguish 2.0.0 vs newer.
 *
 * @param token the token to decode into a TokenIdentifier
 * @param cls the subclass of TokenIdentifier to decode the token into.
 * @return the token identifier./*www  .j a  v  a  2 s  . c  o  m*/
 * @throws IOException
 */
@SuppressWarnings("unchecked")
private TokenIdentifier decodeIdentifier(Token<? extends TokenIdentifier> token,
        Class<? extends TokenIdentifier> cls) throws IOException {
    TokenIdentifier tokenIdentifier = ReflectionUtils.newInstance(cls, null);
    ByteArrayInputStream buf = new ByteArrayInputStream(token.getIdentifier());
    DataInputStream in = new DataInputStream(buf);
    tokenIdentifier.readFields(in);
    in.close();
    return tokenIdentifier;
}