当前位置: 首页>>代码示例>>Java>>正文


Java BytesReference.toBytesArray方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:20,代码来源:XContentHelper.java

示例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;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:8,代码来源:SourceToParse.java

示例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;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:13,代码来源:XContentBuilder.java

示例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);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:53,代码来源:BlobRecoveryTarget.java

示例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());
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:7,代码来源:StreamInput.java


注:本文中的org.elasticsearch.common.bytes.BytesReference.toBytesArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。