Java Code Examples for org.elasticsearch.common.io.stream.StreamInput

The following examples show how to use org.elasticsearch.common.io.stream.StreamInput. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Elasticsearch   Source File: InternalSearchHits.java    License: Apache License 2.0 6 votes vote down vote up
public void readFrom(StreamInput in, StreamContext context) throws IOException {
    totalHits = in.readVLong();
    maxScore = in.readFloat();
    int size = in.readVInt();
    if (size == 0) {
        hits = EMPTY;
    } else {
        if (context.streamShardTarget() == StreamContext.ShardTargetType.LOOKUP) {
            // read the lookup table first
            int lookupSize = in.readVInt();
            for (int i = 0; i < lookupSize; i++) {
                context.handleShardLookup().put(in.readVInt(), readSearchShardTarget(in));
            }
        }

        hits = new InternalSearchHit[size];
        for (int i = 0; i < hits.length; i++) {
            hits[i] = readSearchHit(in, context);
        }
    }
}
 
Example 2
Source Project: Elasticsearch   Source File: GetMappingsResponse.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    int size = in.readVInt();
    ImmutableOpenMap.Builder<String, ImmutableOpenMap<String, MappingMetaData>> indexMapBuilder = ImmutableOpenMap.builder();
    for (int i = 0; i < size; i++) {
        String key = in.readString();
        int valueSize = in.readVInt();
        ImmutableOpenMap.Builder<String, MappingMetaData> typeMapBuilder = ImmutableOpenMap.builder();
        for (int j = 0; j < valueSize; j++) {
            typeMapBuilder.put(in.readString(), MappingMetaData.PROTO.readFrom(in));
        }
        indexMapBuilder.put(key, typeMapBuilder.build());
    }
    mappings = indexMapBuilder.build();
}
 
Example 3
Source Project: Elasticsearch   Source File: RestoreSnapshotRequest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    snapshot = in.readString();
    repository = in.readString();
    indices = in.readStringArray();
    indicesOptions = IndicesOptions.readIndicesOptions(in);
    renamePattern = in.readOptionalString();
    renameReplacement = in.readOptionalString();
    waitForCompletion = in.readBoolean();
    includeGlobalState = in.readBoolean();
    partial = in.readBoolean();
    includeAliases = in.readBoolean();
    settings = readSettingsFromStream(in);
    indexSettings = readSettingsFromStream(in);
    ignoreIndexSettings = in.readStringArray();
}
 
Example 4
Source Project: Elasticsearch   Source File: SignificantStringTerms.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void doReadFrom(StreamInput in) throws IOException {
    this.requiredSize = readSize(in);
    this.minDocCount = in.readVLong();
    this.subsetSize = in.readVLong();
    this.supersetSize = in.readVLong();
    significanceHeuristic = SignificanceHeuristicStreams.read(in);
    int size = in.readVInt();
    List<InternalSignificantTerms.Bucket> buckets = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        Bucket bucket = new Bucket(subsetSize, supersetSize);
        bucket.readFrom(in);
        buckets.add(bucket);
    }
    this.buckets = buckets;
    this.bucketMap = null;
}
 
Example 5
Source Project: crate   Source File: AbstractProjectionsPhase.java    License: Apache License 2.0 6 votes vote down vote up
protected AbstractProjectionsPhase(StreamInput in) throws IOException {
    name = in.readString();
    jobId = new UUID(in.readLong(), in.readLong());
    executionPhaseId = in.readVInt();

    int numCols = in.readVInt();
    if (numCols > 0) {
        outputTypes = new ArrayList<>(numCols);
        for (int i = 0; i < numCols; i++) {
            outputTypes.add(DataTypes.fromStream(in));
        }
    }

    int numProjections = in.readVInt();
    if (numProjections > 0) {
        projections = new ArrayList<>(numProjections);
        for (int i = 0; i < numProjections; i++) {
            projections.add(Projection.fromStream(in));
        }
    }
}
 
Example 6
private TransportResponseHandler<ClearVotingConfigExclusionsResponse> responseHandler(
    Consumer<ClearVotingConfigExclusionsResponse> onResponse, Consumer<TransportException> onException) {
    return new TransportResponseHandler<ClearVotingConfigExclusionsResponse>() {
        @Override
        public void handleResponse(ClearVotingConfigExclusionsResponse response) {
            onResponse.accept(response);
        }

        @Override
        public void handleException(TransportException exp) {
            onException.accept(exp);
        }

        @Override
        public String executor() {
            return Names.SAME;
        }

        @Override
        public ClearVotingConfigExclusionsResponse read(StreamInput in) throws IOException {
            return new ClearVotingConfigExclusionsResponse(in);
        }
    };
}
 
Example 7
Source Project: crate   Source File: PartitionName.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * decodes an encoded ident into it's values
 */
