Backported Java api from 0.2.2.