Dataset implements Writable { @Override public void write(DataOutput out) throws IOException { out.writeInt(attributes.length); for (Attribute attr : attributes) { WritableUtils.writeString(out, attr.name()); } WritableUtils.writeStringArray(out, labels); DFUtils.writeArray(out, ignored); for (String[] vals : values) { if (vals != null) { WritableUtils.writeStringArray(out, vals); } } out.writeInt(labelId); out.writeInt(nbInstances); } private  Dataset(); protected  Dataset(Attribute[] attrs, List<String>[] values, int nbInstances); String[] labels(); int nblabels(); int getLabelId(); int nbInstances(); int labelCode(String label); String getLabel(int code); int valueOf(int attr, String token); int[] getIgnored(); int nbAttributes(); boolean isNumerical(int attr); @Override boolean equals(Object obj); @Override int hashCode(); static Dataset load(Configuration conf, Path path); static Dataset read(DataInput in); @Override void readFields(DataInput in); @Override void write(DataOutput out);  }
@Test public void testWritable() throws Exception { Random rng = RandomUtils.getRandom(); ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); DataOutput out = new DataOutputStream(byteOutStream); int n = 10; for (int nloop = 0; nloop < n; nloop++) { byteOutStream.reset(); Dataset dataset = Utils.randomData(rng, NUM_ATTRIBUTES, 1).getDataset(); dataset.write(out); assertEquals(dataset, readDataset(byteOutStream.toByteArray())); } }