>On the Java side, that means invoking PreparedStatement::setBinaryStream TWICE for the same data.
AFAIK, frontend-backend protocol allows to reuse $1 multiple times in the same query, so it seems to be indeed a bit efficient to use
values($1, $2, $3) on conflict.... set file_data=$1, file_name=$2
kind of query.
Obviously, you can use pl/pgsql procedure to workaround that. At least that would optimize network traffic.
AFAIK, JDBC references parameters by parameter position, so there's no implementation-independent way to reuse the same parameter without it sending it twice over the wire.