public void save(Resource resource) throws IOException {
   if (resource instanceof WritableResource) {
     WritableContainer<ByteBuffer> output = ((WritableResource) resource).getWritable();
     try {
       try {
         handler.save(IOUtils.toOutputStream(output), configuration.getPassword());
       } finally {
         output.close();
       }
     } catch (KeyStoreException e) {
       throw new RuntimeException(e);
     } catch (NoSuchAlgorithmException e) {
       throw new RuntimeException(e);
     } catch (CertificateException e) {
       throw new RuntimeException(e);
     }
   }
 }
 private void addExpectation(ScriptResult result) {
   Script script = getScript(result.getEnvironment());
   if (script instanceof ResourceScript) {
     ReadableResource resource = ((ResourceScript) script).getResource();
     if (resource instanceof WritableResource) {
       try {
         String name =
             useNamespaces && result.getScript().getNamespace() != null
                 ? result.getScript().getNamespace() + "." + result.getScript().getName()
                 : result.getScript().getName();
         ExecutorGroup parse =
             script
                 .getParser()
                 .parse(
                     new StringReader(
                         name
                             + " = "
                             + (result.getStopped().getTime() - result.getStarted().getTime())));
         script.getRoot().getChildren().add(parse.getChildren().get(0));
         StringWriter writer = new StringWriter();
         formatter.format(script.getRoot(), writer);
         String current = writer.toString();
         WritableContainer<ByteBuffer> writable = ((WritableResource) resource).getWritable();
         try {
           writable.write(IOUtils.wrap(current.getBytes(Charset.forName("UTF-8")), true));
         } finally {
           writable.close();
         }
       } catch (ParseException e) {
         throw new RuntimeException(e);
       } catch (IOException e) {
         throw new RuntimeException(e);
       }
     }
   }
 }