sync tool rewrite to java (prototype)