Java Code Examples for org.elasticsearch.common.io.stream.StreamInput#read()

The following examples show how to use org.elasticsearch.common.io.stream.StreamInput#read() . 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: InternalTopK.java    From elasticsearch-topk-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    name = in.readString();
    size = in.readInt();
    int n;
    if (in.readBoolean()) {
        int capacity = in.readInt();
        this.summary = new StreamSummary<>(capacity);
        n = in.readInt();
        byte[] bytes = new byte[n];
        in.read(bytes);
        try {
            summary.fromBytes(bytes);
        } catch (ClassNotFoundException e) {
            throw new IOException("Failed to build summary", e);
        }
    }
    n = in.readInt();
    this.buckets = new ArrayList<>();
    this.bucketsMap = null;
    for (int i = 0; i < n; ++i) {
        this.buckets.add(Bucket.readFrom(in));
    }
    // buckets are alreaduy sorted here
}
 
Example 2
Source File: BlobStartPrefixResponse.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.readInt();
    existingDigests = new byte[size][20];
    for (int i=0; i<size; i++){
        in.read(existingDigests[i]);
    }
}
 
Example 3
Source File: PutChunkRequest.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);
    digest = new byte[20];
    in.read(digest);
    currentPos = in.readVLong();
}
 
Example 4
Source File: BlobStartPrefixResponse.java    From crate with Apache License 2.0 5 votes vote down vote up
public BlobStartPrefixResponse(StreamInput in) throws IOException {
    int size = in.readInt();
    existingDigests = new byte[size][20];
    for (int i = 0; i < size; i++) {
        in.read(existingDigests[i]);
    }
}
 
Example 5
Source File: TcpTransport.java    From crate with Apache License 2.0 5 votes vote down vote up
protected void validateRequest(StreamInput stream, long requestId, String action) throws IOException {
    final int nextByte = stream.read();
    // calling read() is useful to make sure the message is fully read, even if there some kind of EOS marker
    if (nextByte != -1) {
        throw new IllegalStateException("Message not fully read (request) for requestId [" + requestId + "], action [" + action
            + "], available [" + stream.available() + "]; resetting");
    }
}
 
Example 6
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 7
Source File: DeleteBlobRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    digest = new byte[20];
    in.read(digest);
}
 
Example 8
Source File: StartBlobRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    digest = new byte[20];
    in.read(digest);
}
 
Example 9
Source File: DeleteBlobRequest.java    From crate with Apache License 2.0 4 votes vote down vote up
public DeleteBlobRequest(StreamInput in) throws IOException {
    super(in);
    digest = new byte[20];
    in.read(digest);
}
 
Example 10
Source File: StartBlobRequest.java    From crate with Apache License 2.0 4 votes vote down vote up
public StartBlobRequest(StreamInput in) throws IOException {
    super(in);
    digest = new byte[20];
    in.read(digest);
}
 
Example 11
Source File: PutChunkRequest.java    From crate with Apache License 2.0 4 votes vote down vote up
public PutChunkRequest(StreamInput in) throws IOException {
    super(in);
    digest = new byte[20];
    in.read(digest);
    currentPos = in.readVLong();
}