Skip to content

Commit 3dfc0e1

Browse files
committed
Add
1 parent 2e8507f commit 3dfc0e1

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

server/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
requires org.apache.lucene.queryparser;
5555
requires org.apache.lucene.sandbox;
5656
requires org.apache.lucene.suggest;
57+
requires org.elasticsearch.server;
5758

5859
exports org.elasticsearch;
5960
exports org.elasticsearch.action;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.action.index;
11+
12+
import org.elasticsearch.common.bytes.BytesReference;
13+
import org.elasticsearch.common.io.stream.StreamInput;
14+
import org.elasticsearch.common.io.stream.StreamOutput;
15+
import org.elasticsearch.common.io.stream.Writeable;
16+
import org.elasticsearch.common.xcontent.XContentHelper;
17+
import org.elasticsearch.core.Releasable;
18+
import org.elasticsearch.xcontent.XContentType;
19+
20+
import java.io.IOException;
21+
import java.util.Map;
22+
23+
public class SourceContext implements Writeable {
24+
25+
private XContentType contentType;
26+
private BytesReference source;
27+
private Releasable sourceReleasable;
28+
29+
public SourceContext(XContentType contentType, BytesReference source, Releasable sourceReleasable) {
30+
this.contentType = contentType;
31+
this.source = source;
32+
this.sourceReleasable = sourceReleasable;
33+
}
34+
35+
public SourceContext(StreamInput in) throws IOException {
36+
if (in.readBoolean()) {
37+
// faster than StreamInput::readEnum, do not replace we read a lot of these instances at times
38+
contentType = XContentType.ofOrdinal(in.readByte());
39+
} else {
40+
contentType = null;
41+
}
42+
source = in.readBytesReference();
43+
}
44+
45+
@Override
46+
public void writeTo(StreamOutput out) throws IOException {
47+
if (contentType != null) {
48+
out.writeBoolean(true);
49+
XContentHelper.writeTo(out, contentType);
50+
} else {
51+
out.writeBoolean(false);
52+
}
53+
out.writeBytesReference(source);
54+
}
55+
56+
public XContentType getContentType() {
57+
return contentType;
58+
}
59+
60+
public BytesReference getSource() {
61+
return source;
62+
}
63+
64+
public Map<String, Object> sourceAsMap() {
65+
return XContentHelper.convertToMap(source, false, contentType).v2();
66+
}
67+
68+
69+
}

0 commit comments

Comments
 (0)