本文整理匯總了Java中java.util.Properties類的典型用法代碼示例。如果您正苦於以下問題:Java Properties類的具體用法?Java Properties怎麽用?Java Properties使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Properties類屬於java.util包,在下文中一共展示了Properties類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: makeURLParameters
import java.util.Properties; //導入依賴的package包/類
public static String makeURLParameters(final Properties params) {
final StringBuffer result = new StringBuffer(100);
if (!params.isEmpty()) {
boolean first = true;
final Set set = params.entrySet();
for (final Iterator i = set.iterator(); i.hasNext(); ) {
final Map.Entry entry = (Map.Entry) i.next();
if (first) {
result.append('?');
first = false;
} else {
result.append('&');
}
result.append((String) entry.getKey());
result.append('=');
result.append((String) entry.getValue());
}
}
return result.toString();
}
示例2: Database
import java.util.Properties; //導入依賴的package包/類
public Database() throws FileNotFoundException, IOException {
Properties properties = new Properties();
properties.load(new FileInputStream("src/main/resources/database.properties"));
username = properties.getProperty("username");
password = properties.getProperty("password");
hostname = properties.getProperty("url");
database = properties.getProperty("name");
port = properties.getProperty("port");
}
示例3: goal
import java.util.Properties; //導入依賴的package包/類
private static Goal goal(Class<? extends Goal> goalClass) throws Exception {
Properties props = CruiseControlUnitTestUtils.getCruiseControlProperties();
props.setProperty(KafkaCruiseControlConfig.MAX_REPLICAS_PER_BROKER_CONFIG, Long.toString(1L));
BalancingConstraint balancingConstraint = new BalancingConstraint(new KafkaCruiseControlConfig(props));
balancingConstraint.setBalancePercentage(TestConstants.LOW_BALANCE_PERCENTAGE);
balancingConstraint.setCapacityThreshold(TestConstants.MEDIUM_CAPACITY_THRESHOLD);
try {
Constructor<? extends Goal> constructor = goalClass.getDeclaredConstructor(BalancingConstraint.class);
constructor.setAccessible(true);
return constructor.newInstance(balancingConstraint);
} catch (NoSuchMethodException badConstructor) {
//Try default constructor
return goalClass.newInstance();
}
}
示例4: testBug10630
import java.util.Properties; //導入依賴的package包/類
/**
* Tests fix for BUG#10630, Statement.getWarnings() fails with NPE if
* statement has been closed.
*/
public void testBug10630() throws Exception {
Connection conn2 = null;
Statement stmt2 = null;
try {
conn2 = getConnectionWithProps((Properties) null);
stmt2 = conn2.createStatement();
conn2.close();
stmt2.getWarnings();
fail("Should've caught an exception here");
} catch (SQLException sqlEx) {
assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, sqlEx.getSQLState());
} finally {
if (stmt2 != null) {
stmt2.close();
}
if (conn2 != null) {
conn2.close();
}
}
}
示例5: getLoaderData
import java.util.Properties; //導入依賴的package包/類
private LoaderData getLoaderData(Path rootPath) {
String os = getOS();
try {
Path inputPath = rootPath.resolve("manifest.properties");
Properties prop = new Properties();
prop.load(Files.newInputStream(inputPath));
String mainClass = prop.getProperty("main");
String classPath = prop.getProperty(os);
if(classPath == null)
throw error("Your system configuration ("+os+") is not supported in this build.", null);
return new LoaderData(mainClass, classPath.split(":"));
} catch (Exception e) {
throw error("Could not load library manifest.", e);
}
}
示例6: createPool
import java.util.Properties; //導入依賴的package包/類
public static void createPool(PoolAttributes poolAttr) throws Exception {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
DistributedSystem ds = new CacheServerTestUtil().getSystem(props);;
PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory();
pf.init(poolAttr);
PoolImpl p = (PoolImpl) pf.create("CacheServerTestUtil");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setPoolName(p.getName());
RegionAttributes attrs = factory.create();
pool = p;
}
示例7: testSendMail_invServer
import java.util.Properties; //導入依賴的package包/類
/**
* Execute send mail without a valid server.
*/
@Test(expected = MailOperationException.class)
public void testSendMail_invServer() throws Exception {
List<UserData> userData = new ArrayList<UserData>();
UserData ud = new UserData();
ud.email = testMailAddress;
ud.userid = "newid";
ud.olduserid = "oldid";
userData.add(ud);
Properties unProperties = getProperties(
getProperiesForComputerName(unPropertiesFilePath));
unProperties.setProperty(HandlerUtils.MAIL_SERVER, "invalidServer");
userNotification.sendMail(userData, unProperties);
}
示例8: loadServerParameters
import java.util.Properties; //導入依賴的package包/類
private ServerParameters loadServerParameters(Properties serverProperties) {
ServerParameters parameters = new ServerParameters();
parameters.setServerUrl(serverProperties.getProperty(SERVER_URL_PROPERTY));
parameters.setAuthPayload(serverProperties.getProperty(AUTHENTICATION_PROPERTY));
parameters.setAuthenticationUrl(serverProperties.getProperty(AUTHENTICATION_URL_PROPERTY));
parameters.setSearchUrl(serverProperties.getProperty(SEARCH_URL_PROPERTY));
parameters.setRegistrationUrl(serverProperties.getProperty(REGISTRATION_URL_PROPERTY));
parameters.setProjectLoadUrl(serverProperties.getProperty(PROJECT_URL_PROPERTY));
parameters.setProjectLoadByIdUrl(serverProperties.getProperty(PROJECT_URL_BY_ID_PROPERTY));
parameters.setFileFindUrl(serverProperties.getProperty(FIND_FILE_URL_PROPERTY));
parameters.setVersionUrl(serverProperties.getProperty(VERSION_URL_PROPERTY));
parameters.setMinSupportedServerVersion(
Integer.parseInt(serverProperties.getProperty(SERVER_VERSION_PROPERTY)));
parameters.setProjectTreeUrl(serverProperties.getProperty(PROJECT_TREE_URL_PROPERTY));
return parameters;
}
示例9: test
import java.util.Properties; //導入依賴的package包/類
@Test
public void test()
{
ConfigFactory.Instance().LoadProperties("/home/hank/Desktop/rainbow/rainbow-evaluate/rainbow.properties");
Properties params = new Properties();
params.setProperty("method", "PRESTO");
params.setProperty("format", "ORC");
params.setProperty("table.dir", "/rainbow2/orc");
params.setProperty("table.name", "orc");
params.setProperty("workload.file", "/home/hank/Desktop/rainbow/rainbow-evaluate/workload.txt");
params.setProperty("log.dir", "/home/hank/Desktop/rainbow/rainbow-evaluate/workload_eva/");
params.setProperty("drop.cache", "false");
Invoker invoker = new InvokerWorkloadEvaluation();
try
{
invoker.executeCommands(params);
} catch (InvokerException e)
{
e.printStackTrace();
}
}
示例10: configureAttachSettings
import java.util.Properties; //導入依賴的package包/類
private boolean configureAttachSettings(boolean partially) {
AttachSettings settings = AttachWizard.getDefault().configure(attachSettings, partially);
if (settings == null) return false; // cancelled by the user
attachSettings = settings;
final AttachSettings as = new AttachSettings();
attachSettings.copyInto(as);
final Lookup.Provider lp = session.getProject();
RequestProcessor.getDefault().post(new Runnable() {
public void run() {
Properties p = new Properties();
as.store(p);
try {
ProfilerStorage.saveProjectProperties(p, lp, "attach"); // NOI18N
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
});
return true;
}
示例11: setupConnection
import java.util.Properties; //導入依賴的package包/類
public Connection setupConnection(Connection connection, Properties properties) throws Exception {
InputStream is = SqlCommon.class.getClassLoader().getResourceAsStream("application.properties");
properties.load(is);
String user = String.valueOf(properties.get("sql-connector.user"));
String password = String.valueOf(properties.get("sql-connector.password"));
String url = String.valueOf(properties.get("sql-connector.url"));
System.out.println("Connecting to the database for unit tests");
try {
connection = DriverManager.getConnection(url,user,password);
} catch (Exception ex) {
fail("Exception during database startup.");
}
return connection;
}
示例12: configureLegacyPropertyComponents
import java.util.Properties; //導入依賴的package包/類
private void configureLegacyPropertyComponents() {
final Properties legacyProperties = LegacySettingsController.getLegacyProperties().orElse(new Properties());
initLegacySettings(legacyProperties);
fpsLimitSpinner.valueProperty().addListener(__ -> changeLegacyIntegerSetting(LegacySettingsController.FPS_LIMIT, fpsLimitSpinner.getValue()));
pageSizeSpinner.valueProperty().addListener(__ -> changeLegacyIntegerSetting(LegacySettingsController.PAGE_SIZE, pageSizeSpinner.getValue()));
multicoreCheckbox.setOnAction(__ -> changeLegacyBooleanSetting(LegacySettingsController.MULTICORE, multicoreCheckbox.isSelected()));
audioMsgCheckBox.setOnAction(__ -> changeLegacyBooleanSetting(LegacySettingsController.AUDIO_MESSAGE_OFF, !audioMsgCheckBox.isSelected()));
audioproxyCheckBox.setOnAction(__ -> changeLegacyBooleanSetting(LegacySettingsController.AUDIO_PROXY_OFF, !audioproxyCheckBox.isSelected()));
timestampsCheckBox.setOnAction(__ -> changeLegacyBooleanSetting(LegacySettingsController.TIMESTAMP, timestampsCheckBox.isSelected()));
headMoveCheckBox.setOnAction(__ -> changeLegacyBooleanSetting(LegacySettingsController.HEAD_MOVE, !headMoveCheckBox.isSelected()));
imeCheckBox.setOnAction(__ -> changeLegacyBooleanSetting(LegacySettingsController.IME, imeCheckBox.isSelected()));
directModeCheckBox.setOnAction(__ -> changeLegacyBooleanSetting(LegacySettingsController.DIRECT_MODE, directModeCheckBox.isSelected()));
nameTagStatusCheckBox.setOnAction(__ -> changeLegacyBooleanSetting(LegacySettingsController.NO_NAME_TAG_STATUS, !nameTagStatusCheckBox.isSelected()));
}
示例13: testSaveWithWriter
import java.util.Properties; //導入依賴的package包/類
public void testSaveWithWriter() throws IOException, ParserConfigurationException {
propertySet.setBoolean("testBoolean", true);
propertySet.setData("testData", "value1".getBytes());
propertySet.setDate("testDate", new Date());
propertySet.setDouble("testDouble", 10.245D);
propertySet.setInt("testInt", 7);
propertySet.setLong("testLong", 100000);
propertySet.setObject("testObject", new TestObject(1));
Properties props = new Properties();
props.setProperty("prop1", "value1");
propertySet.setProperties("testProperties", props);
propertySet.setString("testString", "value1");
propertySet.setText("testText", TEXT_VALUE);
StringWriter writer = new StringWriter();
((XMLPropertySet) propertySet).save(writer);
assertNotNull(writer.toString());
}
示例14: start
import java.util.Properties; //導入依賴的package包/類
@Override
public void start(Stage primaryStage) throws IOException {
/* 앱 버전 */
Properties prop = new Properties();
FileInputStream fis = new FileInputStream(Constants.SystemMessage.PROPERTY_PATH);
prop.load(new java.io.BufferedInputStream(fis));
String current = prop.getProperty(Constants.SystemMessage.PROPERTY_APP_KEY);
/* 업데이트 앱 버전 체크 */
ApplicationAPI api = new ApplicationAPI();
Map<String, String> result = api.appCheck();
String now = result.get("new_version");
if (current != null && now != null) {
if (!current.equals(now)) {
AlertSupport alert = new AlertSupport(Constants.AlertInfoMessage.VERSION_UPDATE_MESSAGE);
int c = alert.alertConfirm();
if (c == 1) {
Runtime runTime = Runtime.getRuntime();
try {
primaryStage.close();
runTime.exec(Constants.SystemMessage.UPDATE_APP_PATH);
} catch (IOException e) {
e.printStackTrace();
}
} else {
// 업데이트를 하지 않을 때
run(primaryStage, current);
}
} else {
// 최신버전일때
run(primaryStage, current);
}
}
}
示例15: bindProperties
import java.util.Properties; //導入依賴的package包/類
public static void bindProperties(Object object, Properties properties,
String prefix) {
if (properties == null) {
throw new IllegalArgumentException(
"there is no properties setting.");
}
logger.debug("prefix : {}", prefix);
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
String key = (String) entry.getKey();
String value = (String) entry.getValue();
if (!key.startsWith(prefix)) {
continue;
}
String propertyName = key.substring(prefix.length());
tryToSetProperty(object, propertyName, value);
}
}