Java rewrite engine

@chathhorn please review