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


Java StreamInput.wrap方法代码示例

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


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

示例1: testSerializationBwc

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
public void testSerializationBwc() throws IOException {
    final byte[] data = Base64.getDecoder().decode("P4AAAAAFZmllbGQEdHlwZQAAAAAAAA57ImZvbyI6ImJhciJ9AAAAAA==");
    final 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);
    try (StreamInput in = StreamInput.wrap(data)) {
        in.setVersion(version);
        PercolateQueryBuilder queryBuilder = new PercolateQueryBuilder(in);
        assertEquals("type", queryBuilder.getDocumentType());
        assertEquals("field", queryBuilder.getField());
        assertEquals("{\"foo\":\"bar\"}", queryBuilder.getDocument().utf8ToString());
        assertEquals(XContentType.JSON, queryBuilder.getXContentType());

        try (BytesStreamOutput out = new BytesStreamOutput()) {
            out.setVersion(version);
            queryBuilder.writeTo(out);
            assertArrayEquals(data, out.bytes().toBytesRef().bytes);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:PercolateQueryBuilderTests.java

示例2: testStreamInputMarkAndReset

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
public void testStreamInputMarkAndReset() throws IOException {
    int length = randomIntBetween(10, scaledRandomIntBetween(PAGE_SIZE * 2, PAGE_SIZE * 20));
    BytesReference pbr = newBytesReference(length);
    StreamInput si = pbr.streamInput();
    assertNotNull(si);

    StreamInput wrap = StreamInput.wrap(BytesReference.toBytes(pbr));
    while(wrap.available() > 0) {
        if (rarely()) {
            wrap.mark(Integer.MAX_VALUE);
            si.mark(Integer.MAX_VALUE);
        } else if (rarely()) {
            wrap.reset();
            si.reset();
        }
        assertEquals(si.readByte(), wrap.readByte());
        assertEquals(si.available(), wrap.available());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:AbstractBytesReferenceTestCase.java

示例3: testSerializationBwc

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
public void testSerializationBwc() throws IOException {
    final byte[] data = Base64.getDecoder().decode("ATECe30AAAA=");
    final 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);
    try (StreamInput in = StreamInput.wrap(data)) {
        in.setVersion(version);
        PipelineConfiguration configuration = PipelineConfiguration.readFrom(in);
        assertEquals(XContentType.JSON, configuration.getXContentType());
        assertEquals("{}", configuration.getConfig().utf8ToString());

        try (BytesStreamOutput out = new BytesStreamOutput()) {
            out.setVersion(version);
            configuration.writeTo(out);
            assertArrayEquals(data, out.bytes().toBytesRef().bytes);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:PipelineConfigurationTests.java

示例4: testItemSerializationBwc

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
public void testItemSerializationBwc() throws IOException {
    final byte[] data = Base64.getDecoder().decode("AQVpbmRleAEEdHlwZQEODXsiZm9vIjoiYmFyIn0A/wD//////////QAAAAAAAAAA");
    final 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);
    try (StreamInput in = StreamInput.wrap(data)) {
        in.setVersion(version);
        Item item = new Item(in);
        assertEquals(XContentType.JSON, item.xContentType());
        assertEquals("{\"foo\":\"bar\"}", item.doc().utf8ToString());
        assertEquals("index", item.index());
        assertEquals("type", item.type());

        try (BytesStreamOutput out = new BytesStreamOutput()) {
            out.setVersion(version);
            item.writeTo(out);
            assertArrayEquals(data, out.bytes().toBytesRef().bytes);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:MoreLikeThisQueryBuilderTests.java

示例5: testDiscoveryNodeSerializationKeepsHost

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
public void testDiscoveryNodeSerializationKeepsHost() throws Exception {
    InetAddress inetAddress = InetAddress.getByAddress("name1", new byte[] { (byte) 192, (byte) 168, (byte) 0, (byte) 1});
    TransportAddress transportAddress = new TransportAddress(inetAddress, randomIntBetween(0, 65535));
    DiscoveryNode node = new DiscoveryNode("name1", "id1", transportAddress, emptyMap(), emptySet(), Version.CURRENT);

    BytesStreamOutput streamOutput = new BytesStreamOutput();
    streamOutput.setVersion(Version.CURRENT);
    node.writeTo(streamOutput);

    StreamInput in = StreamInput.wrap(streamOutput.bytes().toBytesRef().bytes);
    DiscoveryNode serialized = new DiscoveryNode(in);
    assertEquals(transportAddress.address().getHostString(), serialized.getHostName());
    assertEquals(transportAddress.address().getHostString(), serialized.getAddress().address().getHostString());
    assertEquals(transportAddress.getAddress(), serialized.getHostAddress());
    assertEquals(transportAddress.getAddress(), serialized.getAddress().getAddress());
    assertEquals(transportAddress.getPort(), serialized.getAddress().getPort());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:DiscoveryNodeTests.java

示例6: testDiscoveryNodeSerializationToOldVersion

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
public void testDiscoveryNodeSerializationToOldVersion() throws Exception {
    InetAddress inetAddress = InetAddress.getByAddress("name1", new byte[] { (byte) 192, (byte) 168, (byte) 0, (byte) 1});
    TransportAddress transportAddress = new TransportAddress(inetAddress, randomIntBetween(0, 65535));
    DiscoveryNode node = new DiscoveryNode("name1", "id1", transportAddress, emptyMap(), emptySet(), Version.CURRENT);

    BytesStreamOutput streamOutput = new BytesStreamOutput();
    streamOutput.setVersion(Version.V_5_0_0);
    node.writeTo(streamOutput);

    StreamInput in = StreamInput.wrap(streamOutput.bytes().toBytesRef().bytes);
    in.setVersion(Version.V_5_0_0);
    DiscoveryNode serialized = new DiscoveryNode(in);
    assertEquals(transportAddress.address().getHostString(), serialized.getHostName());
    assertEquals(transportAddress.address().getHostString(), serialized.getAddress().address().getHostString());
    assertEquals(transportAddress.getAddress(), serialized.getHostAddress());
    assertEquals(transportAddress.getAddress(), serialized.getAddress().getAddress());
    assertEquals(transportAddress.getPort(), serialized.getAddress().getPort());
    assertFalse("if the minimum compatibility version moves past 5.0.3, remove the special casing in DiscoverNode(StreamInput) and " +
            "the TransportAddress(StreamInput, String) constructor",
        Version.CURRENT.minimumCompatibilityVersion().onOrAfter(Version.V_5_0_3_UNRELEASED));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:DiscoveryNodeTests.java

示例7: testSerializationBwc

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
public void testSerializationBwc() throws IOException {
    final byte[] data = Base64.getDecoder().decode("ADwDAANmb28APAMBB215X3R5cGULeyJ0eXBlIjp7fX0AAAD////+AA==");
    final 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);
    try (StreamInput in = StreamInput.wrap(data)) {
        in.setVersion(version);
        CreateIndexRequest serialized = new CreateIndexRequest();
        serialized.readFrom(in);
        assertEquals("foo", serialized.index());
        BytesReference bytesReference = JsonXContent.contentBuilder().startObject().startObject("type").endObject().endObject().bytes();
        assertEquals(bytesReference.utf8ToString(), serialized.mappings().get("my_type"));

        try (BytesStreamOutput out = new BytesStreamOutput()) {
            out.setVersion(version);
            serialized.writeTo(out);
            out.flush();
            assertArrayEquals(data, out.bytes().toBytesRef().bytes);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:CreateIndexRequestTests.java

示例8: testPutIndexTemplateRequestSerializationXContent

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
public void testPutIndexTemplateRequestSerializationXContent() throws IOException {
    PutIndexTemplateRequest request = new PutIndexTemplateRequest("foo");
    String mapping = YamlXContent.contentBuilder().startObject().field("foo", "bar").endObject().string();
    request.patterns(Collections.singletonList("foo"));
    request.mapping("bar", mapping, XContentType.YAML);
    assertNotEquals(mapping, request.mappings().get("bar"));
    assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), request.mappings().get("bar"));

    BytesStreamOutput out = new BytesStreamOutput();
    request.writeTo(out);

    StreamInput in = StreamInput.wrap(out.bytes().toBytesRef().bytes);
    PutIndexTemplateRequest serialized = new PutIndexTemplateRequest();
    serialized.readFrom(in);
    assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), serialized.mappings().get("bar"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:PutIndexTemplateRequestTests.java

示例9: testSerializationBwc

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
public void testSerializationBwc() throws IOException {
    final byte[] rawStreamBytes = Base64.getDecoder().decode("ADwDCG11c3RhY2hlAQZzY3JpcHQCe30A");
    final 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);
    try (StreamInput in = StreamInput.wrap(rawStreamBytes)) {
        in.setVersion(version);
        PutStoredScriptRequest serialized = new PutStoredScriptRequest();
        serialized.readFrom(in);
        assertEquals(XContentType.JSON, serialized.xContentType());
        assertEquals("mustache", serialized.lang());
        assertEquals("script", serialized.id());
        assertEquals(new BytesArray("{}"), serialized.content());

        try (BytesStreamOutput out = new BytesStreamOutput()) {
            out.setVersion(version);
            serialized.writeTo(out);
            out.flush();
            assertArrayEquals(rawStreamBytes, out.bytes().toBytesRef().bytes);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:PutStoredScriptRequestTests.java

示例10: testSerializationWithXContentBwc

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
public void testSerializationWithXContentBwc() throws IOException {
    final byte[] data = Base64.getDecoder().decode("AAAAAnt9AAA=");
    final 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);
    try (StreamInput in = StreamInput.wrap(data)) {
        in.setVersion(version);
        SimulatePipelineRequest request = new SimulatePipelineRequest();
        request.readFrom(in);
        assertEquals(XContentType.JSON, request.getXContentType());
        assertEquals("{}", request.getSource().utf8ToString());

        try (BytesStreamOutput out = new BytesStreamOutput()) {
            out.setVersion(version);
            request.writeTo(out);
            assertArrayEquals(data, out.bytes().toBytesRef().bytes);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:SimulatePipelineRequestTests.java

示例11: testSerializationBwc

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
public void testSerializationBwc() throws IOException {
    final byte[] data = Base64.getDecoder().decode("ADwDATECe30=");
    final 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);
    try (StreamInput in = StreamInput.wrap(data)) {
        in.setVersion(version);
        PutPipelineRequest request = new PutPipelineRequest();
        request.readFrom(in);
        assertEquals(XContentType.JSON, request.getXContentType());
        assertEquals("{}", request.getSource().utf8ToString());

        try (BytesStreamOutput out = new BytesStreamOutput()) {
            out.setVersion(version);
            request.writeTo(out);
            assertArrayEquals(data, out.bytes().toBytesRef().bytes);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:PutPipelineRequestTests.java

示例12: testSerialization

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
public void testSerialization() throws IOException {
    PipelineConfiguration configuration = new PipelineConfiguration("1",
        new BytesArray("{}".getBytes(StandardCharsets.UTF_8)), XContentType.JSON);
    assertEquals(XContentType.JSON, configuration.getXContentType());

    BytesStreamOutput out = new BytesStreamOutput();
    configuration.writeTo(out);
    StreamInput in = StreamInput.wrap(out.bytes().toBytesRef().bytes);
    PipelineConfiguration serialized = PipelineConfiguration.readFrom(in);
    assertEquals(XContentType.JSON, serialized.getXContentType());
    assertEquals("{}", serialized.getConfig().utf8ToString());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:PipelineConfigurationTests.java

示例13: load

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
@Override
public Map<String, String> load(byte[] source) throws IOException {
    Properties props = new NoDuplicatesProperties();
    StreamInput stream = StreamInput.wrap(source);
    try {
        props.load(stream);
        Map<String, String> result = newHashMap();
        for (Map.Entry entry : props.entrySet()) {
            result.put((String) entry.getKey(), (String) entry.getValue());
        }
        return result;
    } finally {
        IOUtils.closeWhileHandlingException(stream);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:16,代码来源:PropertiesSettingsLoader.java

示例14: testPutIndexTemplateRequestSerializationXContentBwc

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
public void testPutIndexTemplateRequestSerializationXContentBwc() throws IOException {
    final byte[] data = Base64.getDecoder().decode("ADwDAANmb28IdGVtcGxhdGUAAAAAAAABA2Jhcg8tLS0KZm9vOiAiYmFyIgoAAAAAAAAAAAAAAAA=");
    final 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);
    try (StreamInput in = StreamInput.wrap(data)) {
        in.setVersion(version);
        PutIndexTemplateRequest request = new PutIndexTemplateRequest();
        request.readFrom(in);
        String mapping = YamlXContent.contentBuilder().startObject().field("foo", "bar").endObject().string();
        assertNotEquals(mapping, request.mappings().get("bar"));
        assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), request.mappings().get("bar"));
        assertEquals("foo", request.name());
        assertEquals("template", request.patterns().get(0));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:PutIndexTemplateRequestTests.java

示例15: testIndexRequestXContentSerializationBwc

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
public void testIndexRequestXContentSerializationBwc() throws IOException {
    final byte[] data = Base64.getDecoder().decode("AAD////+AgQDZm9vAAAAAQNiYXIBATEAAAAAAnt9AP/////////9AAAA//////////8AAAAAAAA=");
    final 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);
    try (StreamInput in = StreamInput.wrap(data)) {
        in.setVersion(version);
        IndexRequest serialized = new IndexRequest();
        serialized.readFrom(in);
        assertEquals(XContentType.JSON, serialized.getContentType());
        assertEquals("{}", serialized.source().utf8ToString());
        // don't test writing to earlier versions since output differs due to no timestamp
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:IndexRequestTests.java


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