With awk:
awk '{ORS=" ";}; !NF{ORS="\n"};1' file
The ORS variable specifies the output record separator. If the line number of fields is zero (the line is empty) then the record separator should be a newline, else a space. The 1 at the end just means a positive condition, so awk prints the whole line.