public void save(String key,Object data,boolean isEncrypted,String encryptKey){
  key=safetyKey(key);
  String wrapperJSONSerialized;
  if (data instanceof Record) {
    Type type=jolyglot.newParameterizedType(data.getClass(),Object.class);
    wrapperJSONSerialized=jolyglot.toJson(data,type);
  }
 else {
    wrapperJSONSerialized=jolyglot.toJson(data);
  }
  FileWriter fileWriter=null;
  try {
    File file=new File(cacheDirectory,key);
    fileWriter=new FileWriter(file,false);
    fileWriter.write(wrapperJSONSerialized);
    fileWriter.flush();
    fileWriter.close();
    fileWriter=null;
    if (isEncrypted) {
      fileEncryptor.encrypt(encryptKey,new File(cacheDirectory,key));
    }
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
 finally {
    try {
      if (fileWriter != null) {
        fileWriter.flush();
        fileWriter.close();
      }
    }
 catch (    IOException e) {
      e.printStackTrace();
    }
  }
}

public void save ( String key , Object data , boolean isEncrypted , String encryptKey ) { key = safetyKey ( key ) ; String wrapperJSONSerialized ; if ( data instanceof Record ) { Type type = jolyglot . newParameterizedType ( data . getClass ( ) , Object . class ) ; wrapperJSONSerialized = jolyglot . toJson ( data , type ) ; } else { wrapperJSONSerialized = jolyglot . toJson ( data ) ; } FileWriter fileWriter = null ; try { File file = new File ( cacheDirectory , key ) ; fileWriter = new FileWriter ( file , false ) ; fileWriter . write ( wrapperJSONSerialized ) ; fileWriter . flush ( ) ; fileWriter . close ( ) ; fileWriter = null ; if ( isEncrypted ) { fileEncryptor . encrypt ( encryptKey , new File ( cacheDirectory , key ) ) ; } } catch ( Exception e ) { throw new RuntimeException ( e ) ; } finally { try { if ( fileWriter != null ) { fileWriter . flush ( ) ; fileWriter . close ( ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } } }
save in disk the object passed .
