Examples of FastCharArrayWriter


Examples of jodd.io.FastCharArrayWriter

    if (contentLen != null) {
      contentLenValue = Integer.parseInt(contentLen);

      if (contentLenValue > 0) {
        FastCharArrayWriter fastCharArrayWriter = new FastCharArrayWriter(contentLenValue);

        try {
          StreamUtil.copy(reader, fastCharArrayWriter, contentLenValue);
        } catch (IOException ioex) {
          throw new HttpException(ioex);
        }

        bodyString = fastCharArrayWriter.toString();
      }
    }

    // chunked encoding
    String transferEncoding = header("Transfer-Encoding");
    if (transferEncoding != null && transferEncoding.equalsIgnoreCase("chunked")) {

      FastCharArrayWriter fastCharArrayWriter = new FastCharArrayWriter();
      try {
        while (true) {
          String line = reader.readLine();

          int len = Integer.parseInt(line, 16);

          if (len > 0) {
            StreamUtil.copy(reader, fastCharArrayWriter, len);
            reader.readLine();
          } else {
            // end reached, read trailing headers, if there is any
            readHeaders(reader);
            break;
          }
        }
      } catch (IOException ioex) {
        throw new HttpException(ioex);
      }

      bodyString = fastCharArrayWriter.toString();
    }

    // no body yet - special case
    if (bodyString == null && contentLenValue != 0) {
      // body ends when stream closes
      FastCharArrayWriter fastCharArrayWriter = new FastCharArrayWriter();
      try {
        StreamUtil.copy(reader, fastCharArrayWriter);
      } catch (IOException ioex) {
        throw new HttpException(ioex);
      }
      bodyString = fastCharArrayWriter.toString();
    }

    // BODY READY - PARSE BODY
    String charset = this.charset;
    if (charset == null) {
View Full Code Here

Examples of jodd.io.FastCharArrayWriter

    public void init(char[] content) {
      // create Lagarto
      lagartoParser = new LagartoParser(content, emitStrings);

      // prepare root tag writer
      fastCharArrayWriter = new FastCharArrayWriter();
      tagWriter = new TagWriter(fastCharArrayWriter);
    }
View Full Code Here

Examples of jodd.io.FastCharArrayWriter

  public PrintWriter getWriter() {
    if (outWriter == null) {
      if (outStream != null) {
        throw new IllegalStateException("Can't call getWriter() after getOutputStream()");
      }
      bufferedWriter = new FastCharArrayWriter();
      outWriter = new PrintWriter(bufferedWriter) {
        @Override
        public void close() {
          // do not close the print writer after rendering
          // since it will remove reference to bufferedWriter
View Full Code Here

Examples of org.elasticsearch.common.io.FastCharArrayWriter

*/
@Test
public class XContentBuilderTests {

    @Test public void verifyReuseJsonGenerator() throws Exception {
        FastCharArrayWriter writer = new FastCharArrayWriter();
        XContentGenerator generator = XContentFactory.xContent(XContentType.JSON).createGenerator(writer);
        generator.writeStartObject();
        generator.writeStringField("test", "value");
        generator.writeEndObject();
        generator.flush();

        assertThat(writer.toStringTrim(), equalTo("{\"test\":\"value\"}"));

        // try again...
        writer.reset();
        generator.writeStartObject();
        generator.writeStringField("test", "value");
        generator.writeEndObject();
        generator.flush();
        // we get a space at the start here since it thinks we are not in the root object (fine, we will ignore it in the real code we use)
        assertThat(writer.toStringTrim(), equalTo("{\"test\":\"value\"}"));
    }
View Full Code Here

Examples of org.elasticsearch.common.io.FastCharArrayWriter

    }


    public String buildText() {
        reset();
        FastCharArrayWriter writer = new FastCharArrayWriter();
        for (Entry entry : entries) {
            writer.append(entry.reader());
            writer.append(' ');
        }
        reset();
        return writer.toString();
    }
View Full Code Here

Examples of org.elasticsearch.common.io.FastCharArrayWriter

*/
public class XContentBuilderTests extends ElasticsearchTestCase {

    @Test
    public void testPrettyWithLfAtEnd() throws Exception {
        FastCharArrayWriter writer = new FastCharArrayWriter();
        XContentGenerator generator = XContentFactory.xContent(XContentType.JSON).createGenerator(writer);
        generator.usePrettyPrint();
        generator.usePrintLineFeedAtEnd();

        generator.writeStartObject();
        generator.writeStringField("test", "value");
        generator.writeEndObject();
        generator.flush();

        generator.close();
        // double close, and check there is no error...
        generator.close();

        assertThat(writer.unsafeCharArray()[writer.size() - 1], equalTo('\n'));
    }
View Full Code Here

Examples of org.elasticsearch.common.io.FastCharArrayWriter

        assertThat(writer.unsafeCharArray()[writer.size() - 1], equalTo('\n'));
    }

    @Test
    public void verifyReuseJsonGenerator() throws Exception {
        FastCharArrayWriter writer = new FastCharArrayWriter();
        XContentGenerator generator = XContentFactory.xContent(XContentType.JSON).createGenerator(writer);
        generator.writeStartObject();
        generator.writeStringField("test", "value");
        generator.writeEndObject();
        generator.flush();

        assertThat(writer.toStringTrim(), equalTo("{\"test\":\"value\"}"));

        // try again...
        writer.reset();
        generator.writeStartObject();
        generator.writeStringField("test", "value");
        generator.writeEndObject();
        generator.flush();
        // we get a space at the start here since it thinks we are not in the root object (fine, we will ignore it in the real code we use)
        assertThat(writer.toStringTrim(), equalTo("{\"test\":\"value\"}"));
    }
View Full Code Here

Examples of org.elasticsearch.common.io.FastCharArrayWriter

    }


    public String buildText() {
        reset();
        FastCharArrayWriter writer = new FastCharArrayWriter();
        for (Entry entry : entries) {
            writer.append(entry.reader());
            writer.append(' ');
        }
        reset();
        return writer.toString();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.