List of usage examples for io.netty.buffer ByteBufUtil encodeString
public static ByteBuf encodeString(ByteBufAllocator alloc, CharBuffer src, Charset charset)
From source file:jazmin.server.msg.codec.json.JSONEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, ResponseMessage msg, ByteBuf out) throws Exception { //send raw data if (msg.rawData != null) { out.writeBytes(msg.rawData);/*from w w w .ja v a 2 s . c o m*/ return; } // ResponseProto bean = new ResponseProto(); bean.d = (System.currentTimeMillis()); bean.ri = (msg.requestId); bean.rsp = (msg.responseMessages); bean.si = (msg.serviceId); bean.sc = (msg.statusCode); bean.sm = (msg.statusMessage); String json = JSON.toJSONString(bean) + "\n"; if (logger.isDebugEnabled()) { logger.debug("\nencode message--------------------------------------\n" + DumpUtil.formatJSON(json)); } ByteBuf result = ByteBufUtil.encodeString(ctx.alloc(), CharBuffer.wrap(json), charset); out.writeBytes(result); networkTrafficStat.outBound(json.getBytes().length); }
From source file:org.apache.camel.component.netty4.codec.DatagramPacketStringEncoder.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, AddressedEnvelope<Object, InetSocketAddress> msg, List<Object> out) throws Exception { if (msg.content() instanceof CharSequence) { CharSequence payload = (CharSequence) msg.content(); if (payload.length() == 0) { return; }/*from w ww . j a va 2 s.c o m*/ AddressedEnvelope<Object, InetSocketAddress> addressedEnvelop = new DefaultAddressedEnvelope<Object, InetSocketAddress>( ByteBufUtil.encodeString(ctx.alloc(), CharBuffer.wrap(payload), charset), msg.recipient(), msg.sender()); out.add(addressedEnvelop); } }
From source file:ratpack.groovy.template.internal.DefaultTextTemplateScript.java
License:Apache License
@SuppressWarnings("UnusedDeclaration") public void $(CharSequence charSequence) { //CHECKSTYLE:ON ByteBuf byteBuf = ByteBufUtil.encodeString(buffer.alloc(), CharBuffer.wrap(charSequence.toString()), CharsetUtil.UTF_8);//www . j a v a 2 s. c o m buffer.writeBytes(byteBuf); byteBuf.release(); }
From source file:ratpack.http.internal.DefaultResponse.java
License:Apache License
public void send(String text) { ByteBuf byteBuf = ByteBufUtil.encodeString(byteBufAllocator, CharBuffer.wrap(text), CharsetUtil.UTF_8); contentTypeIfNotSet(HttpHeaderConstants.PLAIN_TEXT_UTF8).send(byteBuf); }
From source file:ratpack.http.ResponseChunks.java
License:Apache License
/** * Transmit each string emitted by the publisher as a chunk. * <p>// w w w. j av a 2 s . co m * The content type of the response is set to the given content type and each string is decoded as the given charset. * * @param contentType the value for the content-type header * @param charset the charset to use to decode each string chunk * @param publisher a publisher of strings * @return a renderable object */ public static ResponseChunks stringChunks(CharSequence contentType, Charset charset, Publisher<? extends CharSequence> publisher) { return new ResponseChunks(contentType, allocator -> Streams.map(publisher, charSequence -> ByteBufUtil.encodeString(allocator, CharBuffer.wrap(charSequence), charset))); }
From source file:ratpack.session.clientside.internal.ClientSideSessionStore.java
License:Apache License
private ByteBuf fromBase64(ByteBufAllocator bufferAllocator, String string) { ByteBuf byteBuf = ByteBufUtil.encodeString(bufferAllocator, CharBuffer.wrap(string), CharsetUtil.ISO_8859_1);/* ww w .j a v a 2 s.com*/ try { return Base64.decode(byteBuf, Base64Dialect.STANDARD); } finally { byteBuf.release(); } }
From source file:ratpack.session.clientside.internal.DefaultClientSessionService.java
License:Apache License
private ByteBuf encode(ByteBufAllocator bufferAllocator, String value) { String escaped = ESCAPER.escape(value); return ByteBufUtil.encodeString(bufferAllocator, CharBuffer.wrap(escaped), CharsetUtil.UTF_8); }
From source file:ratpack.session.clientside.serializer.JavaValueSerializer.java
License:Apache License
@Override public ByteBuf serialize(Registry registry, ByteBufAllocator bufferAllocator, Object value) throws Exception { ByteArrayOutputStream stream = new ByteArrayOutputStream(); ObjectOutputStream outputStream = new ObjectOutputStream(stream); outputStream.writeObject(value);/* w ww.j a v a 2s.co m*/ outputStream.close(); byte[] bytes = stream.toByteArray(); String encoded = ENCODER.encodeToString(bytes); return ByteBufUtil.encodeString(bufferAllocator, CharBuffer.wrap(encoded), CharsetUtil.UTF_8); }
From source file:ratpack.websocket.WebSockets.java
License:Apache License
public static void websocketBroadcast(final Context context, final Publisher<String> broadcaster) { ByteBufAllocator bufferAllocator = context.get(ByteBufAllocator.class); websocketByteBufBroadcast(context, Streams.map(broadcaster, s -> ByteBufUtil.encodeString(bufferAllocator, CharBuffer.wrap(s), CharsetUtil.UTF_8))); }
From source file:tk.jomp16.irc.netty.NettyEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, CharSequence msg, List<Object> out) throws Exception { if (msg.length() == 0) { return;/*from w w w.ja v a 2 s . c om*/ } log.debug(msg); out.add(ByteBufUtil.encodeString(ctx.alloc(), CharBuffer.wrap(msg + "\n"), charset)); }