|
@@ -288,9 +288,7 @@ public class Text extends BinaryComparable
|
|
|
@Override
|
|
|
public void readFields(DataInput in) throws IOException {
|
|
|
int newLength = WritableUtils.readVInt(in);
|
|
|
- setCapacity(newLength, false);
|
|
|
- in.readFully(bytes, 0, newLength);
|
|
|
- length = newLength;
|
|
|
+ readWithKnownLength(in, newLength);
|
|
|
}
|
|
|
|
|
|
public void readFields(DataInput in, int maxLength) throws IOException {
|
|
@@ -302,9 +300,7 @@ public class Text extends BinaryComparable
|
|
|
throw new IOException("tried to deserialize " + newLength +
|
|
|
" bytes of data, but maxLength = " + maxLength);
|
|
|
}
|
|
|
- setCapacity(newLength, false);
|
|
|
- in.readFully(bytes, 0, newLength);
|
|
|
- length = newLength;
|
|
|
+ readWithKnownLength(in, newLength);
|
|
|
}
|
|
|
|
|
|
/** Skips over one Text in the input. */
|
|
@@ -313,6 +309,17 @@ public class Text extends BinaryComparable
|
|
|
WritableUtils.skipFully(in, length);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Read a Text object whose length is already known.
|
|
|
+ * This allows creating Text from a stream which uses a different serialization
|
|
|
+ * format.
|
|
|
+ */
|
|
|
+ public void readWithKnownLength(DataInput in, int len) throws IOException {
|
|
|
+ setCapacity(len, false);
|
|
|
+ in.readFully(bytes, 0, len);
|
|
|
+ length = len;
|
|
|
+ }
|
|
|
+
|
|
|
/** serialize
|
|
|
* write this object to out
|
|
|
* length uses zero-compressed encoding
|