Package org.mvel2.util

Examples of org.mvel2.util.StringAppender


   
    public String generateBaseUrl() {
      return "http://localhost:9080";
    }
    public static String GetContent (InputStream is) throws IOException {
        StringAppender ret = new StringAppender();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String line;
        while ((line = reader.readLine()) != null) {
            ret.append(line + "\n");
        }

        return ret.toString();
    }
View Full Code Here


        return ret.toString();
    }
   
    public static String GetContent (HttpURLConnection connection) throws IOException {
        StringAppender ret = new StringAppender();
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String line;
        while ((line = reader.readLine()) != null) {
            ret.append(line + "\n");
        }

        return ret.toString();
    }   
View Full Code Here

   
    public String generateBaseUrl() {
      return "http://localhost:9080";
    }
    public static String GetContent (InputStream is) throws IOException {
        StringAppender ret = new StringAppender();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String line;
        while ((line = reader.readLine()) != null) {
            ret.append(line + "\n");
        }

        return ret.toString();
    }
View Full Code Here

        return ret.toString();
    }
   
    public static String GetContent (HttpURLConnection connection) throws IOException {
        StringAppender ret = new StringAppender();
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String line;
        while ((line = reader.readLine()) != null) {
            ret.append(line + "\n");
        }

        return ret.toString();
    }   
