Hamiltonian formulation of distributed-parameter systems with boundary energy flow