List of usage examples for java.util Properties load
public synchronized void load(InputStream inStream) throws IOException
From source file:com.magnet.mmx.server.plugin.mmxmgmt.interceptor.MessageDistributorImplTest.java
@BeforeClass public static void setup() throws Exception { InputStream inputStream = DeviceDAOImplTest.class.getResourceAsStream("/test.properties"); Properties testProperties = new Properties(); testProperties.load(inputStream); String host = testProperties.getProperty("db.host"); String port = testProperties.getProperty("db.port"); String user = testProperties.getProperty("db.user"); String password = testProperties.getProperty("db.password"); String driver = testProperties.getProperty("db.driver"); String schema = testProperties.getProperty("db.schema"); String url = "jdbc:mysql://" + host + ":" + port + "/" + schema; ds = new BasicDataSource(); ds.setDriverClassName(driver);//from ww w.j a v a 2 s . co m ds.setUsername(user); ds.setPassword(password); ds.setUrl(url); //clean any existing records and load some records into the database. FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder(); builder.setColumnSensing(true); Connection setup = ds.getConnection(); IDatabaseConnection con = new DatabaseConnection(setup); { InputStream xmlInput = DeviceDAOImplTest.class.getResourceAsStream("/data/app-data-1.xml"); IDataSet dataSet = builder.build(xmlInput); DatabaseOperation.CLEAN_INSERT.execute(con, dataSet); } { InputStream xmlInput = DeviceDAOImplTest.class.getResourceAsStream("/data/device-data-1.xml"); IDataSet dataSet = builder.build(xmlInput); DatabaseOperation.CLEAN_INSERT.execute(con, dataSet); } }
From source file:application.gen.gen.java
public static void genFile(List<Table> tableList) { Properties pros = new Properties(); try {//from w w w. ja v a 2 s. c o m pros.load(new FileInputStream("RelicConfig" + File.separator + "velocity.properties")); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { System.out.println("cant found the velocity.properties"); e.printStackTrace(); } Velocity.init(pros); VelocityContext context = new VelocityContext(); for (application.bean.Template tem : Context.templateList.getTemplates()) { for (Table table : tableList) { if (table.getDbType().equalsIgnoreCase(tem.getDbType())) { context.put("cDir", Context.cDir); context.put("schemaName", "main"); context.put("proName", tem.getNamePre() + table.getTABLE_NAMEFU() + tem.getNameSuf().replace(".sql", "")); context.put("tableName", table.getTABLE_NAME()); context.put("tableNameFU", table.getTABLE_NAMEFU()); context.put("tableNameFL", table.getTABLE_NAMEFL()); context.put("columns", table.getColumns()); context.put("table", table); gen(context, tem.getTemplatePath(), tem.getGenDir() + tem.getNamePre() + table.getTABLE_NAMEFU() + tem.getNameSuf()); } } } }
From source file:com.github.tddts.jet.util.Util.java
/** * Save given property to given propeorty file. * * @param fileName property file path/*from w ww . j av a2s . c o m*/ * @param key property key * @param value property value */ public static void saveProperty(String fileName, String key, String value) { try { File file = new File(fileName); if (!file.exists()) file.createNewFile(); Properties properties = new Properties(); try (InputStream in = FileUtils.openInputStream(file)) { properties.load(in); } properties.setProperty(key, value); try (OutputStream out = FileUtils.openOutputStream(file)) { properties.store(out, ""); } } catch (IOException e) { throw new ApplicationException(e); } }
From source file:com.weaverplatform.nifi.CreateIndividualTest.java
@BeforeClass public static void beforeClass() throws IOException { // Define property file for NiFi Properties props = System.getProperties(); props.setProperty("nifi.properties.file.path", Resources.getResource("nifi.properties").getPath()); // Read test properties Properties testProperties = new Properties(); testProperties.load(Resources.getResource("test.properties").openStream()); WEAVER_URL = testProperties.get("weaver.url").toString(); WEAVER_DATASET = testProperties.get("weaver.global.dataset").toString(); // Set Nifi Weaver properties NiFiProperties.getInstance().put(WeaverProperties.URL, WEAVER_URL); NiFiProperties.getInstance().put(WeaverProperties.DATASET, WEAVER_DATASET); }
From source file:com.liferay.portal.test.TestUtil.java
public static List<String> getPortletConfigLocations(String portletName) throws Exception { String basePath = getFullBasePath(); String docrootPath = "/portlets/" + portletName + "/docroot/"; String path = basePath + docrootPath + "WEB-INF/src/service.properties"; Properties props = new Properties(); FileInputStream fis = new FileInputStream(path); props.load(fis); String springConfigs = props.getProperty("spring.configs"); String[] configs = com.liferay.portal.kernel.util.StringUtil.split(springConfigs, ","); List<String> configLocations = new ArrayList<String>(); for (int i = 0; i < configs.length; i++) { String config = configs[i]; String fullPath = docrootPath + config; //Only include files which are actually present, e.g. ext-spring.xml // isn't required to be there but is automatically included in the spring.configs if (FileUtil.exists(basePath + fullPath)) { _log.info("Including config file: " + fullPath); configLocations.add(fullPath); }/*from w ww .j a v a 2 s . c o m*/ } //Also add in the test xml if present String testPath = docrootPath + "WEB-INF/classes/META-INF/ext-spring-test.xml"; if (FileUtil.exists(basePath + testPath)) { configLocations.add(testPath); } return configLocations; }
From source file:net.centro.rtb.monitoringcenter.infos.AppInfo.java
public static AppInfo create(String applicationName) { Preconditions.checkNotNull(applicationName); AppInfo appInfo = new AppInfo(); appInfo.applicationName = applicationName; Properties properties = new Properties(); try {/*from w w w . ja v a2s .com*/ properties.load(AppInfo.class.getResourceAsStream(BUILD_INFO_PROPERTIES_FILE)); } catch (Exception e) { logger.debug("Error loading the buildInfo file from the classpath: {}", BUILD_INFO_PROPERTIES_FILE, e); if (InterruptedException.class.isInstance(e)) { Thread.currentThread().interrupt(); } return appInfo; } appInfo.applicationVersion = StringUtils.trimToNull(properties.getProperty("build.version")); appInfo.buildTimestamp = parseDate(properties.getProperty("build.timestamp")); appInfo.buildUsername = StringUtils.trimToNull(properties.getProperty("build.username")); appInfo.branchName = StringUtils.trimToNull(properties.getProperty("vcs.branch")); appInfo.commitId = StringUtils.trimToNull(properties.getProperty("vcs.commit.id")); appInfo.commitMessage = StringUtils.trimToNull(properties.getProperty("vcs.commit.message")); appInfo.commitTimestamp = parseDate(properties.getProperty("vcs.commit.timestamp")); appInfo.commitAuthor = StringUtils.trimToNull(properties.getProperty("vcs.commit.author")); return appInfo; }
From source file:com.ict.dtube.filtersrv.FiltersrvStartup.java
public static FiltersrvController main0(String[] args) { System.setProperty(RemotingCommand.RemotingVersionKey, Integer.toString(MQVersion.CurrentVersion)); // Socket???/*w w w .j a va 2 s .c o m*/ if (null == System.getProperty(NettySystemConfig.SystemPropertySocketSndbufSize)) { NettySystemConfig.SocketSndbufSize = 65535; } // Socket? if (null == System.getProperty(NettySystemConfig.SystemPropertySocketRcvbufSize)) { NettySystemConfig.SocketRcvbufSize = 1024; } try { // ? Options options = ServerUtil.buildCommandlineOptions(new Options()); final CommandLine commandLine = ServerUtil.parseCmdLine("mqfiltersrv", args, buildCommandlineOptions(options), new PosixParser()); if (null == commandLine) { System.exit(-1); return null; } // ?? final FiltersrvConfig filtersrvConfig = new FiltersrvConfig(); final NettyServerConfig nettyServerConfig = new NettyServerConfig(); if (commandLine.hasOption('c')) { String file = commandLine.getOptionValue('c'); if (file != null) { InputStream in = new BufferedInputStream(new FileInputStream(file)); Properties properties = new Properties(); properties.load(in); MixAll.properties2Object(properties, filtersrvConfig); System.out.println("load config properties file OK, " + file); in.close(); String port = properties.getProperty("listenPort"); if (port != null) { filtersrvConfig.setConnectWhichBroker(String.format("127.0.0.1:%s", port)); } } } // 0??? nettyServerConfig.setListenPort(0); nettyServerConfig.setServerAsyncSemaphoreValue(filtersrvConfig.getFsServerAsyncSemaphoreValue()); nettyServerConfig .setServerCallbackExecutorThreads(filtersrvConfig.getFsServerCallbackExecutorThreads()); nettyServerConfig.setServerWorkerThreads(filtersrvConfig.getFsServerWorkerThreads()); // ?? if (commandLine.hasOption('p')) { MixAll.printObjectProperties(null, filtersrvConfig); MixAll.printObjectProperties(null, nettyServerConfig); System.exit(0); } MixAll.properties2Object(ServerUtil.commandLine2Properties(commandLine), filtersrvConfig); if (null == filtersrvConfig.getDtubeHome()) { System.out.println("Please set the " + MixAll.DTUBE_HOME_ENV + " variable in your environment to match the location of the Dtube installation"); System.exit(-2); } // ?Logback LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); lc.reset(); configurator.doConfigure(filtersrvConfig.getDtubeHome() + "/conf/logback_filtersrv.xml"); final Logger log = LoggerFactory.getLogger(LoggerName.FiltersrvLoggerName); // ?? final FiltersrvController controller = new FiltersrvController(filtersrvConfig, nettyServerConfig); boolean initResult = controller.initialize(); if (!initResult) { controller.shutdown(); System.exit(-3); } Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { private volatile boolean hasShutdown = false; private AtomicInteger shutdownTimes = new AtomicInteger(0); @Override public void run() { synchronized (this) { log.info("shutdown hook was invoked, " + this.shutdownTimes.incrementAndGet()); if (!this.hasShutdown) { this.hasShutdown = true; long begineTime = System.currentTimeMillis(); controller.shutdown(); long consumingTimeTotal = System.currentTimeMillis() - begineTime; log.info("shutdown hook over, consuming time total(ms): " + consumingTimeTotal); } } } }, "ShutdownHook")); // ?? controller.start(); String tip = "The Filter Server boot success, " + controller.localAddr(); log.info(tip); System.out.println(tip); return controller; } catch (Throwable e) { e.printStackTrace(); System.exit(-1); } return null; }
From source file:com.ignorelist.kassandra.steam.scraper.Configuration.java
public static Configuration fromPropertiesFile(Path propertiesFile) throws IOException { Reader propertiesReader = Files.newBufferedReader(propertiesFile, Charsets.UTF_8); try {/*w ww .j ava2s .com*/ Properties properties = new Properties(); properties.load(propertiesReader); return fromProperties(properties); } finally { IOUtils.closeQuietly(propertiesReader); } }
From source file:com.webkruscht.wmt.DownloadFiles.java
private static void getProperties() throws IOException { Properties p = new Properties(); String propFile = "wmt.properties"; InputStream propStream = DownloadFiles.class.getClassLoader().getResourceAsStream(propFile); p.load(propStream); propStream.close();//from w w w .j a v a 2s . c o m username = p.getProperty("username"); password = p.getProperty("password"); filePath = p.getProperty("filePath"); }
From source file:controllers.FormsController.java
private static Properties getPropertyFile() { Properties properties = new Properties(); InputStream stream = Play.application().classloader().getResourceAsStream("forms_en.properties"); try {/*from w w w.j a v a 2s. c o m*/ properties.load(stream); stream.close(); return properties; } catch (FileNotFoundException ex) { Logger.getLogger(FormsController.class.getName()).log(Level.SEVERE, null, ex); return null; } catch (IOException ex) { Logger.getLogger(FormsController.class.getName()).log(Level.SEVERE, null, ex); return null; } finally { try { stream.close(); } catch (IOException ex) { Logger.getLogger(FormsController.class.getName()).log(Level.SEVERE, null, ex); } } }