Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public ArrayWritable(Class<? extends Writable> valueClass, Writable[] values) {
public ArrayWritable(String[] strings) {
this(Text.class, new Writable[strings.length]);
for (int i = 0; i < strings.length; i++) {
values[i] = new UTF8(strings[i]);
values[i] = new Text(strings[i]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;

import org.junit.Assert;
import org.junit.Test;


Expand Down Expand Up @@ -101,5 +108,29 @@ public void testArrayWritableStringConstructor() {
assertArrayEquals("testArrayWritableStringConstructor toString error!!!",
original, arrayWritable.toStrings());
}

@Test
public void testArrayWritableStrings() throws Exception {
String[] original = {"The 1896 Cedar Keys hurricane was a powerful tropical cyclone " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think we should be using wikipedia text even if it's interesting. just use something from our own docs

"that devastated much of the East Coast of the United States, starting with " +
"Florida's Cedar Keys, near the end of September. The storm's rapid movement " +
"allowed it to maintain much of its intensity after landfall, becoming one " +
"of the costliest United States hurricanes at the time.",
"The fourth tropical cyclone of the 1896 Atlantic hurricane season, it washed out " +
"connecting the Cedar Keys to the mainland with a 10.5 ft (3.2 m) storm surge, " +
"and submerged much of the island group (Cedar Key flooding pictured)."};
ArrayWritable arrayWritable = new ArrayWritable(original);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutput out = new DataOutputStream(baos);
arrayWritable.write(out);
baos.close();

DataInput in = new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));
arrayWritable.readFields(in);

String[] current = arrayWritable.toStrings();
Assert.assertEquals(original[0], current[0]);
Assert.assertEquals(original[1], current[1]);
}

}