@Nullable
public static List<String> decodeIdent(@Nullable String ident) {
    if (ident == null) {
        return List.of();
    }
    byte[] inputBytes = BASE32.decode(ident.toUpperCase(Locale.ROOT));
    try (StreamInput in = StreamInput.wrap(inputBytes)) {
        int size = in.readVInt();
        List<String> values = new ArrayList<>(size);
        for (int i = 0; i < size; i++) {
            values.add(readValueFrom(in));
        }
        return values;
    } catch (IOException e) {
        throw new IllegalArgumentException(
            String.format(Locale.ENGLISH, "Invalid partition ident: %s", ident), e);
    }
}
 
Example 8
Source Project: crate   Source File: JobRequest.java    License: Apache License 2.0 6 votes vote down vote up
public JobRequest(StreamInput in) throws IOException {
    super(in);

    jobId = new UUID(in.readLong(), in.readLong());
    coordinatorNodeId = in.readString();

    int numNodeOperations = in.readVInt();
    ArrayList<NodeOperation> nodeOperations = new ArrayList<>(numNodeOperations);
    for (int i = 0; i < numNodeOperations; i++) {
        nodeOperations.add(new NodeOperation(in));
    }
    this.nodeOperations = nodeOperations;
    enableProfiling = in.readBoolean();

    sessionSettings = new SessionSettings(in);
}
 
Example 9
Source Project: Elasticsearch   Source File: ClusterIndexHealth.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    index = in.readString();
    numberOfShards = in.readVInt();
    numberOfReplicas = in.readVInt();
    activePrimaryShards = in.readVInt();
    activeShards = in.readVInt();
    relocatingShards = in.readVInt();
    initializingShards = in.readVInt();
    unassignedShards = in.readVInt();
    status = ClusterHealthStatus.fromValue(in.readByte());

    int size = in.readVInt();
    for (int i = 0; i < size; i++) {
        ClusterShardHealth shardHealth = readClusterShardHealth(in);
        shards.put(shardHealth.getId(), shardHealth);
    }
    validationFailures = Arrays.asList(in.readStringArray());
}
 
Example 10
Source Project: crate   Source File: LicenseKeyTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLicenseKeyStreaming() throws IOException {
    BytesStreamOutput stream = new BytesStreamOutput();
    LicenseKey licenseKey = createLicenseKey();
    licenseKey.writeTo(stream);

    StreamInput in = stream.bytes().streamInput();
    LicenseKey licenseKey2 = new LicenseKey(in);
    assertEquals(licenseKey, licenseKey2);
}
 
Example 11
Source Project: Elasticsearch   Source File: ElasticsearchException.java    License: Apache License 2.0 5 votes vote down vote up
public ElasticsearchException(StreamInput in) throws IOException {
    super(in.readOptionalString(), in.readThrowable());
    readStackTrace(this, in);
    int numKeys = in.readVInt();
    for (int i = 0; i < numKeys; i++) {
        final String key = in.readString();
        final int numValues = in.readVInt();
        final ArrayList<String> values = new ArrayList<>(numValues);
        for (int j = 0; j < numValues; j++) {
            values.add(in.readString());
        }
        headers.put(key, values);
    }
}
 
Example 12
Source Project: crate   Source File: TcpTransport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Executed for a received response error
 */
private void handlerResponseError(StreamInput stream, final TransportResponseHandler handler) {
    Exception error;
    try {
        error = stream.readException();
    } catch (Exception e) {
        error = new TransportSerializationException("Failed to deserialize exception response from stream", e);
    }
    handleException(handler, error);
}
 
Example 13
Source Project: anomaly-detection   Source File: AnomalyResultResponse.java    License: Apache License 2.0 5 votes vote down vote up
public AnomalyResultResponse(StreamInput in) throws IOException {
    super(in);
    anomalyGrade = in.readDouble();
    confidence = in.readDouble();
    anomalyScore = in.readDouble();
    int size = in.readVInt();
    features = new ArrayList<FeatureData>();
    for (int i = 0; i < size; i++) {
        String featureId = in.readString();
        String featureName = in.readString();
        double featureValue = in.readDouble();
        features.add(new FeatureData(featureId, featureName, featureValue));
    }
    error = in.readOptionalString();
}
 
Example 14
Source Project: crate   Source File: MockTcpTransport.java    License: Apache License 2.0 5 votes vote down vote up
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 {
        try (BytesStreamOutput output = new ReleasableBytesStreamOutput(msgSize, bigArrays)) {
            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
            }
        }
    }
}
 
Example 15
@Override
public void readFrom(StreamInput in) throws IOException {
    term = in.readString();
    startOffset = in.readInt();
    endOffset = in.readInt();
    position = in.readVInt();
    type = in.readOptionalString();
    extendedAttributes = (Map<String, Map<String, Object>>) in.readGenericValue();
}
 
Example 16
@Override
public void readFrom(StreamInput in) throws IOException {
  super.readFrom(in);
  items = new Item[in.readVInt()];
  for (int i = 0; i < items.length; i++) {
    items[i] = Item.readItem(in);
  }
}
 
Example 17
Source Project: crate   Source File: QueryCacheStats.java    License: Apache License 2.0 5 votes vote down vote up
public QueryCacheStats(StreamInput in) throws IOException {
    ramBytesUsed = in.readLong();
    hitCount = in.readLong();
    missCount = in.readLong();
    cacheCount = in.readLong();
    cacheSize = in.readLong();
}
 
Example 18
Source Project: crate   Source File: GeoReference.java    License: Apache License 2.0 5 votes vote down vote up
public GeoReference(StreamInput in) throws IOException {
    super(in);
    geoTree = in.readString();
    precision = in.readOptionalString();
    treeLevels = in.readBoolean() ? null : in.readVInt();
    distanceErrorPct = in.readBoolean() ? null : in.readDouble();
}
 
Example 19
Source Project: Elasticsearch   Source File: RepairTenantRequest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    int tenantNum = in.readInt();
    this.tenantNames = new String[tenantNum];
    for (int i = 0; i < tenantNum; ++i) {
        tenantNames[i] = in.readString();
    }
}
 
Example 20
Source Project: crate   Source File: HyperLogLogDistinctAggregation.java    License: Apache License 2.0 5 votes vote down vote up
HllState(StreamInput in) throws IOException {
    if (in.getVersion().onOrAfter(Version.V_4_1_0)) {
        this.allOn4_1 = in.readBoolean();
    } else {
        this.allOn4_1 = false;
    }
    dataType = DataTypes.fromStream(in);
    murmur3Hash = Murmur3Hash.getForType(dataType, allOn4_1);
    if (in.readBoolean()) {
        hyperLogLogPlusPlus = HyperLogLogPlusPlus.readFrom(in);
    }
}
 
Example 21
Source Project: Elasticsearch   Source File: BoundTransportAddress.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    int boundAddressLength = in.readInt();
    boundAddresses = new TransportAddress[boundAddressLength];
    for (int i = 0; i < boundAddressLength; i++) {
        boundAddresses[i] = TransportAddressSerializers.addressFromStream(in);
    }
    publishAddress = TransportAddressSerializers.addressFromStream(in);
}
 
Example 22
Source Project: Elasticsearch   Source File: GetIndexedScriptRequest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    scriptLang = in.readString();
    id = in.readString();
    this.versionType = VersionType.fromValue(in.readByte());
    this.version = in.readLong();
}
 
Example 23
Source Project: Elasticsearch   Source File: MultiPercolateResponse.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    int size = in.readVInt();
    items = new Item[size];
    for (int i = 0; i < items.length; i++) {
        items[i] = new Item();
        items[i].readFrom(in);
    }
}
 
Example 24
Source Project: Elasticsearch   Source File: GetSettingsResponse.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    int size = in.readVInt();
    ImmutableOpenMap.Builder<String, Settings> builder = ImmutableOpenMap.builder();
    for (int i = 0; i < size; i++) {
        builder.put(in.readString(), Settings.readSettingsFromStream(in));
    }
    indexToSettings = builder.build();
}
 
Example 25
Source Project: Elasticsearch   Source File: ScriptService.java    License: Apache License 2.0 5 votes vote down vote up
public static ScriptType readFrom(StreamInput in) throws IOException {
    int scriptTypeVal = in.readVInt();
    for (ScriptType type : values()) {
        if (type.val == scriptTypeVal) {
            return type;
        }
    }
    throw new IllegalArgumentException("Unexpected value read for ScriptType got [" + scriptTypeVal + "] expected one of ["
            + INLINE.val + "," + FILE.val + "," + INDEXED.val + "]");
}
 
Example 26
Source Project: Elasticsearch   Source File: JobResponse.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    int size = in.readVInt();
    for (int i = 0; i < size; i++) {
        StreamBucket bucket = new StreamBucket(streamers);
        bucket.readFrom(in);
        directResponse.add(bucket);
    }
}
 
Example 27
Source Project: Elasticsearch   Source File: SearchStats.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    queryCount = in.readVLong();
    queryTimeInMillis = in.readVLong();
    queryCurrent = in.readVLong();

    fetchCount = in.readVLong();
    fetchTimeInMillis = in.readVLong();
    fetchCurrent = in.readVLong();

    scrollCount = in.readVLong();
    scrollTimeInMillis = in.readVLong();
    scrollCurrent = in.readVLong();
}
 
Example 28
/**
 * Read from a stream.
 */
public InternalBucket(StreamInput in) throws IOException {
    termBytes = in.readBytesRef();
    docCount = in.readLong();
    aggregations = new InternalAggregations(in);
    level = in.readInt();
    minDepth = in.readInt();
    basename = in.readString();
    int pathsSize = in.readInt();
    paths = new String[pathsSize];
    for (int i=0; i < pathsSize; i++) {
        paths[i] = in.readString();
    }
}
 
Example 29
Source Project: Elasticsearch   Source File: BulkResponse.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    responses = new BulkItemResponse[in.readVInt()];
    for (int i = 0; i < responses.length; i++) {
        responses[i] = BulkItemResponse.readBulkItem(in);
    }
    tookInMillis = in.readVLong();
}
 
Example 30
Source Project: Elasticsearch   Source File: MultiTermVectorsRequest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    preference = in.readOptionalString();
    int size = in.readVInt();
    requests = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        requests.add(TermVectorsRequest.readTermVectorsRequest(in));
    }
}