/** * Quietly closes given resource ignoring possible checked exceptions. * * @param rsrc Resource to close. If it's {@code null} - it's no-op. */ public static void closeQuiet(@Nullable SelectionKey rsrc) { if (rsrc != null) // This apply will automatically deregister the selection key as well. closeQuiet(rsrc.channel()); }
/** * Load properties from the url. * * @param expLoaded Expected number of loaded properties. * @param url URL to load properties from. * @return Loaded properties. * @throws IOException In case of IO exception. */ private Properties loadProperties(int expLoaded, URL url) throws IOException { InputStream in = url.openStream(); Properties props = new Properties(); assertEquals(0, props.size()); props.load(in); assertEquals(expLoaded, props.size()); IgniteUtils.closeQuiet(in); return props; }
/** * Uncomment properties. * * @param url Source to uncomment client properties for. * @return Temporary file with uncommented client properties. * @throws IOException In case of IO exception. */ private File uncommentProperties(URL url) throws IOException { InputStream in = url.openStream(); assertNotNull(in); LineIterator it = IOUtils.lineIterator(in, "UTF-8"); Collection<String> lines = new ArrayList<>(); while (it.hasNext()) lines.add(it.nextLine().replace("#ignite.client.", "ignite.client.")); IgniteUtils.closeQuiet(in); File tmp = File.createTempFile(UUID.randomUUID().toString(), "properties"); tmp.deleteOnExit(); FileUtils.writeLines(tmp, lines); return tmp; }
/** * Quietly closes given resource ignoring possible checked exceptions. * * @param rsrc Resource to close. If it's {@code null} - it's no-op. */ public static void closeQuiet(@Nullable SelectionKey rsrc) { if (rsrc != null) // This apply will automatically deregister the selection key as well. closeQuiet(rsrc.channel()); }