Skip to content

Commit 7bb2f17

Browse files
committed
Pull common StreamInput#readText code into helper method
1 parent f4f6da6 commit 7bb2f17

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,7 @@ public BigInteger readBigInteger() throws IOException {
386386
return new BigInteger(readString());
387387
}
388388

389-
@Nullable
390-
public Text readOptionalText() throws IOException {
391-
int length = readInt();
392-
if (length == -1) {
393-
return null;
394-
}
389+
private Text readText(int length) throws IOException {
395390
byte[] bytes = new byte[length];
396391
if (length > 0) {
397392
readBytes(bytes, 0, length);
@@ -400,15 +395,19 @@ public Text readOptionalText() throws IOException {
400395
return new Text(encoded);
401396
}
402397

398+
@Nullable
399+
public Text readOptionalText() throws IOException {
400+
int length = readInt();
401+
if (length == -1) {
402+
return null;
403+
}
404+
return readText(length);
405+
}
406+
403407
public Text readText() throws IOException {
404408
// use Text so we can cache the string if it's ever converted to it
405409
int length = readInt();
406-
byte[] bytes = new byte[length];
407-
if (length > 0) {
408-
readBytes(bytes, 0, length);
409-
}
410-
var encoded = new XContentString.EncodedBytes(bytes);
411-
return new Text(encoded);
410+
return readText(length);
412411
}
413412

414413
@Nullable

0 commit comments

Comments
 (0)