Package httl.util

Examples of httl.util.UnsafeByteArrayOutputStream


  }

  public Object evaluate(Object parameters)
      throws ParseException {
    if (Context.getContext().getOut() instanceof OutputStream) {
      UnsafeByteArrayOutputStream output = new UnsafeByteArrayOutputStream();
      try {
        render(parameters, output);
      } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
      }
      return output.toByteArray();
    } else {
      UnsafeStringWriter writer = new UnsafeStringWriter();
      try {
        render(parameters, writer);
      } catch (IOException e) {
View Full Code Here


      return new UnsafeByteArrayInputStream(getByteCode());
    }

    @Override
    public OutputStream openOutputStream() {
      return bytecode = new UnsafeByteArrayOutputStream();
    }
View Full Code Here

  public String toString(String key, Object value) {
    return XSTREAM.toXML(value);
  }

  public byte[] toBytes(String key, Object value) {
    UnsafeByteArrayOutputStream out = new UnsafeByteArrayOutputStream();
    XSTREAM.toXML(value, out);
    return out.toByteArray();
  }
View Full Code Here

        mapConverter, outConverter, functions, importMacros, resource, template, root);
  }

  @Override
  public Object evaluate(Object parameters) throws ParseException {
    UnsafeByteArrayOutputStream output = new UnsafeByteArrayOutputStream();
    try {
      render(parameters, output);
    } catch (IOException e) {
      throw new RuntimeException(e.getMessage(), e);
    }
    return output.toByteArray();
  }
View Full Code Here

    Engine _engine = engine;
    if ("extends_default.httl".equals(templateName)) {
      _engine = Engine.getEngine("httl-comment-extends.properties");
    }
    Template template = _engine.getTemplate("/templates/" + templateName, Locale.CHINA, encoding, data);
    UnsafeByteArrayOutputStream actualStream = new UnsafeByteArrayOutputStream();
    StringWriter actualWriter = new StringWriter();
    if ("extends_var.httl".equals(templateName)) {
      if (data instanceof Map) {
        ((Map<String, Object>) data).put("extends", "default.httl");
      } else if (data instanceof Model) {
        ((Model) data).setExtends("default.httl");
      }
    }
    try {
      template.render(data, actualWriter);
      template.render(data, actualStream);
    } catch (Throwable e) {
      System.out.println("\n================================\n" +  config + ": " + template.getName() + "\n================================\n");
      e.printStackTrace();
      throw new IllegalStateException(e.getMessage() + "\n================================\n" +  config + ": " + template.getName() + "\n================================\n", e);
    }
    if ("extends_var.httl".equals(templateName)) {
      if (data instanceof Map) {
        ((Map<String, Object>) data).remove("extends");
      } else if (data instanceof Model) {
        ((Model) data).setExtends(null);
      }
    }
    if (data != null && ! (data instanceof String)) { // FIXME JSON数据的Map没有排序,导致断言失败,暂先跳过
      URL url = this.getClass().getClassLoader().getResource(dir + "results/" + templateName + ".txt");
      if (url == null) {
        throw new FileNotFoundException("Not found file: " + dir + "results/" + templateName + ".txt");
      }
      File result = new File(url.getFile());
      if (! result.exists()) {
        throw new FileNotFoundException("Not found file: " + result.getAbsolutePath());
      }
      String expected = IOUtils.readToString(new InputStreamReader(new FileInputStream(result), encoding));
      expected = expected.replace("\r", "");
      if ("httl-comment-text.properties".equals(config)
          && ! template.getSource().contains("read(")) {
        expected = expected.replace("<!--", "").replace("-->", "");
      }
      assertEquals(templateName, expected, actualWriter.getBuffer().toString().replace("\r", ""));
      assertEquals(templateName, expected, new String(actualStream.toByteArray()).replace("\r", ""));
      if ("set_parameters.httl".equals(templateName)) {
        assertEquals(templateName, "abc", Context.getContext().get("title"));
      }
    }
  }
View Full Code Here

TOP

Related Classes of httl.util.UnsafeByteArrayOutputStream

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.