mcarleio    /
                    sciurus-cache-redis
                
                            | 1 | package io.mcarle.sciurus.cache.redis;  | 
            ||
| 
                                                                                                    
                         0 ignored issues 
                            –
                            show
                                    Code Smell
    
    
    
        introduced 
                            by  
        
   Loading history...
                 | 
                |||
| 2 | |||
| 3 | import java.io.*;  | 
            ||
| 
                                                                                                    
                         0 ignored issues 
                            –
                            show
                         | 
                |||
| 4 | import java.nio.ByteBuffer;  | 
            ||
| 5 | |||
| 6 | class RedisData implements Serializable { | 
            ||
| 
                                                                                                                                                        
                         0 ignored issues 
                            –
                            show
                                    Comprehensibility
            Best Practice
    
    
    
        introduced 
                            by  
        
        
     | 
                |||
| 7 | |||
| 8 | private final Serializable value;  | 
            ||
| 
                                                                                                    
                         0 ignored issues 
                            –
                            show
                         | 
                |||
| 9 | |||
| 10 | 1 |     RedisData(final Serializable value) { | 
            |
| 
                                                                                                    
                         0 ignored issues 
                            –
                            show
                         | 
                |||
| 11 | 1 | this.value = value;  | 
            |
| 
                                                                                                    
                         0 ignored issues 
                            –
                            show
                         | 
                |||
| 12 | 1 | }  | 
            |
| 13 | |||
| 14 |     static ByteBuffer toByteBuffer(final RedisData redisData) { | 
            ||
| 
                                                                                                    
                         0 ignored issues 
                            –
                            show
                         | 
                |||
| 15 |         try { | 
            ||
| 
                                                                                                                                                        
                         0 ignored issues 
                            –
                            show
                         | 
                |||
| 16 | 1 | ByteArrayOutputStream baos = new ByteArrayOutputStream();  | 
            |
| 
                                                                                                    
                         0 ignored issues 
                            –
                            show
                         | 
                |||
| 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) { | 
            |
| 
                                                                                                                                                        
                         0 ignored issues 
                            –
                            show
                         | 
                |||
| 22 | 1 | throw new RuntimeException(e);  | 
            |
| 
                                                                                                                                                        
                         0 ignored issues 
                            –
                            show
                         | 
                |||
| 23 | }  | 
            ||
| 24 | }  | 
            ||
| 25 | |||
| 26 |     static RedisData fromByteBuffer(final ByteBuffer byteBuffer) { | 
            ||
| 
                                                                                                    
                         0 ignored issues 
                            –
                            show
                         | 
                |||
| 27 |         try { | 
            ||
| 
                                                                                                                                                        
                         0 ignored issues 
                            –
                            show
                         | 
                |||
| 28 | 1 | byte[] data = new byte[byteBuffer.remaining()];  | 
            |
| 
                                                                                                    
                         0 ignored issues 
                            –
                            show
                         | 
                |||
| 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) { | 
            |
| 
                                                                                                                                                                                                            
                         0 ignored issues 
                            –
                            show
                         | 
                |||
| 35 | 1 | throw new RuntimeException(e);  | 
            |
| 
                                                                                                                                                        
                         0 ignored issues 
                            –
                            show
                         | 
                |||
| 36 | }  | 
            ||
| 37 | }  | 
            ||
| 38 | |||
| 39 |     Serializable getCachedValue() { | 
            ||
| 
                                                                                                    
                         0 ignored issues 
                            –
                            show
                         | 
                |||
| 40 | 1 | return value;  | 
            |
| 
                                                                                                    
                         0 ignored issues 
                            –
                            show
                         | 
                |||
| 41 | }  | 
            ||
| 42 | }  | 
            ||
| 43 |