import java.io.*; import java.text.*; final class Util { private final static Util instance = new Util(); public static Util getInstance() {return instance;} private final static NumberFormat nf = NumberFormat.getInstance(); static { nf.setMaximumFractionDigits(2); } void log(String s) { System.err.println("*** " + s); System.err.flush(); } void handle(String msg, Throwable e) { log(msg); e.printStackTrace(); } void handle(Throwable e) { handle(e == null ? null : e.getMessage(),e); } String niceSize(File f) { return f == null ? null : niceSize(f.length()); } String niceSize(long len) { if (len > 1e10) { return nf.format(len/1e10) + " GB"; } if (len > 1e7) { return nf.format(len/1e7) + " MB"; } if (len > 1e4) { return nf.format(len/1e5) + " KB"; } return len + " bytes"; } String getExtension(File f) { String path = f.getAbsolutePath(); int ilastDot = path.lastIndexOf('.'); if (ilastDot == -1) { return null; } String ext = path.substring(ilastDot+1).toLowerCase(); return ext; } }