[OmniFaces utilities] The
serializeURLSafe()
method serialize the given string to the short possible unique URL-safe representation. The current implementation will decode the given string with UTF-8 and then compress it with ZLIB using "best compression" algorithm and then Base64-encode the resulting bytes without the =
padding, whereafter the Base64 characters +
and /
are been replaced by respectively -
and _
to make it URL-safe (so that no platform-sensitive URL-encoding needs to be done when used in URLs).[OmniFaces utilities] The
unserializeURLSafe()
method unserialize the given serialized URL-safe string. This does the inverse of #serializeURLSafe(String)
.Method Utils#serializeURLSafe() - Serialize the given string to the short possible unique URL-safe representation
See also: Utils#stream()
Method Utils#unserializeURLSafe() - Unserialize the given serialized URL-safe string
Usage:
// eNrTV_DPzct0S0xOLVawVfAKdlMoLcnMySypVMjJTCpKLKpU0AcAzDMLvQ
String
serialized = Utils.serializeURLSafe("/ OmniFaces = JSF utility library
/");
// /
OmniFaces = JSF utility library /
String
unserialized = Utils.unserializeURLSafe(serialized);
// eNrLKCkpsNLXz8_Ny0xLTE4t1k1LzCvWS8rJTy8uyC_RK8rXBwDehgy5
String
serialized = Utils.serializeURLSafe("http://omnifaces-fans.blogspot.ro/");
// http://omnifaces-fans.blogspot.ro/
String
unserialized = Utils.unserializeURLSafe(serialized);
// eNrLKCkpKLbS1y8t1s1NN9PLTczM0atMzMjP10vOz9XPS83Xz0kszUvOsNcrSsxLsU3JyCwzSixJNSmySMlSNjM0sjA1Njc0sgQAjaYX0w
String
serialized = Utils.serializeURLSafe("https://us-mg6.mail.yahoo.com/neo/launch?.rand=dhiv2ate4r8dj#6128537129");
// https://us-mg6.mail.yahoo.com/neo/launch?.rand=dhiv2ate4r8dj#6128537129
String
unserialized = Utils.unserializeURLSafe(serialized);
// eNozNFDQUjBV0FcwUdBWMFSwVTA01jMFACWyA4Q
String
serialized = Utils.serializeURLSafe("10 * 5 / 4 + 1 = 13.5");
// 10 * 5 /
4 + 1 = 13.5
String
unserialized = Utils.unserializeURLSafe(serialized);
You can
see a real example in OmniFaces source code, CombinedResourceInfo.
Niciun comentariu :
Trimiteți un comentariu