Exemplo n.º 1
0
 /**
  * Releases the given {@link Closeable} especially if it was an instance of {@link Releasable}.
  *
  * <p>For example, the creation of a <code>ResettableInputStream</code> would entail physically
  * opening a file. If the opened file is meant to be closed only (in a finally block) by the very
  * same code block that created it, then it is necessary that the release method must not be
  * called while the execution is made in other stack frames.
  *
  * <p>In such case, as other stack frames may inadvertently or indirectly call the close method of
  * the stream, the creator of the stream would need to explicitly disable the accidental closing
  * via <code>ResettableInputStream#disableClose()</code>, so that the release method becomes the
  * only way to truly close the opened file.
  */
 public static void release(Closeable is, Log log) {
   closeQuietly(is, log);
   if (is instanceof Releasable) {
     Releasable r = (Releasable) is;
     r.release();
   }
 }
Exemplo n.º 2
0
  private static JmesPathExpression getAstFromArgument(
      String argument, Map<String, JmesPathExpression> argumentToAstMap) throws IOException {
    if (argument != null && !argumentToAstMap.containsKey(argument)) {

      ProcessBuilder pb =
          new ProcessBuilder(
              "/apollo/env/SDETools/bin/brazil-runtime-exec",
              "python3.4",
              System.getProperty("codeGenSourceDirectory") + "/bin/jp-to-ast.py",
              argument);
      Process p = pb.start();

      JsonNode jsonNode = mapper.readTree(IOUtils.toString(p.getInputStream()));
      JmesPathExpression ast = fromAstJsonToAstJava(jsonNode);

      argumentToAstMap.put(argument, ast);
      IOUtils.closeQuietly(p.getInputStream(), null);

      return ast;

    } else if (argument != null) {
      return argumentToAstMap.get(argument);
    }
    return null;
  }
 /**
  * To allow customers to override abort to just close. We can think about exposing this method as
  * protected to allow customers to completely prevent the abort behavior if there is a need
  */
 private void doAbort() {
   if (httpRequest != null) {
     httpRequest.abort();
   }
   IOUtils.closeQuietly(in, null);
 }