public static byte[] serialize(Object value) { try { ReusableWritable output = new ReusableWritable(); ObjectOutputStream out = new ObjectOutputStream(output); out.writeObject(value); output.close(); return output.copy(); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public synchronized void write(byte[] b) { chunk.write(b); }
protected void writeJsonBody(MaybeReq req, Channel ctx, Object value) { writeContentTypeHeader(ctx, MediaType.JSON); ReusableWritable out = Msc.locals().jsonRenderingStream(); JSON.stringify(value, out); HttpIO.INSTANCE.writeContentLengthHeader(ctx, out.size()); HttpIO.INSTANCE.closeHeaders(req, ctx.output()); ctx.write(out.array(), 0, out.size()); }
@Override public byte[] renderToBytes(Object model) { RapidoidThreadLocals locals = Msc.locals(); ReusableWritable out = locals.templateRenderingOutput(); doRender(locals, out, model); return out.copy(); }
public ReusableWritable pageRenderingStream() { pageRenderingStream.reset(); return pageRenderingStream; }
private void expand(int requiredCapacity) { // double the capacity, using "long" to prevent overflow long newCapacity = capacity() * 2; // if still not enough, expand up to the required capacity if (newCapacity < requiredCapacity) newCapacity = requiredCapacity; // if the size is too big, cap it newCapacity = Math.min(newCapacity, MAX_SIZE); // after all, the new capacity might not be enough U.must(newCapacity >= requiredCapacity, "Cannot expand the buffer to size %s, the limit is %s!", requiredCapacity, newCapacity); bytes = Arrays.copyOf(bytes, (int) newCapacity); }
private void writeJsonResponse(MaybeReq req, Resp resp, Channel ctx, boolean isKeepAlive, int code, MediaType contentType, Object result) { startResponse(resp, ctx, code, isKeepAlive, contentType); RapidoidThreadLocals locals = Msc.locals(); ReusableWritable out = locals.jsonRenderingStream(); // FIXME headers JSON.stringify(result, out); writeContentLengthHeader(ctx, out.size()); closeHeaders(req, ctx.output()); ctx.write(out.array(), 0, out.size()); }
public static byte[] renderPage(ReqImpl req, String content) { PageDecorator pageDecorator = Customization.of(req).pageDecorator(); U.must(pageDecorator != null, "A page decorator wasn't configured!"); ReusableWritable out = Msc.locals().pageRenderingStream(); try { pageDecorator.renderPage(req, content, out); } catch (Exception e) { throw U.rte("Error while rendering page!", e); } return out.copy(); }
public ReusableWritable jsonRenderingStream() { jsonRenderingStream.reset(); return jsonRenderingStream; }
protected void writeJsonBody(MaybeReq req, Channel ctx, Object value) { writeContentTypeHeader(ctx, MediaType.JSON); ReusableWritable out = Msc.locals().jsonRenderingStream(); JSON.stringify(value, out); HttpIO.INSTANCE.writeContentLengthHeader(ctx, out.size()); HttpIO.INSTANCE.closeHeaders(req, ctx.output()); ctx.write(out.array(), 0, out.size()); }
@Override public byte[] renderToBytes(Object model) { RapidoidThreadLocals locals = Msc.locals(); ReusableWritable out = locals.templateRenderingOutput(); doRender(locals, out, model); return out.copy(); }
public ReusableWritable templateRenderingOutput() { templateRenderingOutput.reset(); return templateRenderingOutput; }
@Override public synchronized void write(byte[] b, int off, int len) { chunk.write(b, off, len); }
private void writeJsonResponse(MaybeReq req, Resp resp, Channel ctx, boolean isKeepAlive, int code, MediaType contentType, Object result) { startResponse(resp, ctx, code, isKeepAlive, contentType); RapidoidThreadLocals locals = Msc.locals(); ReusableWritable out = locals.jsonRenderingStream(); // FIXME headers JSON.stringify(result, out); writeContentLengthHeader(ctx, out.size()); closeHeaders(req, ctx.output()); ctx.write(out.array(), 0, out.size()); }
public static byte[] renderPage(ReqImpl req, String content) { PageDecorator pageDecorator = Customization.of(req).pageDecorator(); U.must(pageDecorator != null, "A page decorator wasn't configured!"); ReusableWritable out = Msc.locals().pageRenderingStream(); try { pageDecorator.renderPage(req, content, out); } catch (Exception e) { throw U.rte("Error while rendering page!", e); } return out.copy(); }
@Override public synchronized void write(int b) { chunk.write(b); }
@Override public synchronized void write(byte[] b) throws IOException { chunk.write(b); }