Custom query result formatting

This adds interfaces for query output formatting. And provides implementations for writing into files, with custom format specified. 
As explained in the previous comment, commit is when all writes succeed, we will be commititng the formatting. Close is for resource cleanup. Will update the same in javadoc