Description: | When a DataOutputStream instance wraps an underlying ByteArrayOutputStream instance,
it is recommended to flush or close the DataOutputStream before invoking the underlying instances's toByteArray(). Also, it is a good practice to call flush/close explicitly as mentioned for example here.
This pull request add a flush method before toByteArray. |
Code with Misuse: |
class TestWritableUtils { @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); 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")); }
}
|