public static <T>T deserialize(String filename,Class<T> type,SerializationMode mode){
  try {
    T object;
    final Path filePath=Paths.get(filename);
    if (!Files.exists(filePath) || Files.size(filePath) == 0L) {
      object=null;
    }
 else     if (mode == SerializationMode.BIN || mode == SerializationMode.BIN_GZ) {
      Kryo kryo=new Kryo();
      kryo.setReferences(false);
      Input input=new Input(mode == SerializationMode.BIN_GZ ? new GZIPInputStream(new FileInputStream(filename)) : new FileInputStream(filename));
      object=kryo.readObject(input,type);
      input.close();
    }
 else     if (mode == SerializationMode.DEFAULT || mode == SerializationMode.DEFAULT_GZ) {
      FileInputStream input=new FileInputStream(new File(filename));
      ObjectInputStream inStream=mode == SerializationMode.DEFAULT_GZ ? new ObjectInputStream(new GZIPInputStream(input)) : new ObjectInputStream(input);
      object=type.cast(inStream.readObject());
      inStream.close();
    }
 else {
      throw new UnsupportedOperationException();
    }
    return object;
  }
 catch (  KryoException|ClassNotFoundException|IOException e) {
    logger.error("Unable to deserialize {} (mode: {})",filename,mode);
    logger.error("Deserialization exception",e);
    throw new RuntimeException(e);
  }
}

public static < T > T deserialize ( String filename , Class < T > type , SerializationMode mode ) { try { T object ; final Path filePath = Paths . get ( filename ) ; if ( ! Files . exists ( filePath ) || Files . size ( filePath ) == 0L ) { object = null ; } else if ( mode == SerializationMode . BIN || mode == SerializationMode . BIN_GZ ) { Kryo kryo = new Kryo ( ) ; kryo . setReferences ( false ) ; Input input = new Input ( mode == SerializationMode . BIN_GZ ? new GZIPInputStream ( new FileInputStream ( filename ) ) : new FileInputStream ( filename ) ) ; object = kryo . readObject ( input , type ) ; input . close ( ) ; } else if ( mode == SerializationMode . DEFAULT || mode == SerializationMode . DEFAULT_GZ ) { FileInputStream input = new FileInputStream ( new File ( filename ) ) ; ObjectInputStream inStream = mode == SerializationMode . DEFAULT_GZ ? new ObjectInputStream ( new GZIPInputStream ( input ) ) : new ObjectInputStream ( input ) ; object = type . cast ( inStream . readObject ( ) ) ; inStream . close ( ) ; } else { throw new UnsupportedOperationException ( ) ; } return object ; } catch ( KryoException | ClassNotFoundException | IOException e ) { logger . error ( "Unable to deserialize {} (mode: {})" , filename , mode ) ; logger . error ( "Deserialization exception" , e ) ; throw new RuntimeException ( e ) ; } }
deserialize an object . the serialization mode is selected automatically . if the specified file does not exist or is empty , then this call returns null .
