Token implements Writable { private static String encodeWritable(Writable obj) throws IOException { DataOutputBuffer buf = new DataOutputBuffer(); obj.write(buf); Base64 encoder = new Base64(0, null, true); byte[] raw = new byte[buf.getLength()]; System.arraycopy(buf.getData(), 0, raw, 0, buf.getLength()); return encoder.encodeToString(raw); } Token(T id, SecretManager<T> mgr);  Token(byte[] identifier, byte[] password, Text kind, Text service);  Token();  Token(Token<T> other); void setID(byte[] bytes); void setPassword(byte[] newPassword); Token<T> copyToken(); byte[] getIdentifier(); @SuppressWarnings("unchecked") T decodeIdentifier(); byte[] getPassword(); synchronized Text getKind(); @InterfaceAudience.Private synchronized void setKind(Text newKind); Text getService(); void setService(Text newService); boolean isPrivate(); boolean isPrivateCloneOf(Text thePublicService); Token<T> privateClone(Text newService); @Override void readFields(DataInput in); @Override void write(DataOutput out); String encodeToUrlString(); void decodeFromUrlString(String newValue); @SuppressWarnings("unchecked") @Override boolean equals(Object right); @Override int hashCode(); @Override String toString(); String buildCacheKey(); boolean isManaged(); long renew(Configuration conf
                    ); void cancel(Configuration conf
                     ); static final Logger LOG; }
@Test public void testEncodeWritable() throws Exception { String[] values = new String[]{"", "a", "bb", "ccc", "dddd", "eeeee", "ffffff", "ggggggg", "hhhhhhhh", "iiiiiiiii", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLM" + "NOPQRSTUVWXYZ01234567890!@#$%^&*()-=_+[]{}|;':,./<>?"}; Token<AbstractDelegationTokenIdentifier> orig; Token<AbstractDelegationTokenIdentifier> copy = new Token<>(); for(int i=0; i< values.length; ++i) { String val = values[i]; Token.LOG.info("Input = {}", val); orig = new Token<>(val.getBytes(), val.getBytes(), new Text(val), new Text(val)); String encode = orig.encodeToUrlString(); copy.decodeFromUrlString(encode); assertEquals(orig, copy); checkUrlSafe(encode); } }