You can use COPY JDBC API to copy to STDOUT and then compress it before you use usual Java file operations to write it to a file. You will have to follow the reverse process while reading from this file and LOADING to a table.
But why would you want to do that?
I guess this would be far faster, and maybe safer than CSVs
I don't think assumption is right. COPY is not meant for backup, it is for LOAD and UN-LOAD.
What you probably need is pg_dump with -Fc format.