private static String versionString() { try { Properties prop = new Properties(); InputStream in = Main.class.getResourceAsStream("/okcurl-version.properties"); prop.load(in); in.close(); return prop.getProperty("version"); } catch (IOException e) { throw new AssertionError("Could not load okcurl-version.properties."); } }
@Override public Properties convert(String source) { try { Properties props = new Properties(); // Must use the ISO-8859-1 encoding because Properties.load(stream) expects it. props.load(new ByteArrayInputStream(source.getBytes(StandardCharsets.ISO_8859_1))); return props; } catch (Exception ex) { // Should never happen. throw new IllegalArgumentException("Failed to parse [" + source + "] into Properties", ex); } }
Properties properties = new Properties(); try { properties.load(new FileInputStream("path/filename")); } catch (IOException e) { ... }
public static Map<String, String> parseProperties(String content) throws IOException { Map<String, String> map = new HashMap<>(); if (StringUtils.isEmpty(content)) { logger.warn("You specified the config centre, but there's not even one single config item in it."); } else { Properties properties = new Properties(); properties.load(new StringReader(content)); properties.stringPropertyNames().forEach( k -> map.put(k, properties.getProperty(k)) ); } return map; }
private void loadProperties() { if (file != null && file.exists()) { InputStream in = null; try { in = new FileInputStream(file); properties.load(in); if (logger.isInfoEnabled()) { logger.info("Load registry cache file " + file + ", data: " + properties); } } catch (Throwable e) { logger.warn("Failed to load registry cache file " + file, e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { logger.warn(e.getMessage(), e); } } } } }
private static Properties fetchProperties(final String propertiesFilePath) { final Properties properties = new Properties(); InputStream is = null; try { is = FileUtils.openInputStream(new File(propertiesFilePath)); properties.load(is); } catch (Throwable cause) { // cause.printStackTrace(System.err); } finally { IOUtils.closeQuietly(is); } return properties; }
Properties prop = new Properties(); InputStream in = getClass().getResourceAsStream("foo.properties"); prop.load(in); in.close();
void loadProperties() { if (file != null && file.exists()) { try (InputStream in = new FileInputStream(file)) { properties.load(in); if (logger.isInfoEnabled()) { logger.info("Load service store file " + file + ", data: " + properties); } } catch (Throwable e) { logger.warn("Failed to load service store file " + file, e); } } }
Properties props = new Properties(); while (urls.hasMoreElements()) { URL url = urls.nextElement(); props.load(is); is.close();
private static void loadPersistedSettings( Properties settings, PartitionedIndexStorage indexStorage, FileSystemAbstraction fs ) { File settingsFile = new File( indexStorage.getIndexFolder(), INDEX_CONFIG_FILE ); if ( fs.fileExists( settingsFile ) ) { try ( Reader reader = fs.openAsReader( settingsFile, StandardCharsets.UTF_8 ) ) { settings.load( reader ); } catch ( IOException e ) { throw new UncheckedIOException( "Failed to read persisted fulltext index properties: " + settingsFile, e ); } } }
/** * Fill the given properties from the given resource (in ISO-8859-1 encoding). * @param props the Properties instance to fill * @param resource the resource to load from * @throws IOException if loading failed */ public static void fillProperties(Properties props, Resource resource) throws IOException { InputStream is = resource.getInputStream(); try { String filename = resource.getFilename(); if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) { props.loadFromXML(is); } else { props.load(is); } } finally { is.close(); } }
private static Properties readPropertiesFromFile (File propertiesFile) throws IOException { InputStream stream = null; try { stream = new FileInputStream(propertiesFile); Properties properties = new Properties(); properties.load(stream); return properties; } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { e.printStackTrace(); } } } }
public static Map<String, String> loadProperties(File file) throws IOException { Properties properties = new Properties(); try (InputStream in = new FileInputStream(file)) { properties.load(in); } return fromProperties(properties); } }
public static Map<String, String> parseProperties(String content) throws IOException { Map<String, String> map = new HashMap<>(); if (StringUtils.isEmpty(content)) { logger.warn("You specified the config centre, but there's not even one single config item in it."); } else { Properties properties = new Properties(); properties.load(new StringReader(content)); properties.stringPropertyNames().forEach( k -> map.put(k, properties.getProperty(k)) ); } return map; }
private void loadProperties() { if (file != null && file.exists()) { InputStream in = null; try { in = new FileInputStream(file); properties.load(in); if (logger.isInfoEnabled()) { logger.info("Load registry cache file " + file + ", data: " + properties); } } catch (Throwable e) { logger.warn("Failed to load registry cache file " + file, e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { logger.warn(e.getMessage(), e); } } } } }
@Test public void testClearCache() throws Exception { final DefaultConfiguration violationCheck = createModuleConfig(DummyFileSetViolationCheck.class); final DefaultConfiguration checkerConfig = new DefaultConfiguration("myConfig"); checkerConfig.addAttribute("charset", "UTF-8"); final File cacheFile = temporaryFolder.newFile(); checkerConfig.addAttribute("cacheFile", cacheFile.getPath()); checkerConfig.addChild(violationCheck); final Checker checker = new Checker(); checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader()); checker.configure(checkerConfig); checker.addListener(getBriefUtLogger()); checker.process(Collections.singletonList(new File("dummy.java"))); checker.clearCache(); // invoke destroy to persist cache final PropertyCacheFile cache = Whitebox.getInternalState(checker, "cacheFile"); cache.persist(); final Properties cacheAfterClear = new Properties(); cacheAfterClear.load(Files.newBufferedReader(cacheFile.toPath())); assertEquals("Cache has unexpected size", 1, cacheAfterClear.size()); }
static { Properties prop = new Properties(); InputStream in = CurrentClassName.class.getResourceAsStream("foo.properties"); prop.load(in); in.close() }
void loadProperties() { if (file != null && file.exists()) { try (InputStream in = new FileInputStream(file)) { properties.load(in); if (logger.isInfoEnabled()) { logger.info("Load service store file " + file + ", data: " + properties); } } catch (Throwable e) { logger.warn("Failed to load service store file " + file, e); } } }
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); InputStream input = classLoader.getResourceAsStream("foo.properties"); // ... Properties properties = new Properties(); properties.load(input);