rewrite to java.nio