![JAR search and dependency download from the Maven repository](/logo.png)
org.hibernate.cache.redis.serializer.SnappyRedisSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-redis Show documentation
Show all versions of hibernate-redis Show documentation
Hibernate second level cache with Redis
The newest version!
package org.hibernate.cache.redis.serializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xerial.snappy.Snappy;
import java.io.IOException;
/**
* SnappyRedisSerializer
* Created by debop on 2014. 3. 15.
*/
public class SnappyRedisSerializer implements RedisSerializer {
private static final Logger log = LoggerFactory.getLogger(SnappyRedisSerializer.class);
private final RedisSerializer inner;
public SnappyRedisSerializer() {
this(new FstRedisSerializer());
}
public SnappyRedisSerializer(RedisSerializer innerSerializer) {
assert (innerSerializer != null);
this.inner = innerSerializer;
}
@Override
public byte[] serialize(T graph) {
try {
return Snappy.compress(inner.serialize(graph));
} catch (IOException e) {
log.error("Fail to serialize graph.", e);
return EMPTY_BYTES;
}
}
@Override
public T deserialize(byte[] bytes) {
if (bytes == null || bytes.length == 0)
return null;
try {
return inner.deserialize(Snappy.uncompress(bytes));
} catch (IOException e) {
log.error("Fail to deserialize graph.", e);
return null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy