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

The following examples show how to use org.elasticsearch.common.io.stream.StreamInput. 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 File: PartitionName.java    From crate with 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 #2
Source File: InternalSearchHits.java    From Elasticsearch with 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 #3
Source File: ClusterIndexHealth.java    From Elasticsearch with 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 #4
Source File: TransportClearVotingConfigExclusionsActionTests.java    From crate with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: AbstractProjectionsPhase.java    From crate with 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
Source File: SignificantStringTerms.java    From Elasticsearch with 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 #7
Source File: GetMappingsResponse.java    From Elasticsearch with 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 #8
Source File: JobRequest.java    From crate with 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 File: RestoreSnapshotRequest.java    From Elasticsearch with 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 #10
Source File: MockTcpTransport.java    From crate with 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 #11
Source File: CompressorFactory.java    From crate with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #12
Source File: BoundTransportAddress.java    From Elasticsearch with 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 #13
Source File: MultiTermVectorsRequest.java    From Elasticsearch with 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));
    }
}
 
Example #14
Source File: TcpTransport.java    From crate with 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 #15
Source File: BulkResponse.java    From Elasticsearch with 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 #16
Source File: ExtendedAnalyzeResponse.java    From elasticsearch-extended-analyze with Apache License 2.0 5 votes vote down vote up
@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 #17
Source File: InternalPathHierarchy.java    From elasticsearch-aggregation-pathhierarchy with MIT License 5 votes vote down vote up
/**
 * 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 #18
Source File: HyperLogLogDistinctAggregation.java    From crate with 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 #19
Source File: CoordinateMultiSearchResponse.java    From siren-join with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 #20
Source File: LicenseKeyTest.java    From crate with 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 #21
Source File: ElasticsearchException.java    From Elasticsearch with 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 #22
Source File: GetIndexedScriptRequest.java    From Elasticsearch with 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 File: SearchStats.java    From Elasticsearch with 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 #24
Source File: JobResponse.java    From Elasticsearch with 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 #25
Source File: ScriptService.java    From Elasticsearch with 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 File: GetSettingsResponse.java    From Elasticsearch with 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 #27
Source File: RepairTenantRequest.java    From Elasticsearch with 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 #28
Source File: QueryCacheStats.java    From crate with 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 #29
Source File: GeoReference.java    From crate with 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 #30
Source File: MultiPercolateResponse.java    From Elasticsearch with 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);
    }
}