Platform independent line counting, compatibile with JDK LineNumberReader.java