コード例 #1
0
 @Override
 public void setProperty(final String name, final Object value) {
   DSLEntryResult result = methodMissingImpl(name, value);
   if (!result.isSuccess()) {
     super.setProperty(name, value);
   }
 }
コード例 #2
0
 public void run() {
   try {
     String line = null;
     script.setProperty("out", writer);
     script.setProperty("socket", socket);
     script.setProperty("init", Boolean.TRUE);
     while ((line = reader.readLine()) != null) {
       // System.out.println(line);
       script.setProperty("line", line);
       Object o = script.run();
       script.setProperty("init", Boolean.FALSE);
       if (o != null) {
         if ("success".equals(o)) {
           break; // to close sockets gracefully etc...
         } else {
           if (autoOutputFlag) {
             writer.println(o);
           }
         }
       }
       writer.flush();
     }
   } catch (IOException e) {
     e.printStackTrace();
   } finally {
     try {
       writer.flush();
       writer.close();
     } finally {
       try {
         socket.close();
       } catch (IOException e3) {
         e3.printStackTrace();
       }
     }
   }
 }
コード例 #3
0
ファイル: GroovyMain.java プロジェクト: sigtool/groovy-core
  /**
   * Process a script against a single input file.
   *
   * @param s script to execute.
   * @param reader input file.
   * @param pw output sink.
   */
  private void processReader(Script s, BufferedReader reader, PrintWriter pw) throws IOException {
    String line;
    String lineCountName = "count";
    s.setProperty(lineCountName, BigInteger.ZERO);
    String autoSplitName = "split";
    s.setProperty("out", pw);

    try {
      InvokerHelper.invokeMethod(s, "begin", null);
    } catch (MissingMethodException mme) {
      // ignore the missing method exception
      // as it means no begin() method is present
    }

    while ((line = reader.readLine()) != null) {
      s.setProperty("line", line);
      s.setProperty(lineCountName, ((BigInteger) s.getProperty(lineCountName)).add(BigInteger.ONE));

      if (autoSplit) {
        s.setProperty(autoSplitName, line.split(splitPattern));
      }

      Object o = s.run();

      if (autoOutput && o != null) {
        pw.println(o);
      }
    }

    try {
      InvokerHelper.invokeMethod(s, "end", null);
    } catch (MissingMethodException mme) {
      // ignore the missing method exception
      // as it means no end() method is present
    }
  }