本文整理汇总了Java中org.elasticsearch.common.bytes.BytesReference.toBytesArray方法的典型用法代码示例。如果您正苦于以下问题:Java BytesReference.toBytesArray方法的具体用法?Java BytesReference.toBytesArray怎么用?Java BytesReference.toBytesArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.common.bytes.BytesReference
的用法示例。
在下文中一共展示了BytesReference.toBytesArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertToJson
import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
public static String convertToJson(BytesReference bytes, boolean reformatJson, boolean prettyPrint) throws IOException {
if (bytes.hasArray()) {
return convertToJson(bytes.array(), bytes.arrayOffset(), bytes.length(), reformatJson, prettyPrint);
}
XContentType xContentType = XContentFactory.xContentType(bytes);
if (xContentType == XContentType.JSON && !reformatJson) {
BytesArray bytesArray = bytes.toBytesArray();
return new String(bytesArray.array(), bytesArray.arrayOffset(), bytesArray.length(), Charsets.UTF_8);
}
try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(bytes.streamInput())) {
parser.nextToken();
XContentBuilder builder = XContentFactory.jsonBuilder();
if (prettyPrint) {
builder.prettyPrint();
}
builder.copyCurrentStructure(parser);
return builder.string();
}
}
示例2: SourceToParse
import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
private SourceToParse(Origin origin, BytesReference source) {
this.origin = origin;
// we always convert back to byte array, since we store it and Field only supports bytes..
// so, we might as well do it here, and improve the performance of working with direct byte arrays
this.source = source.toBytesArray();
this.parser = null;
}
示例3: field
import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
/**
* Writes the binary content of the given BytesReference
* Use {@link org.elasticsearch.common.xcontent.XContentParser#binaryValue()} to read the value back
*/
public XContentBuilder field(String name, BytesReference value) throws IOException {
field(name);
if (!value.hasArray()) {
value = value.toBytesArray();
}
generator.writeBinary(value.array(), value.arrayOffset(), value.length());
return this;
}
示例4: messageReceived
import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
@Override
public void messageReceived(BlobRecoveryChunkRequest request, TransportChannel channel) throws Exception {
BlobRecoveryStatus onGoingRecovery = onGoingRecoveries.get(request.recoveryId());
if (onGoingRecovery == null) {
// shard is getting closed on us
throw new IllegalBlobRecoveryStateException("Could not retrieve onGoingRecoveryStatus");
}
BlobRecoveryTransferStatus transferStatus = onGoingRecovery.onGoingTransfers().get(request.transferId());
BlobShard shard = onGoingRecovery.blobShard;
if (onGoingRecovery.canceled()) {
onGoingRecovery.sentCanceledToSource();
throw new IndexShardClosedException(onGoingRecovery.shardId());
}
if (transferStatus == null) {
throw new IndexShardClosedException(onGoingRecovery.shardId());
}
BytesReference content = request.content();
if (!content.hasArray()) {
content = content.toBytesArray();
}
transferStatus.outputStream().write(
content.array(), content.arrayOffset(), content.length()
);
if (request.isLast()) {
transferStatus.outputStream().close();
File source = new File(shard.blobContainer().getBaseDirectory(),
transferStatus.sourcePath()
);
File target = new File(shard.blobContainer().getBaseDirectory(),
transferStatus.targetPath()
);
if (target.exists()) {
logger.info("target file {} exists already.", target.getName());
// this might happen on bad timing while recovering/relocating.
// noop
} else {
if (!source.renameTo(target)) {
throw new BlobWriteException(target.getName(), target.length(), null);
}
}
onGoingRecovery.onGoingTransfers().remove(request.transferId());
}
channel.sendResponse(TransportResponse.Empty.INSTANCE);
}
示例5: wrap
import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
public static StreamInput wrap(BytesReference reference) {
if (reference.hasArray() == false) {
reference = reference.toBytesArray();
}
return wrap(reference.array(), reference.arrayOffset(), reference.length());
}