Java Code Examples for io.netty.buffer.ByteBufUtil#getBytes()
The following examples show how to use
io.netty.buffer.ByteBufUtil#getBytes() .
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: ParserProxyHandler.java From pulsar with Apache License 2.0 | 6 votes |
private void logging(Channel conn, PulsarApi.BaseCommand.Type cmdtype, String info, List<RawMessage> messages) throws Exception{ if (messages != null) { // lag for (int i=0; i<messages.size(); i++) { info = info + "["+ (System.currentTimeMillis() - messages.get(i).getPublishTime()) + "] " + new String(ByteBufUtil.getBytes((messages.get(i)).getData()), "UTF8"); } } // log conn format is like from source to target switch (this.connType) { case ParserProxyHandler.FRONTEND_CONN: log.info(ParserProxyHandler.FRONTEND_CONN + ":{} cmd:{} msg:{}", "[" + conn.remoteAddress() + conn.localAddress() + "]", cmdtype, info); break; case ParserProxyHandler.BACKEND_CONN: log.info(ParserProxyHandler.BACKEND_CONN + ":{} cmd:{} msg:{}", "[" + conn.localAddress() + conn.remoteAddress() + "]", cmdtype, info); break; } }
Example 2
Source File: NettyHttpServerHandler.java From xxl-rpc with GNU General Public License v3.0 | 6 votes |
@Override protected void channelRead0(final ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception { // request parse final byte[] requestBytes = ByteBufUtil.getBytes(msg.content()); // byteBuf.toString(io.netty.util.CharsetUtil.UTF_8); final String uri = msg.uri(); final boolean keepAlive = HttpUtil.isKeepAlive(msg); // do invoke serverHandlerPool.execute(new Runnable() { @Override public void run() { process(ctx, uri, requestBytes, keepAlive); } }); }
Example 3
Source File: NetFlowV9Parser.java From graylog-plugin-netflow with Apache License 2.0 | 6 votes |
/** * Like above, but only retrieves the bytes and template ids */ public static List<Map.Entry<Integer, byte[]>> parseTemplatesShallow(ByteBuf bb) { final ImmutableList.Builder<Map.Entry<Integer, byte[]>> templates = ImmutableList.builder(); int len = bb.readUnsignedShort(); int p = 4; // flow set id and length field itself while (p < len) { final int start = bb.readerIndex(); final int templateId = bb.readUnsignedShort(); final int fieldCount = bb.readUnsignedShort(); final ImmutableList.Builder<NetFlowV9FieldDef> fieldDefs = ImmutableList.builder(); for (int i = 0; i < fieldCount; i++) { int fieldType = bb.readUnsignedShort(); int fieldLength = bb.readUnsignedShort(); } final byte[] bytes = ByteBufUtil.getBytes(bb, start, bb.readerIndex() - start); final Map.Entry<Integer, byte[]> template = Maps.immutableEntry(templateId, bytes); templates.add(template); p += 4 + fieldCount * 4; } return templates.build(); }
Example 4
Source File: HandshakeV9Request.java From r2dbc-mysql with Apache License 2.0 | 6 votes |
static HandshakeV9Request decodeV9(ByteBuf buf, HandshakeHeader header) { int bytes = buf.readableBytes(); if (bytes <= 0) { return new HandshakeV9Request(header, EMPTY_BYTES); } byte[] salt; if (buf.getByte(buf.writerIndex() - 1) == 0) { salt = ByteBufUtil.getBytes(buf, buf.readerIndex(), bytes - 1); } else { salt = ByteBufUtil.getBytes(buf); } return new HandshakeV9Request(header, salt); }
Example 5
Source File: SchemaUtils.java From pulsar with Apache License 2.0 | 6 votes |
public static Object toAvroObject(Object value) { if (value != null) { if (value instanceof ByteBuffer) { ByteBuffer bb = (ByteBuffer) value; byte[] bytes = new byte[bb.remaining()]; bb.duplicate().get(bytes); return bytes; } else if (value instanceof ByteBuf) { return ByteBufUtil.getBytes((ByteBuf) value); } else { return value; } } else { return null; } }
Example 6
Source File: GrpcTestUtil.java From armeria with Apache License 2.0 | 5 votes |
public static byte[] uncompressedFrame(ByteBuf proto) { final ByteBuf buf = Unpooled.buffer(); buf.writeByte(0); buf.writeInt(proto.readableBytes()); buf.writeBytes(proto); proto.release(); final byte[] result = ByteBufUtil.getBytes(buf); buf.release(); return result; }
Example 7
Source File: AttributeMessage.java From redisson with Apache License 2.0 | 5 votes |
protected byte[] toByteArray(Encoder encoder, Object value) throws IOException { if (value == null) { return null; } ByteBuf buf = encoder.encode(value); try { return ByteBufUtil.getBytes(buf); } finally { buf.release(); } }
Example 8
Source File: AttributeMessage.java From redisson with Apache License 2.0 | 5 votes |
protected byte[] toByteArray(Encoder encoder, Object value) throws IOException { if (value == null) { return null; } ByteBuf buf = encoder.encode(value); try { return ByteBufUtil.getBytes(buf); } finally { buf.release(); } }
Example 9
Source File: IOUtil.java From spring-boot-protocol with Apache License 2.0 | 5 votes |
/** * Read file to byte[] * @param sourcePath sourcePath * @param sourceFileName sourceFileName * @return byte[] * @throws FileNotFoundException FileNotFoundException * @throws IOException IOException */ public static byte[] readFileToBytes(String sourcePath, String sourceFileName) throws FileNotFoundException,IOException { ByteBuf byteBuf = readFileToByteBuf(sourcePath,sourceFileName); writerModeToReadMode(byteBuf); try { return ByteBufUtil.getBytes(byteBuf,byteBuf.readerIndex(), byteBuf.readableBytes(),false); }finally { RecyclableUtil.release(byteBuf); } }
Example 10
Source File: ByteArrayCodec.java From r2dbc-mysql with Apache License 2.0 | 5 votes |
@Override public byte[] decode(ByteBuf value, FieldInformation info, Class<?> target, boolean binary, CodecContext context) { if (!value.isReadable()) { return EMPTY_BYTES; } return ByteBufUtil.getBytes(value); }
Example 11
Source File: LargeFieldReader.java From r2dbc-mysql with Apache License 2.0 | 5 votes |
@Override public byte[] readSizeFixedBytes(int length) { require(length > 0, "length must be a positive integer"); ByteBuf buf = nonEmptyBuffer(); if (buf.readableBytes() >= length) { return ByteBufUtil.getBytes(buf.readSlice(length)); } return readBytes(buf, length); }
Example 12
Source File: ChangeAuthMessage.java From r2dbc-mysql with Apache License 2.0 | 5 votes |
static ChangeAuthMessage decode(ByteBuf buf) { buf.skipBytes(1); // skip generic header 0xFE of change authentication messages String authType = HandshakeHeader.readCStringAscii(buf); int bytes = buf.readableBytes(); byte[] salt = bytes > 0 && buf.getByte(buf.writerIndex() - 1) == TERMINAL ? ByteBufUtil.getBytes(buf, buf.readerIndex(), bytes - 1) : ByteBufUtil.getBytes(buf); // The terminal character has been removed from salt. return new ChangeAuthMessage(authType, salt); }
Example 13
Source File: StreamBufferingEncoder.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
private void cancelGoAwayStreams(int lastStreamId, long errorCode, ByteBuf debugData) { Iterator<PendingStream> iter = pendingStreams.values().iterator(); Exception e = new Http2GoAwayException(lastStreamId, errorCode, ByteBufUtil.getBytes(debugData)); while (iter.hasNext()) { PendingStream stream = iter.next(); if (stream.streamId > lastStreamId) { iter.remove(); stream.close(e); } } }
Example 14
Source File: ByteArrayCodec.java From r2dbc-mysql with Apache License 2.0 | 5 votes |
@Override public byte[] decode(ByteBuf value, FieldInformation info, Class<?> target, boolean binary, CodecContext context) { if (!value.isReadable()) { return EMPTY_BYTES; } return ByteBufUtil.getBytes(value); }
Example 15
Source File: LargeFieldReader.java From r2dbc-mysql with Apache License 2.0 | 5 votes |
@Override public byte[] readSizeFixedBytes(int length) { require(length > 0, "length must be a positive integer"); ByteBuf buf = nonEmptyBuffer(); if (buf.readableBytes() >= length) { return ByteBufUtil.getBytes(buf.readSlice(length)); } return readBytes(buf, length); }
Example 16
Source File: ChangeAuthMessage.java From r2dbc-mysql with Apache License 2.0 | 5 votes |
static ChangeAuthMessage decode(ByteBuf buf) { buf.skipBytes(1); // skip generic header 0xFE of change authentication messages String authType = HandshakeHeader.readCStringAscii(buf); int bytes = buf.readableBytes(); byte[] salt = bytes > 0 && buf.getByte(buf.writerIndex() - 1) == TERMINAL ? ByteBufUtil.getBytes(buf, buf.readerIndex(), bytes - 1) : ByteBufUtil.getBytes(buf); // The terminal character has been removed from salt. return new ChangeAuthMessage(authType, salt); }
Example 17
Source File: AbstractUnaryGrpcService.java From armeria with Apache License 2.0 | 5 votes |
@Override protected final CompletableFuture<ByteBuf> handleMessage(ByteBuf message) { final byte[] bytes; try { bytes = ByteBufUtil.getBytes(message); } finally { message.release(); } return handleMessage(bytes).thenApply(Unpooled::wrappedBuffer); }
Example 18
Source File: NormalFieldReader.java From r2dbc-mysql with Apache License 2.0 | 4 votes |
@Override public byte[] readSizeFixedBytes(int length) { require(length > 0, "length must be a positive integer"); return ByteBufUtil.getBytes(buf.readSlice(length)); }
Example 19
Source File: NormalFieldReader.java From r2dbc-mysql with Apache License 2.0 | 4 votes |
@Override public byte[] readSizeFixedBytes(int length) { require(length > 0, "length must be a positive integer"); return ByteBufUtil.getBytes(buf.readSlice(length)); }
Example 20
Source File: DataBufferFactoryWrapper.java From armeria with Apache License 2.0 | 4 votes |
/** * Returns a memory-based {@link DataBuffer} which will be garbage-collected. */ private DataBuffer withDataBufferFactory(PooledHttpData data) { final byte[] dataArray = ByteBufUtil.getBytes(data.content()); data.release(); return delegate.wrap(dataArray); }