本文整理了Java中io.micronaut.core.io.buffer.ByteBuffer.asNativeBuffer()
方法的一些代码示例,展示了ByteBuffer.asNativeBuffer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuffer.asNativeBuffer()
方法的具体详情如下:
包路径:io.micronaut.core.io.buffer.ByteBuffer
类名称:ByteBuffer
方法名:asNativeBuffer
暂无
代码示例来源:origin: micronaut-projects/micronaut-core
private ByteBuf charSequenceToByteBuf(CharSequence bodyValue, MediaType requestContentType) {
CharSequence charSequence = bodyValue;
return byteBufferFactory.copiedBuffer(
charSequence.toString().getBytes(
requestContentType.getCharset().orElse(defaultCharset)
)
).asNativeBuffer();
}
代码示例来源:origin: micronaut-projects/micronaut-core
} else if (body instanceof ByteBuffer) {
ByteBuffer byteBuffer = (ByteBuffer) body;
Object nativeBuffer = byteBuffer.asNativeBuffer();
if (nativeBuffer instanceof ByteBuf) {
byteBuf = (ByteBuf) nativeBuffer;
LOG.debug("Encoding emitted response object [{}] using codec: {}", body, codec);
byteBuf = (ByteBuf) codec.encode(body, new NettyByteBufferFactory(context.alloc())).asNativeBuffer();
代码示例来源:origin: micronaut-projects/micronaut-core
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> getBody(Argument<T> type) {
return convertedBodies.computeIfAbsent(type.getType(), aClass -> getBody().flatMap(b -> {
ArgumentConversionContext<T> context = ConversionContext.of(type);
if (b instanceof ByteBuffer) {
return conversionService.convert(((ByteBuffer) b).asNativeBuffer(), context);
}
return conversionService.convert(b, context);
}));
}
代码示例来源:origin: micronaut-projects/micronaut-core
} else if (body instanceof ByteBuffer) {
ByteBuffer byteBuffer = (ByteBuffer) body;
Object nativeBuffer = byteBuffer.asNativeBuffer();
if (nativeBuffer instanceof ByteBuf) {
byteBuf = (ByteBuf) nativeBuffer;
LOG.debug("Encoding emitted response object [{}] using codec: {}", body, codec);
byteBuf = (ByteBuf) codec.encode(body, new NettyByteBufferFactory(context.alloc())).asNativeBuffer();
代码示例来源:origin: micronaut-projects/micronaut-core
ByteBuf bytebuf = (ByteBuf) ((ByteBuffer) b).asNativeBuffer();
return convertByteBuf(bytebuf, finalArgument);
} else {
代码示例来源:origin: micronaut-projects/micronaut-core
/**
* Encode the given message with the given media type.
* @param message The message
* @param mediaType The media type
* @return The encoded frame
*/
public WebSocketFrame encodeMessage(Object message, MediaType mediaType) {
if (message instanceof byte[]) {
return new BinaryWebSocketFrame(Unpooled.wrappedBuffer((byte[]) message));
} else if (ClassUtils.isJavaLangType(message.getClass())) {
String s = message.toString();
return new TextWebSocketFrame(s);
} else if (message instanceof ByteBuf) {
return new BinaryWebSocketFrame((ByteBuf) message);
} else if (message instanceof ByteBuffer) {
return new BinaryWebSocketFrame(Unpooled.wrappedBuffer((ByteBuffer) message));
} else {
Optional<MediaTypeCodec> codec = codecRegistry.findCodec(mediaType != null ? mediaType : MediaType.APPLICATION_JSON_TYPE);
if (codec.isPresent()) {
io.micronaut.core.io.buffer.ByteBuffer encoded = codec.get().encode(message, new NettyByteBufferFactory(UnpooledByteBufAllocator.DEFAULT));
return new TextWebSocketFrame((ByteBuf) encoded.asNativeBuffer());
}
}
throw new WebSocketSessionException("Unable to encode WebSocket message: " + message);
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
} else if (mediaTypeCodecRegistry != null) {
Optional<MediaTypeCodec> registeredCodec = mediaTypeCodecRegistry.findCodec(requestContentType);
ByteBuf encoded = registeredCodec.map(codec -> (ByteBuf) codec.encode(o, byteBufferFactory).asNativeBuffer())
.orElse(null);
if (encoded != null) {
} else if (mediaTypeCodecRegistry != null) {
Optional<MediaTypeCodec> registeredCodec = mediaTypeCodecRegistry.findCodec(requestContentType);
bodyContent = registeredCodec.map(codec -> (ByteBuf) codec.encode(bodyValue, byteBufferFactory).asNativeBuffer())
.orElse(null);
代码示例来源:origin: io.micronaut/micronaut-http-client
private ByteBuf charSequenceToByteBuf(CharSequence bodyValue, MediaType requestContentType) {
CharSequence charSequence = bodyValue;
return byteBufferFactory.copiedBuffer(
charSequence.toString().getBytes(
requestContentType.getCharset().orElse(defaultCharset)
)
).asNativeBuffer();
}
代码示例来源:origin: io.micronaut/http-client
private ByteBuf charSequenceToByteBuf(CharSequence bodyValue, MediaType requestContentType) {
CharSequence charSequence = bodyValue;
return byteBufferFactory.copiedBuffer(
charSequence.toString().getBytes(
requestContentType.getCharset().orElse(defaultCharset)
)
).asNativeBuffer();
}
代码示例来源:origin: io.micronaut/http-client
return getBody().flatMap(b -> {
if (b instanceof ByteBuffer) {
ByteBuf bytebuf = (ByteBuf) ((ByteBuffer) b).asNativeBuffer();
return convertByteBuf(bytebuf, argument);
代码示例来源:origin: io.micronaut/micronaut-http-client
ByteBuf bytebuf = (ByteBuf) ((ByteBuffer) b).asNativeBuffer();
return convertByteBuf(bytebuf, finalArgument);
} else {
代码示例来源:origin: io.micronaut/http-client
} else if (mediaTypeCodecRegistry != null) {
Optional<MediaTypeCodec> registeredCodec = mediaTypeCodecRegistry.findCodec(requestContentType);
ByteBuf encoded = registeredCodec.map(codec -> (ByteBuf) codec.encode(o, byteBufferFactory).asNativeBuffer())
.orElse(null);
if (encoded != null) {
} else if (mediaTypeCodecRegistry != null) {
Optional<MediaTypeCodec> registeredCodec = mediaTypeCodecRegistry.findCodec(requestContentType);
bodyContent = registeredCodec.map(codec -> (ByteBuf) codec.encode(bodyValue, byteBufferFactory).asNativeBuffer())
.orElse(null);
代码示例来源:origin: io.micronaut/micronaut-http-client
} else if (mediaTypeCodecRegistry != null) {
Optional<MediaTypeCodec> registeredCodec = mediaTypeCodecRegistry.findCodec(requestContentType);
ByteBuf encoded = registeredCodec.map(codec -> (ByteBuf) codec.encode(o, byteBufferFactory).asNativeBuffer())
.orElse(null);
if (encoded != null) {
} else if (mediaTypeCodecRegistry != null) {
Optional<MediaTypeCodec> registeredCodec = mediaTypeCodecRegistry.findCodec(requestContentType);
bodyContent = registeredCodec.map(codec -> (ByteBuf) codec.encode(bodyValue, byteBufferFactory).asNativeBuffer())
.orElse(null);
内容来源于网络,如有侵权,请联系作者删除!