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


Java BytesStreamOutput.bytes方法代码示例

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


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

示例1: run

import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
@Override
public Object run() {
    final BytesStreamOutput result = new BytesStreamOutput();
    try (UTF8StreamWriter writer = utf8StreamWriter().setOutput(result)) {
        // crazy reflection here
        SpecialPermission.check();
        AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
            ((Mustache) template.compiled()).execute(writer, vars);
            return null;
        });
    } catch (Exception e) {
        logger.error((Supplier<?>) () -> new ParameterizedMessage("Error running {}", template), e);
        throw new GeneralScriptException("Error running " + template, e);
    }
    return result.bytes();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:MustacheScriptEngineService.java

示例2: 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();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:TermVectorsWriter.java

示例3: testSerializeRequest

import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的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: messageReceived

import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
@Override
public void messageReceived(PullFullClusterStateRequest request, final TransportChannel channel) throws Exception {
    ClusterStateWithDLSN clusterStateWithDLSN = clusterStateOpLog.getLatestClusterState();
    if (!clusterStateWithDLSN.state().getClusterName().equals(request.clusterName)) {
       throw new java.lang.Exception("master cluster name is [" + clusterStateWithDLSN.state().getClusterName() + "], request cluster name is [" + request.clusterName + "]");
    }
    if (!clusterStateWithDLSN.state().nodes().localNodeMaster()) {
        throw new java.lang.Exception("current node is no longer master node");
    }
    BytesStreamOutput bStream = new BytesStreamOutput();
    try (StreamOutput stream = CompressorFactory.defaultCompressor().streamOutput(bStream)) {
        clusterStateWithDLSN.writeTo(stream);
    }
    BytesReference fullStateBytes = bStream.bytes();
    channel.sendResponse(new org.elasticsearch.transport.BytesTransportResponse(fullStateBytes));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:17,代码来源:PullFullClusterStateAction.java

示例5: 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();
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:25,代码来源:DistributedTranslog.java

示例6: markStoreCorrupted

import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
/**
 * Marks this store as corrupted. This method writes a <tt>corrupted_${uuid}</tt> file containing the given exception
 * message. If a store contains a <tt>corrupted_${uuid}</tt> file {@link #isMarkedCorrupted()} will return <code>true</code>.
 */
public void markStoreCorrupted(IOException exception) throws IOException {
    ensureOpen();
    if (!isMarkedCorrupted()) {
        String uuid = CORRUPTED + Strings.randomBase64UUID();
        try (IndexOutput output = this.directory().createOutput(uuid, IOContext.DEFAULT)) {
            CodecUtil.writeHeader(output, CODEC, VERSION);
            BytesStreamOutput out = new BytesStreamOutput();
            out.writeThrowable(exception);
            BytesReference bytes = out.bytes();
            output.writeVInt(bytes.length());
            output.writeBytes(bytes.array(), bytes.arrayOffset(), bytes.length());
            CodecUtil.writeFooter(output);
        } catch (IOException ex) {
            logger.warn("Can't mark store as corrupted", ex);
        }
        directory().sync(Collections.singleton(uuid));
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:Store.java

示例7: sendResponse

import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
@Override
public void sendResponse(Throwable error) throws IOException {
    BytesStreamOutput stream = new BytesStreamOutput();
    stream.skip(NettyHeader.HEADER_SIZE);
    RemoteTransportException tx = new RemoteTransportException(transport.nodeName(), transport.wrapAddress(channel.getLocalAddress()), action, error);
    stream.writeThrowable(tx);
    byte status = 0;
    status = TransportStatus.setResponse(status);
    status = TransportStatus.setError(status);

    BytesReference bytes = stream.bytes();
    ChannelBuffer buffer = bytes.toChannelBuffer();
    NettyHeader.writeHeader(buffer, requestId, status, version);
    channel.write(buffer);
    transportServiceAdapter.onResponseSent(requestId, action, error);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:17,代码来源:NettyTransportChannel.java

示例8: readMessage

import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
private void readMessage(MockChannel mockChannel, StreamInput input) throws IOException {
    Socket socket = mockChannel.activeChannel;
    byte[] minimalHeader = new byte[TcpHeader.MARKER_BYTES_SIZE];
    int firstByte = input.read();
    if (firstByte == -1) {
        throw new IOException("Connection reset by peer");
    }
    minimalHeader[0] = (byte) firstByte;
    minimalHeader[1] = (byte) input.read();
    int msgSize = input.readInt();
    if (msgSize == -1) {
        socket.getOutputStream().flush();
    } else {
        BytesStreamOutput output = new BytesStreamOutput();
        final byte[] buffer = new byte[msgSize];
        input.readFully(buffer);
        output.write(minimalHeader);
        output.writeInt(msgSize);
        output.write(buffer);
        final BytesReference bytes = output.bytes();
        if (TcpTransport.validateMessageHeader(bytes)) {
            InetSocketAddress remoteAddress = (InetSocketAddress) socket.getRemoteSocketAddress();
            messageReceived(bytes.slice(TcpHeader.MARKER_BYTES_SIZE + TcpHeader.MESSAGE_LENGTH_SIZE, msgSize),
                mockChannel, mockChannel.profile, remoteAddress, msgSize);
        } else {
            // ping message - we just drop all stuff
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:MockTcpTransport.java

示例9: serialize

import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
private static BytesReference serialize(Version version, Streamable streamable) throws IOException {
    BytesStreamOutput output = new BytesStreamOutput();
    output.setVersion(version);
    streamable.writeTo(output);
    output.flush();
    return output.bytes();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:ElasticsearchAssertions.java

示例10: uncompress

import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的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:baidu,项目名称:Elasticsearch,代码行数:8,代码来源:CompressorFactory.java

示例11: serializeDiffClusterState

import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
public static BytesReference serializeDiffClusterState(Diff diff, Version nodeVersion) throws IOException {
    BytesStreamOutput bStream = new BytesStreamOutput();
    try (StreamOutput stream = CompressorFactory.COMPRESSOR.streamOutput(bStream)) {
        stream.setVersion(nodeVersion);
        stream.writeBoolean(false);
        diff.writeTo(stream);
    }
    return bStream.bytes();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:PublishClusterStateAction.java

示例12: publishClusterStateVersionToNode

import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
public void publishClusterStateVersionToNode(final long newVersion,
        final DiscoveryNode node, 
        final TimeValue publishTimeout,
        final BlockingClusterStatePublishResponseHandler publishResponseHandler) {
    try {
        BytesStreamOutput bStream = new BytesStreamOutput();
        bStream.writeLong(newVersion);
        clusterService.localNode().writeTo(bStream);
        bStream.writeString(node.getId());
        BytesReference nodeBytes = bStream.bytes();
        TransportRequestOptions options = TransportRequestOptions.builder().withType(TransportRequestOptions.Type.STATE).withCompress(false).withTimeout(publishTimeout).build();
        transportService.sendRequest(node, PUBLISH_VERSION_ACTION_NAME, new BytesTransportRequest(nodeBytes, node.version()), 
                options, 
                new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {
            
            @Override
            public void handleResponse(TransportResponse.Empty response) {
                publishResponseHandler.onResponse(node);
            }
            
            @Override
            public void handleException(TransportException exp) {
                logger.debug("failed to send cluster state to {}, version {}", exp, node, newVersion);
                publishResponseHandler.onFailure(node, exp);
            }
        });
    } catch (Throwable t) {
        logger.warn("error sending cluster state to {}", t, node);
        publishResponseHandler.onFailure(node, t);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:32,代码来源:PublishClusterStateVersionAction.java

示例13: encodeSettings

import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
public static BytesReference encodeSettings(Settings settings) throws IOException {
    BytesStreamOutput bso = new BytesStreamOutput();
    XContentBuilder builder = XContentFactory.jsonBuilder(bso);
    builder.startObject();
    for (Map.Entry<String, String> entry : settings.getAsMap().entrySet()) {
        builder.field(entry.getKey(), entry.getValue());
    }
    builder.endObject();
    builder.flush();
    return bso.bytes();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:12,代码来源:FulltextAnalyzerResolver.java

示例14: run

import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
@Override
public Object run() {
    BytesStreamOutput result = new BytesStreamOutput();
    try (UTF8StreamWriter writer = utf8StreamWriter().setOutput(result)) {
        ((Mustache) template.compiled()).execute(writer, vars);
    } catch (Exception e) {
        logger.error("Error running " + template, e);
        throw new ScriptException("Error running " + template, e);
    }
    return result.bytes();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:12,代码来源:MustacheScriptEngineService.java

示例15: serializeFullClusterState

import org.elasticsearch.common.io.stream.BytesStreamOutput; //导入方法依赖的package包/类
public static BytesReference serializeFullClusterState(ClusterState clusterState, Version nodeVersion) throws IOException {
    BytesStreamOutput bStream = new BytesStreamOutput();
    try (StreamOutput stream = CompressorFactory.defaultCompressor().streamOutput(bStream)) {
        stream.setVersion(nodeVersion);
        stream.writeBoolean(true);
        clusterState.writeTo(stream);
    }
    return bStream.bytes();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:10,代码来源:PublishClusterStateAction.java


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