@Override @SuppressWarnings("unchecked") public Writable put(Writable key, Writable value) { addToMap(key.getClass()); addToMap(value.getClass()); return instance.put(key, value); }
/** * Make a copy of a writable object using serialization to a buffer. * * @param orig The object to copy * @return The copied object */ public static Writable clone(Writable orig, JobConf conf) { try { Writable newInst = (Writable) conf.newInstance(orig.getClass()); CopyInCopyOutBuffer buffer = (CopyInCopyOutBuffer) cloneBuffers.get(); buffer.outBuffer.reset(); orig.write(buffer.outBuffer); buffer.moveData(); newInst.readFields(buffer.inBuffer); return newInst; } catch (IOException e) { throw new RuntimeException("Error writing/reading clone buffer", e); } }
/** Utility method for testing writables. */ public static Writable testWritable(Writable before, Configuration conf) throws Exception { DataOutputBuffer dob = new DataOutputBuffer(); before.write(dob); DataInputBuffer dib = new DataInputBuffer(); dib.reset(dob.getData(), dob.getLength()); Writable after = (Writable) ReflectionUtils.newInstance(before.getClass(), conf); after.readFields(dib); assertEquals(before, after); return after; }