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


Java BytesReference.streamInput方法代码示例

本文整理汇总了Java中org.elasticsearch.common.bytes.BytesReference.streamInput方法的典型用法代码示例。如果您正苦于以下问题:Java BytesReference.streamInput方法的具体用法?Java BytesReference.streamInput怎么用?Java BytesReference.streamInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.common.bytes.BytesReference的用法示例。


在下文中一共展示了BytesReference.streamInput方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFieldStats

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
/**
 * Fetch {@linkplain FieldStats} for a field. These stats are cached until the shard changes.
 * @param shard the shard to use with the cache key
 * @param searcher searcher to use to lookup the field stats
 * @param field the actual field
 * @param useCache should this request use the cache?
 */
public FieldStats<?> getFieldStats(IndexShard shard, Engine.Searcher searcher, String field, boolean useCache) throws Exception {
    MappedFieldType fieldType = shard.mapperService().fullName(field);
    if (fieldType == null) {
        return null;
    }
    if (useCache == false) {
        return fieldType.stats(searcher.reader());
    }
    BytesReference cacheKey = new BytesArray("fieldstats:" + field);
    BytesReference statsRef = cacheShardLevelResult(shard, searcher.getDirectoryReader(), cacheKey, out -> {
        try {
            out.writeOptionalWriteable(fieldType.stats(searcher.reader()));
        } catch (IOException e) {
            throw new IllegalStateException("Failed to write field stats output", e);
        }
    });
    try (StreamInput in = statsRef.streamInput()) {
        return in.readOptionalWriteable(FieldStats::readFrom);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:IndicesService.java

示例2: testTransportRoundTrip

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
public void testTransportRoundTrip() throws IOException {
    ExtendedBounds orig = randomExtendedBounds();

    BytesReference origBytes;
    try (BytesStreamOutput out = new BytesStreamOutput()) {
        orig.writeTo(out);
        origBytes = out.bytes();
    }

    ExtendedBounds read;
    try (StreamInput in = origBytes.streamInput()) {
        read = new ExtendedBounds(in);
        assertEquals("read fully", 0, in.available());
    }
    assertEquals(orig, read);

    BytesReference readBytes;
    try (BytesStreamOutput out = new BytesStreamOutput()) {
        read.writeTo(out);
        readBytes = out.bytes();
    }

    assertEquals(origBytes, readBytes);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:ExtendedBoundsTests.java

示例3: testSerializeRequest

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
public void testSerializeRequest() throws IOException {
    ClusterRerouteRequest req = new ClusterRerouteRequest();
    req.setRetryFailed(randomBoolean());
    req.dryRun(randomBoolean());
    req.explain(randomBoolean());
    req.add(new AllocateEmptyPrimaryAllocationCommand("foo", 1, "bar", randomBoolean()));
    req.timeout(TimeValue.timeValueMillis(randomIntBetween(0, 100)));
    BytesStreamOutput out = new BytesStreamOutput();
    req.writeTo(out);
    BytesReference bytes = out.bytes();
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(NetworkModule.getNamedWriteables());
    StreamInput wrap = new NamedWriteableAwareStreamInput(bytes.streamInput(),
        namedWriteableRegistry);
    ClusterRerouteRequest deserializedReq = new ClusterRerouteRequest();
    deserializedReq.readFrom(wrap);

    assertEquals(req.isRetryFailed(), deserializedReq.isRetryFailed());
    assertEquals(req.dryRun(), deserializedReq.dryRun());
    assertEquals(req.explain(), deserializedReq.explain());
    assertEquals(req.timeout(), deserializedReq.timeout());
    assertEquals(1, deserializedReq.getCommands().commands().size()); // allocation commands have their own tests
    assertEquals(req.getCommands().commands().size(), deserializedReq.getCommands().commands().size());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:ClusterRerouteTests.java

示例4: writeAtomic

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
private void writeAtomic(final String blobName, final BytesReference bytesRef) throws IOException {
    final String tempBlobName = "pending-" + blobName + "-" + UUIDs.randomBase64UUID();
    try (InputStream stream = bytesRef.streamInput()) {
        snapshotsBlobContainer.writeBlob(tempBlobName, stream, bytesRef.length());
        snapshotsBlobContainer.move(tempBlobName, blobName);
    } catch (IOException ex) {
        // temporary blob creation or move failed - try cleaning up
        try {
            snapshotsBlobContainer.deleteBlob(tempBlobName);
        } catch (IOException e) {
            ex.addSuppressed(e);
        }
        throw ex;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:BlobStoreRepository.java

示例5: copyRawValue

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
protected void copyRawValue(BytesReference content, XContent xContent) throws IOException {
    // EMPTY is safe here because we never call namedObject
    try (StreamInput input = content.streamInput();
         XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, input)) {
        copyCurrentStructure(parser);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:JsonXContentGenerator.java

示例6: roundTrip

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
private TaskId roundTrip(TaskId taskId, int expectedSize) throws IOException {
    try (BytesStreamOutput out = new BytesStreamOutput()) {
        taskId.writeTo(out);
        BytesReference bytes = out.bytes();
        assertEquals(expectedSize, bytes.length());
        try (StreamInput in = bytes.streamInput()) {
            return TaskId.readFromStream(in);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:TaskIdTests.java

示例7: validateMessageHeader

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
/**
 * Validates the first N bytes of the message header and returns <code>false</code> if the message is
 * a ping message and has no payload ie. isn't a real user level message.
 *
 * @throws IllegalStateException if the message is too short, less than the header or less that the header plus the message size
 * @throws HttpOnTransportException if the message has no valid header and appears to be a HTTP message
 * @throws IllegalArgumentException if the message is greater that the maximum allowed frame size. This is dependent on the available
 * memory.
 */
public static boolean validateMessageHeader(BytesReference buffer) throws IOException {
    final int sizeHeaderLength = TcpHeader.MARKER_BYTES_SIZE + TcpHeader.MESSAGE_LENGTH_SIZE;
    if (buffer.length() < sizeHeaderLength) {
        throw new IllegalStateException("message size must be >= to the header size");
    }
    int offset = 0;
    if (buffer.get(offset) != 'E' || buffer.get(offset + 1) != 'S') {
        // special handling for what is probably HTTP
        if (bufferStartsWith(buffer, offset, "GET ") ||
                bufferStartsWith(buffer, offset, "POST ") ||
                bufferStartsWith(buffer, offset, "PUT ") ||
                bufferStartsWith(buffer, offset, "HEAD ") ||
                bufferStartsWith(buffer, offset, "DELETE ") ||
                bufferStartsWith(buffer, offset, "OPTIONS ") ||
                bufferStartsWith(buffer, offset, "PATCH ") ||
                bufferStartsWith(buffer, offset, "TRACE ")) {

            throw new HttpOnTransportException("This is not a HTTP port");
        }

        // we have 6 readable bytes, show 4 (should be enough)
        throw new StreamCorruptedException("invalid internal transport message format, got ("
                + Integer.toHexString(buffer.get(offset) & 0xFF) + ","
                + Integer.toHexString(buffer.get(offset + 1) & 0xFF) + ","
                + Integer.toHexString(buffer.get(offset + 2) & 0xFF) + ","
                + Integer.toHexString(buffer.get(offset + 3) & 0xFF) + ")");
    }

    final int dataLen;
    try (StreamInput input = buffer.streamInput()) {
        input.skip(TcpHeader.MARKER_BYTES_SIZE);
        dataLen = input.readInt();
        if (dataLen == PING_DATA_SIZE) {
            // discard the messages we read and continue, this is achieved by skipping the bytes
            // and returning null
            return false;
        }
    }

    if (dataLen <= 0) {
        throw new StreamCorruptedException("invalid data length: " + dataLen);
    }
    // safety against too large frames being sent
    if (dataLen > NINETY_PER_HEAP_SIZE) {
        throw new IllegalArgumentException("transport content length received [" + new ByteSizeValue(dataLen) + "] exceeded ["
                + new ByteSizeValue(NINETY_PER_HEAP_SIZE) + "]");
    }

    if (buffer.length() < dataLen + sizeHeaderLength) {
        throw new IllegalStateException("buffer must be >= to the message size but wasn't");
    }
    return true;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:63,代码来源:TcpTransport.java

示例8: TermVector

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
TermVector(BytesReference termVectors, long readOffset) throws IOException {
    this.perFieldTermVectorInput = termVectors.streamInput();
    this.readOffset = readOffset;
    reset();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:6,代码来源:TermVectorsFields.java

示例9: testBWCHeadersAndMetadata

import org.elasticsearch.common.bytes.BytesReference; //导入方法依赖的package包/类
public void testBWCHeadersAndMetadata() throws IOException {
    //this is a request serialized with headers only, no metadata as they were added in 5.3.0
    BytesReference decoded = new BytesArray(Base64.getDecoder().decode
            ("AQ10ZXN0ICBtZXNzYWdlACYtb3JnLmVsYXN0aWNzZWFyY2guRXhjZXB0aW9uU2VyaWFsaXphdGlvblRlc3RzASBFeGNlcHRpb25TZXJpYWxpemF0aW9uVG" +
                    "VzdHMuamF2YQR0ZXN03wYkc3VuLnJlZmxlY3QuTmF0aXZlTWV0aG9kQWNjZXNzb3JJbXBsAR1OYXRpdmVNZXRob2RBY2Nlc3NvckltcGwuamF2Y" +
                    "QdpbnZva2Uw/v///w8kc3VuLnJlZmxlY3QuTmF0aXZlTWV0aG9kQWNjZXNzb3JJbXBsAR1OYXRpdmVNZXRob2RBY2Nlc3NvckltcGwuamF2YQZp" +
                    "bnZva2U+KHN1bi5yZWZsZWN0LkRlbGVnYXRpbmdNZXRob2RBY2Nlc3NvckltcGwBIURlbGVnYXRpbmdNZXRob2RBY2Nlc3NvckltcGwuamF2YQZ" +
                    "pbnZva2UrGGphdmEubGFuZy5yZWZsZWN0Lk1ldGhvZAELTWV0aG9kLmphdmEGaW52b2tl8QMzY29tLmNhcnJvdHNlYXJjaC5yYW5kb21pemVkdG" +
                    "VzdGluZy5SYW5kb21pemVkUnVubmVyARVSYW5kb21pemVkUnVubmVyLmphdmEGaW52b2tlsQ01Y29tLmNhcnJvdHNlYXJjaC5yYW5kb21pemVkd" +
                    "GVzdGluZy5SYW5kb21pemVkUnVubmVyJDgBFVJhbmRvbWl6ZWRSdW5uZXIuamF2YQhldmFsdWF0ZYsHNWNvbS5jYXJyb3RzZWFyY2gucmFuZG9t" +
                    "aXplZHRlc3RpbmcuUmFuZG9taXplZFJ1bm5lciQ5ARVSYW5kb21pemVkUnVubmVyLmphdmEIZXZhbHVhdGWvBzZjb20uY2Fycm90c2VhcmNoLnJ" +
                    "hbmRvbWl6ZWR0ZXN0aW5nLlJhbmRvbWl6ZWRSdW5uZXIkMTABFVJhbmRvbWl6ZWRSdW5uZXIuamF2YQhldmFsdWF0Zb0HOWNvbS5jYXJyb3RzZW" +
                    "FyY2gucmFuZG9taXplZHRlc3RpbmcucnVsZXMuU3RhdGVtZW50QWRhcHRlcgEVU3RhdGVtZW50QWRhcHRlci5qYXZhCGV2YWx1YXRlJDVvcmcuY" +
                    "XBhY2hlLmx1Y2VuZS51dGlsLlRlc3RSdWxlU2V0dXBUZWFyZG93bkNoYWluZWQkMQEhVGVzdFJ1bGVTZXR1cFRlYXJkb3duQ2hhaW5lZC5qYXZh" +
                    "CGV2YWx1YXRlMTBvcmcuYXBhY2hlLmx1Y2VuZS51dGlsLkFic3RyYWN0QmVmb3JlQWZ0ZXJSdWxlJDEBHEFic3RyYWN0QmVmb3JlQWZ0ZXJSdWx" +
                    "lLmphdmEIZXZhbHVhdGUtMm9yZy5hcGFjaGUubHVjZW5lLnV0aWwuVGVzdFJ1bGVUaHJlYWRBbmRUZXN0TmFtZSQxAR5UZXN0UnVsZVRocmVhZE" +
                    "FuZFRlc3ROYW1lLmphdmEIZXZhbHVhdGUwN29yZy5hcGFjaGUubHVjZW5lLnV0aWwuVGVzdFJ1bGVJZ25vcmVBZnRlck1heEZhaWx1cmVzJDEBI" +
                    "1Rlc3RSdWxlSWdub3JlQWZ0ZXJNYXhGYWlsdXJlcy5qYXZhCGV2YWx1YXRlQCxvcmcuYXBhY2hlLmx1Y2VuZS51dGlsLlRlc3RSdWxlTWFya0Zh" +
                    "aWx1cmUkMQEYVGVzdFJ1bGVNYXJrRmFpbHVyZS5qYXZhCGV2YWx1YXRlLzljb20uY2Fycm90c2VhcmNoLnJhbmRvbWl6ZWR0ZXN0aW5nLnJ1bGV" +
                    "zLlN0YXRlbWVudEFkYXB0ZXIBFVN0YXRlbWVudEFkYXB0ZXIuamF2YQhldmFsdWF0ZSREY29tLmNhcnJvdHNlYXJjaC5yYW5kb21pemVkdGVzdG" +
                    "luZy5UaHJlYWRMZWFrQ29udHJvbCRTdGF0ZW1lbnRSdW5uZXIBFlRocmVhZExlYWtDb250cm9sLmphdmEDcnVu7wI0Y29tLmNhcnJvdHNlYXJja" +
                    "C5yYW5kb21pemVkdGVzdGluZy5UaHJlYWRMZWFrQ29udHJvbAEWVGhyZWFkTGVha0NvbnRyb2wuamF2YRJmb3JrVGltZW91dGluZ1Rhc2urBjZj" +
                    "b20uY2Fycm90c2VhcmNoLnJhbmRvbWl6ZWR0ZXN0aW5nLlRocmVhZExlYWtDb250cm9sJDMBFlRocmVhZExlYWtDb250cm9sLmphdmEIZXZhbHV" +
                    "hdGXOAzNjb20uY2Fycm90c2VhcmNoLnJhbmRvbWl6ZWR0ZXN0aW5nLlJhbmRvbWl6ZWRSdW5uZXIBFVJhbmRvbWl6ZWRSdW5uZXIuamF2YQ1ydW" +
                    "5TaW5nbGVUZXN0lAc1Y29tLmNhcnJvdHNlYXJjaC5yYW5kb21pemVkdGVzdGluZy5SYW5kb21pemVkUnVubmVyJDUBFVJhbmRvbWl6ZWRSdW5uZ" +
                    "XIuamF2YQhldmFsdWF0ZaIGNWNvbS5jYXJyb3RzZWFyY2gucmFuZG9taXplZHRlc3RpbmcuUmFuZG9taXplZFJ1bm5lciQ2ARVSYW5kb21pemVk" +
                    "UnVubmVyLmphdmEIZXZhbHVhdGXUBjVjb20uY2Fycm90c2VhcmNoLnJhbmRvbWl6ZWR0ZXN0aW5nLlJhbmRvbWl6ZWRSdW5uZXIkNwEVUmFuZG9" +
                    "taXplZFJ1bm5lci5qYXZhCGV2YWx1YXRl3wYwb3JnLmFwYWNoZS5sdWNlbmUudXRpbC5BYnN0cmFjdEJlZm9yZUFmdGVyUnVsZSQxARxBYnN0cm" +
                    "FjdEJlZm9yZUFmdGVyUnVsZS5qYXZhCGV2YWx1YXRlLTljb20uY2Fycm90c2VhcmNoLnJhbmRvbWl6ZWR0ZXN0aW5nLnJ1bGVzLlN0YXRlbWVud" +
                    "EFkYXB0ZXIBFVN0YXRlbWVudEFkYXB0ZXIuamF2YQhldmFsdWF0ZSQvb3JnLmFwYWNoZS5sdWNlbmUudXRpbC5UZXN0UnVsZVN0b3JlQ2xhc3NO" +
                    "YW1lJDEBG1Rlc3RSdWxlU3RvcmVDbGFzc05hbWUuamF2YQhldmFsdWF0ZSlOY29tLmNhcnJvdHNlYXJjaC5yYW5kb21pemVkdGVzdGluZy5ydWx" +
                    "lcy5Ob1NoYWRvd2luZ09yT3ZlcnJpZGVzT25NZXRob2RzUnVsZSQxAShOb1NoYWRvd2luZ09yT3ZlcnJpZGVzT25NZXRob2RzUnVsZS5qYXZhCG" +
                    "V2YWx1YXRlKE5jb20uY2Fycm90c2VhcmNoLnJhbmRvbWl6ZWR0ZXN0aW5nLnJ1bGVzLk5vU2hhZG93aW5nT3JPdmVycmlkZXNPbk1ldGhvZHNSd" +
                    "WxlJDEBKE5vU2hhZG93aW5nT3JPdmVycmlkZXNPbk1ldGhvZHNSdWxlLmphdmEIZXZhbHVhdGUoOWNvbS5jYXJyb3RzZWFyY2gucmFuZG9taXpl" +
                    "ZHRlc3RpbmcucnVsZXMuU3RhdGVtZW50QWRhcHRlcgEVU3RhdGVtZW50QWRhcHRlci5qYXZhCGV2YWx1YXRlJDljb20uY2Fycm90c2VhcmNoLnJ" +
                    "hbmRvbWl6ZWR0ZXN0aW5nLnJ1bGVzLlN0YXRlbWVudEFkYXB0ZXIBFVN0YXRlbWVudEFkYXB0ZXIuamF2YQhldmFsdWF0ZSQ5Y29tLmNhcnJvdH" +
                    "NlYXJjaC5yYW5kb21pemVkdGVzdGluZy5ydWxlcy5TdGF0ZW1lbnRBZGFwdGVyARVTdGF0ZW1lbnRBZGFwdGVyLmphdmEIZXZhbHVhdGUkM29yZ" +
                    "y5hcGFjaGUubHVjZW5lLnV0aWwuVGVzdFJ1bGVBc3NlcnRpb25zUmVxdWlyZWQkMQEfVGVzdFJ1bGVBc3NlcnRpb25zUmVxdWlyZWQuamF2YQhl" +
                    "dmFsdWF0ZTUsb3JnLmFwYWNoZS5sdWNlbmUudXRpbC5UZXN0UnVsZU1hcmtGYWlsdXJlJDEBGFRlc3RSdWxlTWFya0ZhaWx1cmUuamF2YQhldmF" +
                    "sdWF0ZS83b3JnLmFwYWNoZS5sdWNlbmUudXRpbC5UZXN0UnVsZUlnbm9yZUFmdGVyTWF4RmFpbHVyZXMkMQEjVGVzdFJ1bGVJZ25vcmVBZnRlck" +
                    "1heEZhaWx1cmVzLmphdmEIZXZhbHVhdGVAMW9yZy5hcGFjaGUubHVjZW5lLnV0aWwuVGVzdFJ1bGVJZ25vcmVUZXN0U3VpdGVzJDEBHVRlc3RSd" +
                    "WxlSWdub3JlVGVzdFN1aXRlcy5qYXZhCGV2YWx1YXRlNjljb20uY2Fycm90c2VhcmNoLnJhbmRvbWl6ZWR0ZXN0aW5nLnJ1bGVzLlN0YXRlbWVu" +
                    "dEFkYXB0ZXIBFVN0YXRlbWVudEFkYXB0ZXIuamF2YQhldmFsdWF0ZSREY29tLmNhcnJvdHNlYXJjaC5yYW5kb21pemVkdGVzdGluZy5UaHJlYWR" +
                    "MZWFrQ29udHJvbCRTdGF0ZW1lbnRSdW5uZXIBFlRocmVhZExlYWtDb250cm9sLmphdmEDcnVu7wIQamF2YS5sYW5nLlRocmVhZAELVGhyZWFkLm" +
                    "phdmEDcnVu6QUABAdoZWFkZXIyAQZ2YWx1ZTIKZXMuaGVhZGVyMwEGdmFsdWUzB2hlYWRlcjEBBnZhbHVlMQplcy5oZWFkZXI0AQZ2YWx1ZTQAA" +
                    "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +
                    "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +
                    "AAAAA"));

    try (StreamInput in = decoded.streamInput()) {
        //randomize the version across released and unreleased ones
        Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2,
                Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
        in.setVersion(version);
        ElasticsearchException exception = new ElasticsearchException(in);
        assertEquals("test  message", exception.getMessage());
        //the headers received as part of a single set get split based on their prefix
        assertEquals(2, exception.getHeaderKeys().size());
        assertEquals("value1", exception.getHeader("header1").get(0));
        assertEquals("value2", exception.getHeader("header2").get(0));
        assertEquals(2, exception.getMetadataKeys().size());
        assertEquals("value3", exception.getMetadata("es.header3").get(0));
        assertEquals("value4", exception.getMetadata("es.header4").get(0));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:66,代码来源:ExceptionSerializationTests.java


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