}
}
/** 编码。 */
public String encode(Map<String, Object> attrs, StoreContext storeContext) throws SessionEncoderException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// 1. 序列化
// 2. 压缩
Deflater def = new Deflater(Deflater.BEST_COMPRESSION, false);
DeflaterOutputStream dos = new DeflaterOutputStream(baos, def);
try {
serializer.serialize(assertNotNull(attrs, "objectToEncode is null"), dos);
} catch (Exception e) {
throw new SessionEncoderException("Failed to encode session state", e);
} finally {
try {
dos.close();
} catch (IOException e) {
}
def.end();
}
byte[] plaintext = baos.toByteArray().toByteArray();
// 3. 加密
byte[] cryptotext = encrypt(plaintext);
// 4. base64编码