本文整理汇总了Java中org.elasticsearch.common.bytes.BytesReference.hasArray方法的典型用法代码示例。如果您正苦于以下问题:Java BytesReference.hasArray方法的具体用法?Java BytesReference.hasArray怎么用?Java BytesReference.hasArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.common.bytes.BytesReference
的用法示例。
在下文中一共展示了BytesReference.hasArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: createParser
import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
@Override
public XContentParser createParser(BytesReference bytes) throws IOException {
if (bytes.hasArray()) {
return createParser(bytes.array(), bytes.arrayOffset(), bytes.length());
}
return createParser(bytes.streamInput());
}
示例3: copyRawValue
import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
protected void copyRawValue(BytesReference content, XContent xContent) throws IOException {
XContentParser parser = null;
try {
if (content.hasArray()) {
parser = xContent.createParser(content.array(), content.arrayOffset(), content.length());
} else {
parser = xContent.createParser(content.streamInput());
}
copyCurrentStructure(parser);
} finally {
if (parser != null) {
parser.close();
}
}
}
示例4: 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;
}
示例5: 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);
}
示例6: 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());
}