List of usage examples for io.netty.buffer ByteBuf readByte
public abstract byte readByte();
From source file:com.github.vitrifiedcode.javautilities.netty.DiscardServerHandler.java
License:Open Source License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) { ByteBuf in = (ByteBuf) msg; try {//from w w w .j ava 2 s . c o m while (in.isReadable()) { System.out.print((char) in.readByte()); System.out.flush(); } } finally { ReferenceCountUtil.release(msg); } }
From source file:com.goodgamenow.source.serverquery.MasterQueryHandler.java
License:Open Source License
private static String decodeAddress(ByteBuf buf) { return "" + Byte.toUnsignedInt(buf.readByte()) + '.' + Byte.toUnsignedInt(buf.readByte()) + '.' + Byte.toUnsignedInt(buf.readByte()) + '.' + Byte.toUnsignedInt(buf.readByte()); }
From source file:com.groupon.vertx.memcache.stream.MemcacheInputStream.java
License:Apache License
/** * This method handles processing the incoming Buffer from the NetSocket. The Buffer * is not guaranteed to contain a whole message so this method tracks the current state * of the incoming data and notifies the pending commands when enough data has been sent * for a response./*from w w w . ja v a 2s.c o m*/ * * @param processBuffer - The Buffer containing the current set of bytes. */ public void processBuffer(Buffer processBuffer) { if (processBuffer == null || processBuffer.length() == 0) { return; } byte first; byte second; ByteBuf byteBuf = processBuffer.getByteBuf(); while (byteBuf.isReadable()) { first = byteBuf.readByte(); if (first == '\r') { if (byteBuf.isReadable()) { second = byteBuf.readByte(); if (second == '\n') { addCompletedLine(); } previous = second; } else { previous = first; } } else if (first == '\n' && previous == '\r') { addCompletedLine(); previous = first; } else { buffer.write(first); previous = first; } } }
From source file:com.groupon.vertx.redis.RedisInputStream.java
License:Apache License
/** * This method handles processing the incoming Buffer from the NetSocket. The Buffer * is not guaranteed to contain a whole message so this method tracks the current state * of the incoming data and notifies the pending commands when enough data has been sent * for a response./* w w w . j a v a 2s . c o m*/ * * @param processBuffer - The Buffer containing the current set of bytes. */ public void processBuffer(Buffer processBuffer) { if (processBuffer == null || processBuffer.length() == 0) { return; } byte first; byte second; ByteBuf byteBuf = processBuffer.getByteBuf(); while (byteBuf.isReadable()) { first = byteBuf.readByte(); if (first == '\r' && byteBuf.isReadable()) { second = byteBuf.readByte(); if (second == '\n') { byte[] line = new byte[bufferPosition]; System.arraycopy(buffer, 0, line, 0, line.length); addCompletedLine(line); } else { buffer[bufferPosition++] = first; buffer[bufferPosition++] = second; } } else if (first == '\n' && buffer[bufferPosition - 1] == '\r') { byte[] line = new byte[bufferPosition - 1]; System.arraycopy(buffer, 0, line, 0, line.length); addCompletedLine(line); } else { buffer[bufferPosition++] = first; } } }
From source file:com.heliosapm.ohcrs.core.AbstractDriverCodec.java
License:Apache License
/** * {@inheritDoc}/*from w ww. j a v a 2 s. co m*/ * @see com.heliosapm.ohcrs.core.DriverCodec#readByte(io.netty.buffer.ByteBuf) */ @Override public Byte readByte(final ByteBuf b) throws SQLException { if (checkNull(b)) return null; return b.readByte(); }
From source file:com.heliosapm.ohcrs.core.AbstractDriverCodec.java
License:Apache License
/** * {@inheritDoc}/*from w ww . j a va 2s .co m*/ * @see com.heliosapm.ohcrs.core.DriverCodec#readbyte(io.netty.buffer.ByteBuf) */ @Override public byte readbyte(final ByteBuf b) throws SQLException { if (checkNull(b)) return 0; return b.readByte(); }
From source file:com.heliosapm.shorthand.caster.broadcast.BroadcastListenerRouter.java
License:Open Source License
@Override protected void decode(ChannelHandlerContext ctx, DatagramPacket msg, List<Object> out) throws Exception { ByteBuf data = msg.content(); byte msgType = data.readByte(); BroadcastType bt = BroadcastType.ORD2ENUM.get((int) msgType); log("Processing Broadcast [%s]", bt.name()); BroadcastExecutable exec = bt.unmarshallPacket(data.nioBuffer(), msg.sender()); taskThreadPool.execute(exec);// w ww .ja va2 s . co m }
From source file:com.heliosapm.streams.metrics.StreamedMetric.java
License:Open Source License
/** * Reads a streamed metric from the passed byte array * @param bytes the byte array to read the streamed metric from * @return the appropriate type of StreamedMetric *//*from w ww. j a va 2 s .co m*/ public static StreamedMetric read(final byte[] bytes) { final ByteBuf buff = BufferManager.getInstance().directBuffer(bytes.length).writeBytes(bytes); try { final byte type = buff.readByte(); switch (type) { case 0: return StreamedMetric.fromBuff(buff); case 1: return StreamedMetricValue.fromBuff(buff); default: throw new RuntimeException("Unrecognized metric type code [" + type + "]"); } } finally { try { buff.release(); } catch (Exception x) { /* No Op */} } }
From source file:com.heliosapm.streams.metrics.StreamedMetric.java
License:Open Source License
/** * Reads a streamed metric from the passed buffer * @param buff the buffer to read the streamed metric from * @return the appropriate type of StreamedMetric *///from w w w.ja v a 2 s .c o m public static StreamedMetric read(final ByteBuf buff) { final byte type = buff.readByte(); switch (type) { case 0: return StreamedMetric.fromBuff(buff); case 1: return StreamedMetricValue.fromBuff(buff); default: throw new RuntimeException("Unrecognized metric type code [" + type + "]"); } }
From source file:com.heliosapm.streams.metrics.StreamedMetric.java
License:Open Source License
void readFromBuff(final ByteBuf buff) { final byte v = buff.readByte(); if (v == 0) { valueType = null;// w w w. j av a 2s . c o m } else { valueType = ValueType.ordinal(v - 1); } timestamp = buff.readLong(); metricName = BufferManager.readUTF(buff); final int tsize = buff.readByte(); for (int i = 0; i < tsize; i++) { final String key = BufferManager.readUTF(buff); final String val = BufferManager.readUTF(buff); tags.put(key, val); } }