Java Code Examples for org.jboss.netty.buffer.ChannelBuffer#getByte()
The following examples show how to use
org.jboss.netty.buffer.ChannelBuffer#getByte() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BitmapFromImage.java From rosjava_android_template with Apache License 2.0 | 6 votes |
@Override public Bitmap call(sensor_msgs.Image message) { Preconditions.checkArgument(message.getEncoding().equals("rgb8")); Bitmap bitmap = Bitmap.createBitmap(message.getWidth(), message.getHeight(), Bitmap.Config.ARGB_8888); for (int x = 0; x < message.getWidth(); x++) { for (int y = 0; y < message.getHeight(); y++) { ChannelBuffer data = message.getData(); byte red = data.getByte(y * message.getStep() + 3 * x); byte green = data.getByte(y * message.getStep() + 3 * x + 1); byte blue = data.getByte(y * message.getStep() + 3 * x + 2); bitmap.setPixel(x, y, Color.argb(255, red & 0xFF, green & 0xFF, blue & 0xFF)); } } return bitmap; }
Example 2
Source File: SizeHeaderFrameDecoder.java From Elasticsearch with Apache License 2.0 | 5 votes |
private boolean bufferStartsWith(ChannelBuffer buffer, int readerIndex, String method) { char[] chars = method.toCharArray(); for (int i = 0; i < chars.length; i++) { if (buffer.getByte(readerIndex + i) != chars[i]) { return false; } } return true; }
Example 3
Source File: DeflateCompressor.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public boolean isCompressed(ChannelBuffer buffer) { if (buffer.readableBytes() < HEADER.length) { return false; } final int offset = buffer.readerIndex(); for (int i = 0; i < HEADER.length; ++i) { if (buffer.getByte(offset + i) != HEADER[i]) { return false; } } return true; }
Example 4
Source File: LZFCompressor.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public boolean isCompressed(ChannelBuffer buffer) { int offset = buffer.readerIndex(); return buffer.readableBytes() >= 3 && buffer.getByte(offset) == LZFChunk.BYTE_Z && buffer.getByte(offset + 1) == LZFChunk.BYTE_V && (buffer.getByte(offset + 2) == LZFChunk.BLOCK_TYPE_COMPRESSED || buffer.getByte(offset + 2) == LZFChunk.BLOCK_TYPE_NON_COMPRESSED); }
Example 5
Source File: RaopRtpPacket.java From Android-Airplay-Server with MIT License | 5 votes |
/** * Reads an 32-bit unsigned integer from a channel buffer * @param buffer the channel buffer * @param index the start index * @return the integer, as long to preserve the original sign */ public static long getBeUInt(final ChannelBuffer buffer, final int index) { return ( ((buffer.getByte(index+0) & 0xffL) << 24) | ((buffer.getByte(index+1) & 0xffL) << 16) | ((buffer.getByte(index+2) & 0xffL) << 8) | ((buffer.getByte(index+3) & 0xffL) << 0) ); }
Example 6
Source File: RaopRtpPacket.java From Android-Airplay-Server with MIT License | 5 votes |
/** * Reads an 16-bit unsigned integer from a channel buffer * @param buffer the channel buffer * @param index the start index * @return the short, as int to preserve the original sign */ public static int getBeUInt16(final ChannelBuffer buffer, final int index) { return (int)( ((buffer.getByte(index+0) & 0xffL) << 8) | ((buffer.getByte(index+1) & 0xffL) << 0) ); }
Example 7
Source File: MessageDecoder.java From chuidiang-ejemplos with GNU Lesser General Public License v3.0 | 5 votes |
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception { System.out.println(ctx.canHandleUpstream()); List<List<Byte>> objectsDecoded = new LinkedList<>(); int initialIndex = buffer.readerIndex(); int readableBytes = buffer.readableBytes(); List<Byte> bytes = new LinkedList<>(); for (int i = initialIndex; i < initialIndex + readableBytes; i++) { if (buffer.getByte(i) == 0) { buffer.readerIndex(i + 1); objectsDecoded.add(bytes); bytes = new LinkedList<>(); } else { bytes.add(buffer.getByte(i)); } } if (objectsDecoded.size()>0){ return objectsDecoded; } return null; }
Example 8
Source File: ChannelBuffers.java From simple-netty-source with Apache License 2.0 | 5 votes |
private static int firstIndexOf(ChannelBuffer buffer, int fromIndex, int toIndex, byte value) { fromIndex = Math.max(fromIndex, 0); if (fromIndex >= toIndex || buffer.capacity() == 0) { return -1; } for (int i = fromIndex; i < toIndex; i ++) { if (buffer.getByte(i) == value) { return i; } } return -1; }
Example 9
Source File: ChannelBuffers.java From simple-netty-source with Apache License 2.0 | 5 votes |
private static int lastIndexOf(ChannelBuffer buffer, int fromIndex, int toIndex, byte value) { fromIndex = Math.min(fromIndex, buffer.capacity()); if (fromIndex < 0 || buffer.capacity() == 0) { return -1; } for (int i = fromIndex - 1; i >= toIndex; i --) { if (buffer.getByte(i) == value) { return i; } } return -1; }
Example 10
Source File: Hybi10WebSocketFrameDecoder.java From restcommander with Apache License 2.0 | 5 votes |
private void unmask(ChannelBuffer frame) { byte[] bytes = frame.array(); for (int i = 0; i < bytes.length; i++) { int b = frame.getByte(i) ^ maskingKey.getByte(i % 4); frame.setByte(i, b); } }
Example 11
Source File: PcepFactories.java From onos with Apache License 2.0 | 5 votes |
@Override public PcepMessage readFrom(ChannelBuffer bb) throws PcepParseException, PcepOutOfBoundMessageException { if (!bb.readable()) { throw new PcepParseException("Empty message received"); } /* * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Ver | Flags | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * * Currently Version 1 is supported * Currently no flags are used, it is all ignored */ byte packetVersion = bb.getByte(bb.readerIndex()); packetVersion = (byte) (packetVersion >> SHIFT_FLAG); PcepFactory factory; switch (packetVersion) { case 1: factory = org.onosproject.pcepio.protocol.ver1.PcepFactoryVer1.INSTANCE; break; default: throw new PcepParseException("Unknown Packet version: " + packetVersion); } return factory.getReader().readFrom(bb); }
Example 12
Source File: SizeHeaderFrameDecoder.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception { if (buffer.readableBytes() < 6) { return null; } int readerIndex = buffer.readerIndex(); if (buffer.getByte(readerIndex) != 'E' || buffer.getByte(readerIndex + 1) != 'S') { // special handling for what is probably HTTP if (bufferStartsWith(buffer, readerIndex, "GET ") || bufferStartsWith(buffer, readerIndex, "POST ") || bufferStartsWith(buffer, readerIndex, "PUT ") || bufferStartsWith(buffer, readerIndex, "HEAD ") || bufferStartsWith(buffer, readerIndex, "DELETE ") || bufferStartsWith(buffer, readerIndex, "OPTIONS ") || bufferStartsWith(buffer, readerIndex, "PATCH ") || bufferStartsWith(buffer, readerIndex, "TRACE ")) { throw new HttpOnTransportException("This is not a HTTP port"); } // we have 6 readable bytes, show 4 (should be enough) throw new StreamCorruptedException("invalid internal transport message format, got (" + Integer.toHexString(buffer.getByte(readerIndex) & 0xFF) + "," + Integer.toHexString(buffer.getByte(readerIndex + 1) & 0xFF) + "," + Integer.toHexString(buffer.getByte(readerIndex + 2) & 0xFF) + "," + Integer.toHexString(buffer.getByte(readerIndex + 3) & 0xFF) + ")"); } int dataLen = buffer.getInt(buffer.readerIndex() + 2); if (dataLen == NettyHeader.PING_DATA_SIZE) { // discard the messages we read and continue, this is achieved by skipping the bytes // and returning null buffer.skipBytes(6); return null; } if (dataLen <= 0) { throw new StreamCorruptedException("invalid data length: " + dataLen); } // safety against too large frames being sent if (dataLen > NINETY_PER_HEAP_SIZE) { throw new TooLongFrameException( "transport content length received [" + new ByteSizeValue(dataLen) + "] exceeded [" + new ByteSizeValue(NINETY_PER_HEAP_SIZE) + "]"); } if (buffer.readableBytes() < dataLen + 6) { return null; } buffer.skipBytes(6); return buffer; }
Example 13
Source File: ChannelBuffers.java From simple-netty-source with Apache License 2.0 | 4 votes |
/** * Returns {@code true} if and only if the two specified buffers are * identical to each other as described in {@code ChannelBuffer#equals(Object)}. * This method is useful when implementing a new buffer type. */ public static boolean equals(ChannelBuffer bufferA, ChannelBuffer bufferB) { final int aLen = bufferA.readableBytes(); if (aLen != bufferB.readableBytes()) { return false; } final int longCount = aLen >>> 3; final int byteCount = aLen & 7; int aIndex = bufferA.readerIndex(); int bIndex = bufferB.readerIndex(); if (bufferA.order() == bufferB.order()) { for (int i = longCount; i > 0; i --) { if (bufferA.getLong(aIndex) != bufferB.getLong(bIndex)) { return false; } aIndex += 8; bIndex += 8; } } else { for (int i = longCount; i > 0; i --) { if (bufferA.getLong(aIndex) != swapLong(bufferB.getLong(bIndex))) { return false; } aIndex += 8; bIndex += 8; } } for (int i = byteCount; i > 0; i --) { if (bufferA.getByte(aIndex) != bufferB.getByte(bIndex)) { return false; } aIndex ++; bIndex ++; } return true; }
Example 14
Source File: NodeDescriptors.java From onos with Apache License 2.0 | 4 votes |
/** * Reads node descriptors Sub-TLVs. * * @param cb ChannelBuffer * @param desLength node descriptor length * @param desType local node descriptor or remote node descriptor type * @param protocolId protocol ID * @return object of NodeDescriptors * @throws BgpParseException while parsing node descriptors */ public static NodeDescriptors read(ChannelBuffer cb, short desLength, short desType, byte protocolId) throws BgpParseException { log.debug("Read NodeDescriptor"); List<BgpValueType> subTlvs = new LinkedList<>(); BgpValueType tlv = null; while (cb.readableBytes() > 0) { ChannelBuffer tempBuf = cb.copy(); short type = cb.readShort(); short length = cb.readShort(); if (cb.readableBytes() < length) { throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR, tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN)); } ChannelBuffer tempCb = cb.readBytes(length); switch (type) { case AutonomousSystemTlv.TYPE: tlv = AutonomousSystemTlv.read(tempCb); break; case BgpLSIdentifierTlv.TYPE: tlv = BgpLSIdentifierTlv.read(tempCb); break; case AreaIDTlv.TYPE: tlv = AreaIDTlv.read(tempCb); break; case IGP_ROUTERID_TYPE: if (protocolId == IS_IS_LEVEL_1_PROTOCOL_ID || protocolId == IS_IS_LEVEL_2_PROTOCOL_ID) { boolean isNonPseudoNode = true; if ((length == ISISPSEUDONODE_LEN) && (tempCb.getByte(ISISPSEUDONODE_LEN - 1) != 0)) { isNonPseudoNode = false; } if (isNonPseudoNode) { tlv = IsIsNonPseudonode.read(tempCb); } else { tlv = IsIsPseudonode.read(tempCb); } } else if (protocolId == OSPF_V2_PROTOCOL_ID || protocolId == OSPF_V3_PROTOCOL_ID) { if (length == OSPFNONPSEUDONODE_LEN) { tlv = OspfNonPseudonode.read(tempCb); } else if (length == OSPFPSEUDONODE_LEN) { tlv = OspfPseudonode.read(tempCb); } } break; default: UnSupportedAttribute.skipBytes(tempCb, length); } subTlvs.add(tlv); } return new NodeDescriptors(subTlvs, desLength, desType); }