Total Complexity | 6 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | package io.mcarle.sciurus.cache.redis; |
||
6 | class RedisData implements Serializable { |
||
7 | |||
8 | private final Serializable value; |
||
9 | |||
10 | 1 | RedisData(final Serializable value) { |
|
11 | 1 | this.value = value; |
|
12 | 1 | } |
|
13 | |||
14 | static ByteBuffer toByteBuffer(final RedisData redisData) { |
||
15 | try { |
||
16 | 1 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
17 | 1 | ObjectOutputStream oos = new ObjectOutputStream(baos); |
|
18 | 1 | oos.writeObject(redisData); |
|
19 | 1 | oos.close(); |
|
20 | 1 | return ByteBuffer.wrap(baos.toByteArray()); |
|
21 | 1 | } catch (IOException e) { |
|
22 | 1 | throw new RuntimeException(e); |
|
23 | } |
||
24 | } |
||
25 | |||
26 | static RedisData fromByteBuffer(final ByteBuffer byteBuffer) { |
||
27 | try { |
||
28 | 1 | byte[] data = new byte[byteBuffer.remaining()]; |
|
29 | 1 | byteBuffer.get(data); |
|
30 | 1 | ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data)); |
|
31 | 1 | Object o = ois.readObject(); |
|
32 | 1 | ois.close(); |
|
33 | 1 | return (RedisData) o; |
|
34 | 1 | } catch (Exception e) { |
|
35 | 1 | throw new RuntimeException(e); |
|
36 | } |
||
37 | } |
||
38 | |||
39 | Serializable getCachedValue() { |
||
40 | 1 | return value; |
|
41 | } |
||
43 |