本文整理汇总了Java中org.elasticsearch.common.io.stream.BytesStreamOutput.close方法的典型用法代码示例。如果您正苦于以下问题:Java BytesStreamOutput.close方法的具体用法?Java BytesStreamOutput.close怎么用?Java BytesStreamOutput.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.common.io.stream.BytesStreamOutput
的用法示例。
在下文中一共展示了BytesStreamOutput.close方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeHeader
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
private BytesReference writeHeader(int numFieldsWritten, boolean getTermStatistics, boolean getFieldStatistics, boolean scores) throws IOException {
// now, write the information about offset of the terms in the
// termVectors field
BytesStreamOutput header = new BytesStreamOutput();
header.writeString(HEADER);
header.writeInt(CURRENT_VERSION);
header.writeBoolean(getTermStatistics);
header.writeBoolean(getFieldStatistics);
header.writeBoolean(scores);
header.writeVInt(numFieldsWritten);
for (int i = 0; i < fields.size(); i++) {
header.writeString(fields.get(i));
header.writeVLong(fieldOffset.get(i).longValue());
}
header.close();
return header.bytes();
}
示例2: testSerialization
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
public void testSerialization() throws Exception {
UnassignedInfo.Reason reason = RandomPicks.randomFrom(random(), UnassignedInfo.Reason.values());
UnassignedInfo meta = reason == UnassignedInfo.Reason.ALLOCATION_FAILED ?
new UnassignedInfo(reason, randomBoolean() ? randomAsciiOfLength(4) : null, null, randomIntBetween(1, 100), System.nanoTime(),
System.currentTimeMillis(), false, AllocationStatus.NO_ATTEMPT):
new UnassignedInfo(reason, randomBoolean() ? randomAsciiOfLength(4) : null);
BytesStreamOutput out = new BytesStreamOutput();
meta.writeTo(out);
out.close();
UnassignedInfo read = new UnassignedInfo(out.bytes().streamInput());
assertThat(read.getReason(), equalTo(meta.getReason()));
assertThat(read.getUnassignedTimeInMillis(), equalTo(meta.getUnassignedTimeInMillis()));
assertThat(read.getMessage(), equalTo(meta.getMessage()));
assertThat(read.getDetails(), equalTo(meta.getDetails()));
assertThat(read.getNumFailedAllocations(), equalTo(meta.getNumFailedAllocations()));
}
示例3: writeOperation
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
/**
*
* @param operation
* @return
* @throws IOException
*/
public Tuple<Future<DLSN>, Tuple<BytesReference, Long>> writeOperation(Translog.Operation operation, AtomicLong txid) throws IOException {
BytesStreamOutput out = new BytesStreamOutput();
try (ReleasableLock lock = writeLock.acquire()) {
Future<DLSN> writeResult = null;
out.writeByte(operation.opType().id());
operation.writeTo(out);
BytesReference bytes = out.bytes();
LogRecord logRecord = new LogRecord(txid.incrementAndGet(), bytes.toBytes());
writeResult = logWriter.write(logRecord);
sizeInBytes += (20 + logRecord.getPayload().length);
++ numOperations;
return new Tuple<Future<DLSN>, Tuple<BytesReference, Long>>(writeResult, new Tuple<BytesReference, Long>(bytes, txid.get()));
} catch (TransactionIdOutOfOrderException e) {
throw e;
} finally {
out.close();
}
}
示例4: testWriteToOutputStream
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
public void testWriteToOutputStream() throws IOException {
int length = randomIntBetween(10, PAGE_SIZE * 4);
BytesReference pbr = newBytesReference(length);
BytesStreamOutput out = new BytesStreamOutput();
pbr.writeTo(out);
assertEquals(pbr.length(), out.size());
assertArrayEquals(BytesReference.toBytes(pbr), BytesReference.toBytes(out.bytes()));
out.close();
}
示例5: testSliceWriteToOutputStream
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
public void testSliceWriteToOutputStream() throws IOException {
int length = randomIntBetween(10, PAGE_SIZE * randomIntBetween(2, 5));
BytesReference pbr = newBytesReference(length);
int sliceOffset = randomIntBetween(1, length / 2);
int sliceLength = length - sliceOffset;
BytesReference slice = pbr.slice(sliceOffset, sliceLength);
BytesStreamOutput sliceOut = new BytesStreamOutput(sliceLength);
slice.writeTo(sliceOut);
assertEquals(slice.length(), sliceOut.size());
assertArrayEquals(BytesReference.toBytes(slice), BytesReference.toBytes(sliceOut.bytes()));
sliceOut.close();
}
示例6: serializeDeserialize
import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
public T serializeDeserialize() throws IOException {
BytesStreamOutput out = new BytesStreamOutput();
source.writeTo(out);
out.close();
StreamInput in = out.bytes().streamInput();
T obj = deserialize(in);
lastRead = obj;
return obj;
}