當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。