本文整理了Java中io.micronaut.core.io.buffer.ByteBuffer.toByteArray()
方法的一些代码示例,展示了ByteBuffer.toByteArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuffer.toByteArray()
方法的具体详情如下:
包路径:io.micronaut.core.io.buffer.ByteBuffer
类名称:ByteBuffer
方法名:toByteArray
[英]Create a copy of the underlying storage from buf into a byte array. The copy will start at ByteBuffer#readerIndex() and copy ByteBuffer#readableBytes() bytes.
[中]将基础存储的副本从buf创建到字节数组中。复制将从ByteBuffer#readerIndex()开始,然后复制ByteBuffer#readableBytes()字节。
代码示例来源:origin: micronaut-projects/micronaut-core
@Override
public <T> byte[] encode(T object) throws CodecException {
ByteBuffer buffer = encode(object, byteBufferFactory);
return buffer.toByteArray();
}
代码示例来源:origin: micronaut-projects/micronaut-core
byte[] result = object.toByteArray();
((ReferenceCounted) object).release();
return Optional.of(result);
代码示例来源:origin: io.micronaut/http-server
@Override
public <T> byte[] encode(T object) throws CodecException {
ByteBuffer buffer = encode(object, byteBufferFactory);
return buffer.toByteArray();
}
代码示例来源:origin: io.micronaut/runtime
@Override
public <T> T decode(Argument<T> type, ByteBuffer<?> buffer) throws CodecException {
try {
if (CharSequence.class.isAssignableFrom(type.getType())) {
return (T) buffer.toString(applicationConfiguration.getDefaultCharset());
} else if (type.hasTypeVariables()) {
JavaType javaType = constructJavaType(type);
return objectMapper.readValue(buffer.toByteArray(), javaType);
} else {
return objectMapper.readValue(buffer.toByteArray(), type.getType());
}
} catch (IOException e) {
throw new CodecException("Error decoding JSON stream for type [" + type.getType() + "]: " + e.getMessage());
}
}
代码示例来源:origin: io.micronaut.aws/micronaut-function-aws-api-proxy
private byte[] encodeInternal(MediaTypeCodec codec) throws InvalidResponseObjectException {
byte[] encoded = null;
try {
if (body != null) {
if (body instanceof ByteBuffer) {
encoded = ((ByteBuffer) body).toByteArray();
} else if (body instanceof byte[]) {
encoded = (byte[]) body;
} else {
final Optional<MediaType> contentType = getContentType();
if (!contentType.isPresent()) {
contentType(MediaType.APPLICATION_JSON_TYPE);
}
encoded = codec.encode(body);
}
}
} catch (Exception e) {
throw new InvalidResponseObjectException("Invalid Response: " + e.getMessage() , e);
}
return encoded;
}
内容来源于网络,如有侵权,请联系作者删除!