@Test public void testEmptyArrayReadWrite() throws Exception { ArrayWritable array = new WritableArrayWritable(Text.class); FastByteArrayOutputStream out = new FastByteArrayOutputStream(); DataOutputStream da = new DataOutputStream(out); array.write(da); da.close(); WritableArrayWritable waw = new WritableArrayWritable(NullWritable.class); waw.readFields(new DataInputStream(new FastByteArrayInputStream(out.bytes()))); assertSame(array.getValueClass(), waw.getValueClass()); } }
@Override public void write(DataOutput out) throws IOException { out.writeUTF(getValueClass().getName()); Writable[] writables = get(); // handle null - ArrayWritable does not if (writables == null) { out.writeInt(0); } else { super.write(out); } } }
return new WritableArrayWritable(arrayType);
@Test public void testMapWithArrayReadWrite() throws Exception { LinkedMapWritable written = new LinkedMapWritable(); ArrayWritable array = new WritableArrayWritable(Text.class); array.set(new Writable[] { new Text("one") , new Text("two"), new Text("three")} ); written.put(new Text("foo"), array); FastByteArrayOutputStream out = new FastByteArrayOutputStream(); DataOutputStream da = new DataOutputStream(out); written.write(da); da.close(); LinkedMapWritable read = new LinkedMapWritable(); read.readFields(new DataInputStream(new FastByteArrayInputStream(out.bytes()))); assertThat(read.size(), is(written.size())); assertThat(read.toString(), is(written.toString())); }
@Override public void write(DataOutput out) throws IOException { out.writeUTF(getValueClass().getName()); Writable[] writables = get(); // handle null - ArrayWritable does not if (writables == null) { out.writeInt(0); } else { super.write(out); } } }
return new WritableArrayWritable(arrayType);
@Override public void write(DataOutput out) throws IOException { out.writeUTF(getValueClass().getName()); Writable[] writables = get(); // handle null - ArrayWritable does not if (writables == null) { out.writeInt(0); } else { super.write(out); } } }
return new WritableArrayWritable(arrayType);
@Override public void write(DataOutput out) throws IOException { out.writeUTF(getValueClass().getName()); Writable[] writables = get(); // handle null - ArrayWritable does not if (writables == null) { out.writeInt(0); } else { super.write(out); } } }
return new WritableArrayWritable(arrayType);
@Override public void write(DataOutput out) throws IOException { out.writeUTF(getValueClass().getName()); Writable[] writables = get(); // handle null - ArrayWritable does not if (writables == null) { out.writeInt(0); } else { super.write(out); } } }
return new WritableArrayWritable(arrayType);