Package ratpack.util.internal

Examples of ratpack.util.internal.ByteBufWriteThroughOutputStream


    w.println("</table>");
  }

  protected void render(Context context, String pageTitle, Consumer<? super BodyWriter> body) {
    ByteBuf buffer = context.getLaunchConfig().getBufferAllocator().buffer();
    OutputStream out = new ByteBufWriteThroughOutputStream(buffer);
    PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(out, CharsetUtil.UTF_8));
    BodyWriter writer = new BodyWriter(printWriter);

    writer
      .println("<!DOCTYPE html>")
View Full Code Here


    @Override
    public ByteBuf apply(ServerSentEvent serverSentEvent) throws Exception {
      ByteBuf buffer = bufferAllocator.buffer();

      OutputStream outputStream = new ByteBufWriteThroughOutputStream(buffer);
      Writer writer = new OutputStreamWriter(outputStream, UTF_8);

      String eventType = serverSentEvent.getEventType();
      if (eventType != null) {
        outputStream.write(EVENT_TYPE_PREFIX);
        writer.append(eventType).flush();
        outputStream.write(NEWLINE);
      }

      String eventData = serverSentEvent.getEventData();
      if (eventData != null) {
        outputStream.write(EVENT_DATA_PREFIX);
        for (Character character : Lists.charactersOf(eventData)) {
          if (character == '\n') {
            outputStream.write(NEWLINE);
            outputStream.write(EVENT_DATA_PREFIX);
          } else {
            writer.append(character).flush();
          }
        }
        outputStream.write(NEWLINE);
      }


      String eventId = serverSentEvent.getEventId();
      if (eventId != null) {
        outputStream.write(EVENT_ID_PREFIX);
        writer.append(eventId).flush();
        outputStream.write(NEWLINE);
      }

      outputStream.write(NEWLINE);
      writer.flush();
      writer.close();
      return buffer;
    }
View Full Code Here

      }

      @Override
      public Body stream(Action<? super OutputStream> action) throws Exception {
        ByteBuf byteBuf = byteBufAllocator.buffer();
        try (OutputStream outputStream = new ByteBufWriteThroughOutputStream(byteBuf)) {
          action.execute(outputStream);
        } catch (Throwable t) {
          byteBuf.release();
          throw t;
        }
View Full Code Here

TOP

Related Classes of ratpack.util.internal.ByteBufWriteThroughOutputStream

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.