add read/write optional text
This commit is contained in:
parent
0e5287f1f2
commit
bcdda811ef
|
@ -192,6 +192,15 @@ public abstract class StreamInput extends InputStream {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Text readOptionalText() throws IOException {
|
||||||
|
int length = readInt();
|
||||||
|
if (length == -1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new StringAndBytesText(readBytesReference(length));
|
||||||
|
}
|
||||||
|
|
||||||
public Text readText() throws IOException {
|
public Text readText() throws IOException {
|
||||||
// use StringAndBytes so we can cache the string if its ever converted to it
|
// use StringAndBytes so we can cache the string if its ever converted to it
|
||||||
int length = readInt();
|
int length = readInt();
|
||||||
|
|
|
@ -184,6 +184,14 @@ public abstract class StreamOutput extends OutputStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeOptionalText(@Nullable Text text) throws IOException {
|
||||||
|
if (text == null) {
|
||||||
|
writeInt(-1);
|
||||||
|
} else {
|
||||||
|
writeText(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void writeText(Text text) throws IOException {
|
public void writeText(Text text) throws IOException {
|
||||||
if (!text.hasBytes() && seekPositionSupported()) {
|
if (!text.hasBytes() && seekPositionSupported()) {
|
||||||
long pos1 = position();
|
long pos1 = position();
|
||||||
|
|
Loading…
Reference in New Issue