List of usage examples for io.netty.buffer ByteBuf toString
public abstract String toString(Charset charset);
From source file:org.redisson.client.protocol.decoder.StringDataDecoder.java
License:Apache License
@Override public String decode(ByteBuf buf, State state) { return buf.toString(CharsetUtil.UTF_8); }
From source file:org.redisson.client.protocol.decoder.StringMapDataDecoder.java
License:Apache License
@Override public Map<String, String> decode(ByteBuf buf, State state) { String value = buf.toString(CharsetUtil.UTF_8); Map<String, String> result = new HashMap<String, String>(); for (String entry : value.split("\r\n|\n")) { String[] parts = entry.split(":"); if (parts.length == 2) { result.put(parts[0], parts[1]); }/*from w w w . j a v a 2s . c o m*/ } return result; }
From source file:org.redisson.client.protocol.pubsub.PubSubStatusDecoder.java
License:Apache License
@Override public Object decode(ByteBuf buf, State state) { String status = buf.toString(CharsetUtil.UTF_8); buf.skipBytes(2);/* ww w . j a v a2 s .c o m*/ return status; }
From source file:org.redisson.misc.Hash.java
License:Apache License
public static String hashToBase64(byte[] objectState) { long h1 = LongHashFunction.farmUo().hashBytes(objectState); long h2 = LongHashFunction.xx_r39().hashBytes(objectState); ByteBuf buf = Unpooled.buffer((2 * Long.SIZE) / Byte.SIZE).writeLong(h1).writeLong(h2); ByteBuf b = Base64.encode(buf); String s = b.toString(CharsetUtil.UTF_8); b.release();/*from www. ja va 2s .c om*/ buf.release(); return s.substring(0, s.length() - 2); }
From source file:org.redisson.spring.data.connection.PropertiesDecoder.java
License:Apache License
@Override public Properties decode(ByteBuf buf, State state) { String value = buf.toString(CharsetUtil.UTF_8); Properties result = new Properties(); for (String entry : value.split("\r\n|\n")) { String[] parts = entry.split(":"); if (parts.length == 2) { result.put(parts[0], parts[1]); }// w ww.j a va2 s. c om } return result; }
From source file:org.redisson.spring.data.connection.RedisClusterNodeDecoder.java
License:Apache License
@Override public List<RedisClusterNode> decode(ByteBuf buf, State state) throws IOException { String response = buf.toString(CharsetUtil.UTF_8); List<RedisClusterNode> nodes = new ArrayList<RedisClusterNode>(); for (String nodeInfo : response.split("\n")) { String[] params = nodeInfo.split(" "); String nodeId = params[0]; String flagsStr = params[2]; Set<Flag> flags = EnumSet.noneOf(Flag.class); for (String flag : flagsStr.split(",")) { String flagValue = flag.toUpperCase().replaceAll("\\?", ""); flags.add(Flag.valueOf(flagValue)); }/*from www .jav a 2 s . c om*/ RedisURI address = null; if (!flags.contains(Flag.NOADDR)) { String addr = params[1].split("@")[0]; address = new RedisURI("redis://" + addr); } String masterId = params[3]; if ("-".equals(masterId)) { masterId = null; } Set<Integer> slotsCollection = new HashSet<Integer>(); LinkState linkState = null; if (params.length >= 8 && params[7] != null) { linkState = LinkState.valueOf(params[7].toUpperCase()); } if (params.length > 8) { for (int i = 0; i < params.length - 8; i++) { String slots = params[i + 8]; if (slots.indexOf("-<-") != -1 || slots.indexOf("->-") != -1) { continue; } String[] parts = slots.split("-"); if (parts.length == 1) { slotsCollection.add(Integer.valueOf(parts[0])); } else if (parts.length == 2) { for (int j = Integer.valueOf(parts[0]); j < Integer.valueOf(parts[1]) + 1; j++) { slotsCollection.add(j); } } } } NodeType type = null; if (flags.contains(Flag.MASTER)) { type = NodeType.MASTER; } else if (flags.contains(Flag.SLAVE)) { type = NodeType.SLAVE; } RedisClusterNodeBuilder builder = RedisClusterNode.newRedisClusterNode().linkState(linkState) .slaveOf(masterId).serving(new SlotRange(slotsCollection)).withId(nodeId).promotedAs(type) .withFlags(flags); if (address != null) { builder.listeningAt(address.getHost(), address.getPort()); } nodes.add(builder.build()); } return nodes; }
From source file:org.restexpress.response.StringBufferHttpResponseWriter.java
License:Apache License
@Override public void write(ChannelHandlerContext ctx, Request request, Response response) { if (headers != null) { for (String headerName : response.getHeaderNames()) { List<String> headerValues = new ArrayList<String>(response.getHeaders(headerName)); headers.put(headerName, headerValues); }// ww w. j a v a 2s . com } if (response.getBody() == null) { body.append("null"); return; } if (ByteBuf.class.isAssignableFrom(response.getBody().getClass())) { ByteBuf buf = (ByteBuf) response.getBody(); body.append(buf.toString(ContentType.CHARSET)); return; } body.append(response.getBody()); }
From source file:org.rzo.netty.ahessian.session.ClientSessionFilter.java
License:Apache License
public void messageReceived(ChannelHandlerContext ctx, Object e) throws Exception { // if session established forward all messages if (_hasSession) ctx.fireChannelRead(e);/*from w w w . ja v a 2 s .c o m*/ else { ByteBuf b = (ByteBuf) e; _sessionId += b.toString(Charset.forName("UTF-8")); checkSession(ctx); } }
From source file:org.rzo.netty.ahessian.session.ServerSessionFilter.java
License:Apache License
public void channelRead(ChannelHandlerContext ctx, Object e) throws Exception { // if session established forward all messages if (_hasSession) { Session session = ctx.channel().attr(SESSION).get(); session.onMessage();/* w w w.ja va 2s . c om*/ ctx.fireChannelRead(e); } else { ByteBuf b = (ByteBuf) e; _sessionId += b.toString(Charset.forName("UTF-8")); b.release(b.refCnt()); if (_sessionId.equals("?")) newSession(ctx); else checkSession(ctx); } }
From source file:org.rzo.netty.mcast.MulticastEndpoint.java
License:Apache License
public String getStringMessage(ByteBuf e) { ByteBuf m = getMessage(e); if (m == null) return null; return m.toString(Charset.defaultCharset()); }