View Full Code Here

        try {
            ServletInputStream inputStream = httpServletRequest.getInputStream();
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(inputStream, "UTF-8")
            );
            StringAppender sb = new StringAppender(httpServletRequest.getContentLength());
            CharBuffer buffer = CharBuffer.allocate(10);

            int read;
            while ((read = reader.read(buffer)) > 0) {
                buffer.rewind();
                for (; read > 0; read--) {
                    sb.append(buffer.get());
                }
                buffer.rewind();
            }

            for (Message msg : createCommandMessage(sessionProvider.getSession(httpServletRequest.getSession()), sb.toString())) {
                service.store(msg);
            }
        }
        catch (Throwable e) {
            // handle gracefully
View Full Code Here

import java.lang.reflect.Method;

public class RebindUtils {
    public static String createCallSignature(Method m) {
        StringAppender append = new StringAppender(m.getName()).append(':');
        for (Class c : m.getParameterTypes()) {
            append.append(c.getName()).append(':');
        }
        return append.toString();
    }
View Full Code Here

    return MVEL.executeExpression(MVEL.compileExpression(ex), base, map);
  }

  protected static Object _test(String ex) {
    ExpressionCompiler compiler = new ExpressionCompiler(ex);
    StringAppender failErrors = new StringAppender();

    CompiledExpression compiled = compiler.compile();
    Object first = null, second = null, third = null, fourth = null, fifth = null, sixth = null, seventh = null,
        eighth = null;

    System.out.println(DebugTools.decompile((Serializable) compiled));

    if (!Boolean.getBoolean("mvel2.disable.jit")) {

      setDefaultOptimizer("ASM");

      try {
        first = executeExpression(compiled, new Base(), createTestMap());
      }
      catch (Exception e) {
        failErrors.append("\nFIRST TEST: { " + ex + " }: EXCEPTION REPORT: \n\n");

        CharArrayWriter writer = new CharArrayWriter();
        e.printStackTrace(new PrintWriter(writer));

        failErrors.append(writer.toCharArray());
      }

      try {
        second = executeExpression(compiled, new Base(), createTestMap());
      }
      catch (Exception e) {
        failErrors.append("\nSECOND TEST: { " + ex + " }: EXCEPTION REPORT: \n\n");

        CharArrayWriter writer = new CharArrayWriter();
        e.printStackTrace(new PrintWriter(writer));

        failErrors.append(writer.toCharArray());
      }

    }

    try {
      third = MVEL.eval(ex, new Base(), createTestMap());
    }
    catch (Exception e) {
      failErrors.append("\nTHIRD TEST: { " + ex + " }: EXCEPTION REPORT: \n\n");

      CharArrayWriter writer = new CharArrayWriter();
      e.printStackTrace(new PrintWriter(writer));

      failErrors.append(writer.toCharArray());
    }

    if (first != null && !first.getClass().isArray()) {
      if (!first.equals(second)) {
        System.out.println(failErrors.toString());

        throw new AssertionError("Different result from test 1 and 2 (Compiled Re-Run / JIT) [first: "
            + valueOf(first) + "; second: " + valueOf(second) + "]");
      }

      if (!first.equals(third)) {
        if (failErrors != null) System.out.println(failErrors.toString());

        throw new AssertionError("Different result from test 1 and 3 (Compiled to Interpreted) [first: " +
            valueOf(first) + " (" + (first != null ? first.getClass().getName() : null) + "); third: " + valueOf(third) + " (" + (third != null ? third.getClass().getName() : "null") + ")]");
      }
    }

    setDefaultOptimizer("reflective");
    Serializable compiled2 = compileExpression(ex);

    try {
      fourth = executeExpression(compiled2, new Base(), createTestMap());
    }
    catch (Exception e) {
      if (failErrors == null) failErrors = new StringAppender();
      failErrors.append("\nFOURTH TEST: { " + ex + " }: EXCEPTION REPORT: \n\n");

      CharArrayWriter writer = new CharArrayWriter();
      e.printStackTrace(new PrintWriter(writer));

      failErrors.append(writer.toCharArray());
    }

    try {
      fifth = executeExpression(compiled2, new Base(), createTestMap());
    }
    catch (Exception e) {
      e.printStackTrace();
      if (failErrors == null) failErrors = new StringAppender();
      failErrors.append("\nFIFTH TEST: { " + ex + " }: EXCEPTION REPORT: \n\n");

      CharArrayWriter writer = new CharArrayWriter();
      e.printStackTrace(new PrintWriter(writer));

      failErrors.append(writer.toCharArray());
    }

    if (fourth != null && !fourth.getClass().isArray()) {
      if (!fourth.equals(fifth)) {
        throw new AssertionError("Different result from test 4 and 5 (Compiled Re-Run X2) [fourth: "
            + valueOf(fourth) + "; fifth: " + valueOf(fifth) + "]");
      }
    }

    ParserContext ctx = new ParserContext();
    ctx.setSourceFile("unittest");
    ctx.setDebugSymbols(true);

    ExpressionCompiler debuggingCompiler = new ExpressionCompiler(ex);
    //     debuggingCompiler.setDebugSymbols(true);

    CompiledExpression compiledD = debuggingCompiler.compile(ctx);

    try {
      sixth = executeExpression(compiledD, new Base(), createTestMap());
    }
    catch (Exception e) {
      if (failErrors == null) failErrors = new StringAppender();
      failErrors.append("\nSIXTH TEST: { " + ex + " }: EXCEPTION REPORT: \n\n");

      CharArrayWriter writer = new CharArrayWriter();
      e.printStackTrace(new PrintWriter(writer));

      failErrors.append(writer.toCharArray());
    }


    if (sixth != null && !sixth.getClass().isArray()) {
      if (!fifth.equals(sixth)) {
        System.out.println("Payload 1 -- No Symbols: ");
        System.out.println(decompile(compiled));
        System.out.println();

        System.out.println("Payload 2 -- With Symbols: ");
        System.out.println(decompile(compiledD));
        System.out.println();

        throw new AssertionError("Different result from test 5 and 6 (Compiled to Compiled+DebuggingSymbols) [first: "
            + valueOf(fifth) + "; second: " + valueOf(sixth) + "]");
      }
    }

    try {
      seventh = executeExpression(compiledD, new Base(), createTestMap());
    }
    catch (Exception e) {
      if (failErrors == null) failErrors = new StringAppender();
      failErrors.append("\nSEVENTH TEST: { " + ex + " }: EXCEPTION REPORT: \n\n");

      CharArrayWriter writer = new CharArrayWriter();
      e.printStackTrace(new PrintWriter(writer));

      failErrors.append(writer.toCharArray());
    }

    if (seventh != null && !seventh.getClass().isArray()) {
      if (!seventh.equals(sixth)) {
        throw new AssertionError("Different result from test 4 and 5 (Compiled Re-Run / Reflective) [first: "
            + valueOf(first) + "; second: " + valueOf(second) + "]");
      }
    }

    try {
      Serializable xx = serializationTest(compiledD);
      AbstractParser.resetParserContext();
      eighth = executeExpression(xx, new Base(), new MapVariableResolverFactory(createTestMap()));
    }
    catch (Exception e) {
      if (failErrors == null) failErrors = new StringAppender();
      failErrors.append("\nEIGHTH TEST (Serializability): { " + ex + " }: EXCEPTION REPORT: \n\n");

      CharArrayWriter writer = new CharArrayWriter();
      e.printStackTrace(new PrintWriter(writer));

      failErrors.append(writer.toCharArray());
    }

    if (eighth != null && !eighth.getClass().isArray()) {
      if (!eighth.equals(seventh)) {
        throw new AssertionError("Different result from test 7 and 8 (Compiled Re-Run / Reflective) [first: "
            + valueOf(first) + "; second: " + valueOf(second) + "]");
      }
    }


    if (failErrors.length() > 0) {
      System.out.println(decompile(compiledD));
      throw new AssertionError("Detailed Failure Report:\n" + failErrors.toString());
    }

    return fourth;
  }
View Full Code Here

      '.', '?', '/', '`', ' ', '\t', '\n', '\r'
  };

  public static void main(String[] args) throws IOException {
    DecimalFormat df = new DecimalFormat("###,###.##");
    StringAppender append = new StringAppender();
    int len;
    long start = currentTimeMillis();
    long time;
    double rate;

    int seed;

    boolean flip = false;

    Random rand = new Random(System.currentTimeMillis());
    Random rand1 = new Random(System.currentTimeMillis() + 1);
    Random rand2 = new Random(rand1.nextInt());
    Random rand3 = new Random(rand.nextInt(SALTS.length - 1));
    Random rand4 = new Random(rand3.nextInt());

    for (int run = 0; run < MAX; run++) {
      len = (int) (random() * 500) + 10;
      append.reset();

      for (int i = 0; i < len; i++) {
        append.append(CHAR_TABLE[((SALTS[((rand.nextInt(1000)) + 1) % SALTS.length]) * ((flip = !flip) ? rand1.nextInt(1000) : rand2.nextInt(1000)) + 1) % CHAR_TABLE.length]);
        SALTS[rand3.nextInt(SALTS.length - 1)] ^= rand4.nextInt(1000) + 1;
      }


      try {
        MVEL.eval(append.toString());
      }
      catch (UnresolveablePropertyException e) {
        //ignore
      }
      catch (CompileException e) {
        //ignore
      }
      catch (ArithmeticException e) {
        //ignore
      }
      catch (ScriptRuntimeException e) {
        //ignore
      }
      catch (Exception e) {
        System.out.println("untrapped error!\n---\n" + append.toString() + "\n---\n");
        System.out.flush();
        e.printStackTrace();
        System.err.flush();
      }

View Full Code Here

   }

   @DefaultCommand
   public void execScript(@Option(required = true, description = "expr") final String... expr)
   {
      StringAppender appender = new StringAppender();
      for (String s : expr)
      {
         appender.append(s);
      }

      Object retVal = eval(appender.toString(), new ScriptContext(), shell.getEnvironment().getProperties());

      if (retVal != null)
      {
         shell.println(valueOf(retVal));
      }
View Full Code Here

  }

  public static String renderMessage(Object value) {

    if (value instanceof Message) {
      StringAppender appender = new StringAppender();
      Map<String, Object> vars = ((Message) value).getParts();

      boolean first = true;
      for (Map.Entry<String, Object> entry : vars.entrySet()) {
        if (first) {
          first = false;
        }
        else {
          appender.append(", ");
        }

        appender.append(entry.getKey()).append('=').append(entry.getValue());
      }

      return appender.toString();
    }
    return null;
  }
View Full Code Here

TOP

Related Classes of org.mvel2.util.StringAppender

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.