HADOOP-17430. Restore ability to set Text to empty byte array (#2545)
Contributed by gaozhan.ding
This commit is contained in:
parent
42eb9ff68e
commit
b1abb10ea2
@ -223,10 +223,18 @@ public void set(String string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set to a utf8 byte array.
|
* Set to a utf8 byte array. If the length of <code>utf8</code> is
|
||||||
|
* <em>zero</em>, actually clear {@link #bytes} and any existing
|
||||||
|
* data is lost.
|
||||||
*/
|
*/
|
||||||
public void set(byte[] utf8) {
|
public void set(byte[] utf8) {
|
||||||
set(utf8, 0, utf8.length);
|
if (utf8.length == 0) {
|
||||||
|
bytes = EMPTY_BYTES;
|
||||||
|
length = 0;
|
||||||
|
textLength = -1;
|
||||||
|
} else {
|
||||||
|
set(utf8, 0, utf8.length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -459,4 +459,22 @@ public void testUtf8Length() {
|
|||||||
2, Text.utf8Length(new String(new char[]{(char)254})));
|
2, Text.utf8Length(new String(new char[]{(char)254})));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetBytes(){
|
||||||
|
Text a = new Text(new byte[100]);
|
||||||
|
assertEquals("testSetBytes100 getLength error !",
|
||||||
|
100, a.getLength());
|
||||||
|
assertEquals("testSetBytes100 getBytes.length error !",
|
||||||
|
100, a.getBytes().length);
|
||||||
|
assertEquals("testSetBytes100 getTextLength error !",
|
||||||
|
100, a.getTextLength());
|
||||||
|
|
||||||
|
a.set(new byte[0]);
|
||||||
|
assertEquals("testSetBytes0 getLength error !",
|
||||||
|
0, a.getLength());
|
||||||
|
assertEquals("testSetBytes0 getBytes.length error !",
|
||||||
|
0, a.getBytes().length);
|
||||||
|
assertEquals("testSetBytes0 getTextLength error !",
|
||||||
|
0, a.getTextLength());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user