public void write(DataOutput out) { try { Text.writeString(out, getKeyClass().getCanonicalName()); Text.writeString(out, getPersistentClass().getCanonicalName()); WritableUtils.writeProperties(out, properties); } catch (IOException e) { LOG.error(e.getMessage(), e); } }
@Test public void testWritesReads() throws Exception { Properties props = new Properties(); props.put("keyBlah", "valueBlah"); props.put("keyBlah2", "valueBlah2"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutput out = new DataOutputStream(bos); WritableUtils.writeProperties(out, props); ((DataOutputStream)out).flush(); DataInput in = new DataInputStream(new ByteArrayInputStream(bos.toByteArray())); Properties propsRead = WritableUtils.readProperties(in); assertEquals(propsRead.get("keyBlah"), props.get("keyBlah")); assertEquals(propsRead.get("keyBlah2"), props.get("keyBlah2")); } }
@SuppressWarnings("unchecked") public void readFields(DataInput in) { try { Class<K> keyClass = (Class<K>) ClassLoadingUtils.loadClass(Text.readString(in)); Class<T> persistentClass = (Class<T>)ClassLoadingUtils.loadClass(Text.readString(in)); Properties props = WritableUtils.readProperties(in); initialize(keyClass, persistentClass, props); } catch (ClassNotFoundException | IOException ex) { LOG.error(ex.getMessage(), ex); } }
@SuppressWarnings("unchecked") public void readFields(DataInput in) throws IOException { try { Class<K> keyClass = (Class<K>) ClassLoadingUtils.loadClass(Text.readString(in)); Class<T> persistentClass = (Class<T>)ClassLoadingUtils.loadClass(Text.readString(in)); Properties props = WritableUtils.readProperties(in); initialize(keyClass, persistentClass, props); } catch (ClassNotFoundException e) { LOG.error("ClassNotFoundException", e); throw new IOException(e); } }
public void write(DataOutput out) throws IOException { Text.writeString(out, getKeyClass().getCanonicalName()); Text.writeString(out, getPersistentClass().getCanonicalName()); WritableUtils.writeProperties(out, properties); }