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


Java StreamInput.close方法代码示例

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


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

示例1: testRoundTrip

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
/** ensure we can round trip in serialization */
public void testRoundTrip() throws IOException {
    ScriptException e = new ScriptException("messageData", new Exception("causeData"), Arrays.asList("stack1", "stack2"), 
                                            "sourceData", "langData");
    
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    StreamOutput output = new DataOutputStreamOutput(new DataOutputStream(bytes));
    e.writeTo(output);
    output.close();
    
    StreamInput input = new InputStreamStreamInput(new ByteArrayInputStream(bytes.toByteArray()));
    ScriptException e2 = new ScriptException(input);
    input.close();
    
    assertEquals(e.getMessage(), e2.getMessage());
    assertEquals(e.getScriptStack(), e2.getScriptStack());
    assertEquals(e.getScript(), e2.getScript());
    assertEquals(e.getLang(), e2.getLang());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:ScriptExceptionTests.java

示例2: uncompress

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
private static BytesReference uncompress(BytesReference bytes, Compressor compressor) throws IOException {
    StreamInput compressed = compressor.streamInput(bytes.streamInput());
    BytesStreamOutput bStream = new BytesStreamOutput();
    Streams.copy(compressed, bStream);
    compressed.close();
    return bStream.bytes();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:CompressorFactory.java

示例3: testBytesStreamInput

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
public void testBytesStreamInput() throws IOException {
    byte stuff[] = new byte[] { 0, 1, 2, 3 };
    BytesRef stuffRef = new BytesRef(stuff, 2, 2);
    BytesArray stuffArray = new BytesArray(stuffRef);
    StreamInput input = stuffArray.streamInput();
    assertEquals(2, input.read());
    assertEquals(3, input.read());
    assertEquals(-1, input.read());
    input.close();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:StreamsTests.java

示例4: doTest

import org.elasticsearch.common.io.stream.StreamInput; //导入方法依赖的package包/类
private void doTest(byte bytes[]) throws IOException {
    ByteBuffer bb = ByteBuffer.wrap(bytes);
    StreamInput rawIn = new ByteBufferStreamInput(bb);
    Compressor c = compressor;

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    OutputStreamStreamOutput rawOs = new OutputStreamStreamOutput(bos);
    StreamOutput os = c.streamOutput(rawOs);

    Random r = random();
    int bufferSize = r.nextBoolean() ? 65535 : TestUtil.nextInt(random(), 1, 70000);
    int prepadding = r.nextInt(70000);
    int postpadding = r.nextInt(70000);
    byte buffer[] = new byte[prepadding + bufferSize + postpadding];
    r.nextBytes(buffer); // fill block completely with junk
    int len;
    while ((len = rawIn.read(buffer, prepadding, bufferSize)) != -1) {
        os.write(buffer, prepadding, len);
    }
    os.close();
    rawIn.close();

    // now we have compressed byte array

    byte compressed[] = bos.toByteArray();
    ByteBuffer bb2 = ByteBuffer.wrap(compressed);
    StreamInput compressedIn = new ByteBufferStreamInput(bb2);
    StreamInput in = c.streamInput(compressedIn);

    // randomize constants again
    bufferSize = r.nextBoolean() ? 65535 : TestUtil.nextInt(random(), 1, 70000);
    prepadding = r.nextInt(70000);
    postpadding = r.nextInt(70000);
    buffer = new byte[prepadding + bufferSize + postpadding];
    r.nextBytes(buffer); // fill block completely with junk

    ByteArrayOutputStream uncompressedOut = new ByteArrayOutputStream();
    while ((len = in.read(buffer, prepadding, bufferSize)) != -1) {
        uncompressedOut.write(buffer, prepadding, len);
    }
    uncompressedOut.close();

    assertArrayEquals(bytes, uncompressedOut.toByteArray());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:45,代码来源:DeflateCompressTests.java


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