public static void withEncoding(@NotNull String encoding, @NotNull ThrowableRunnable r) { Charset oldCharset = Charset.defaultCharset(); try { try { patchSystemFileEncoding(encoding); r.run(); } finally { patchSystemFileEncoding(oldCharset.name()); } } catch (Throwable t) { throw new RuntimeException(t); } }