List of usage examples for java.lang System getProperties
public static Properties getProperties()
From source file:ntpgraphic.LineChart.java
public static void NTPClient(String[] servers, int i) { Properties defaultProps = System.getProperties(); //obtiene las "properties" del sistema defaultProps.put("java.net.preferIPv6Addresses", "true");//mapea el valor true en la variable java.net.preferIPv6Addresses if (servers.length == 0) { System.err.println("Usage: NTPClient <hostname-or-address-list>"); System.exit(1);//from w ww .jav a 2 s .c o m } Promedio = 0; Cant = 0; NTPUDPClient client = new NTPUDPClient(); // We want to timeout if a response takes longer than 10 seconds client.setDefaultTimeout(10000); try { client.open(); for (String arg : servers) { System.out.println(); try { InetAddress hostAddr = InetAddress.getByName(arg); System.out.println("> " + hostAddr.getHostName() + "/" + hostAddr.getHostAddress()); TimeInfo info = client.getTime(hostAddr); processResponse(info, i); } catch (IOException ioe) { System.err.println(ioe.toString()); } } } catch (SocketException e) { System.err.println(e.toString()); } client.close(); //System.out.println("\n Pomedio "+(Promedio/Cant)); }
From source file:gov.nasa.ensemble.common.CommonPlugin.java
/** * Checks whether the 'junit.isRunning' property is set to "true". If not, then it checks the 'eclipse.application' property to * test whether the application currently running has "testapplication" is its name. If yes, it returns true. Else, returns * false.// ww w .j a v a 2 s .c o m * * NOTE: Bamboo sets the 'junit.isRunning' property before all of its test cases. And when developers run a test case as a * "JUnit Plug-in Test" the application will include "testapplication" in the name. If the test case is run as "JUnit Test", * this method will not be reliable. * * @return boolean */ public static boolean isJunitRunning() { Properties p = System.getProperties(); // debug // for(Object obj : p.keySet()) { // String prop = (String) obj; // System.out.println(prop + " : " + p.getProperty(prop)); // } // cruise control sets this property when running test cases String junit = p.getProperty(JUNIT_IS_RUNNING_PROPERTY, "false"); if (junit.equals("true")) return true; // when running test cases from the GUI, one of the following two // properties will most likely be set (depending upon your Eclipse // version). This heuristic may have to be updated as new Eclipse // versions come on line and change their running property set // Eclipse 3.1 String app = p.getProperty(ECLIPSE_APPLICATION_PROPERTY, ""); if (app.contains("testapplication")) return true; // Eclipse 3.2 String cmds = p.getProperty(ECLIPSE_COMMANDS_PROPERTY, ""); if (cmds.contains("junit") && cmds.contains("testapplication")) return true; if (cmds.contains("EnsembleTestRunner")) return true; // didn't find any of the properties we were looking for so the only // conclusion at this point is that we are not in a test case return false; }
From source file:com.egt.core.util.Utils.java
private static String getQuote() { return System.getProperties().getProperty("path.separator").equals(";") ? DOUBLE_QUOTE : SINGLE_QUOTE; }
From source file:ch.cyberduck.core.cryptomator.DAVReadFeatureTest.java
@Test public void testReadRange() throws Exception { final Host host = new Host(new DAVProtocol(), "test.cyberduck.ch", new Credentials(System.getProperties().getProperty("webdav.user"), System.getProperties().getProperty("webdav.password"))); host.setDefaultPath("/dav/basic"); final DAVSession session = new DAVSession(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final TransferStatus status = new TransferStatus(); final int length = 140000; final byte[] content = RandomUtils.nextBytes(length); status.setLength(content.length);/*from ww w . j ava2 s. c om*/ final Path home = new DefaultHomeFinderService(session).find(); final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore()); cryptomator.create(session, null, new VaultCredentials("test")); session.withRegistry( new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); final CryptoWriteFeature<String> writer = new CryptoWriteFeature<>(session, new DAVWriteFeature(session), cryptomator); final Cryptor cryptor = cryptomator.getCryptor(); final FileHeader header = cryptor.fileHeaderCryptor().create(); status.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header)); status.setNonces(new RandomNonceGenerator()); status.setChecksum(writer.checksum(test).compute(new ByteArrayInputStream(content), status)); final OutputStream out = writer.write(test, status, new DisabledConnectionCallback()); assertNotNull(out); new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out); out.close(); assertTrue(new CryptoFindFeature(session, new DAVFindFeature(session), cryptomator).find(test)); Assert.assertEquals(content.length, new CryptoListService(session, session, cryptomator) .list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize()); Assert.assertEquals(content.length, writer.append(test, status.getLength(), PathCache.empty()).size, 0L); { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(40000); final TransferStatus read = new TransferStatus(); read.setOffset(23); // offset within chunk read.setAppend(true); read.length(40000); // ensure to read at least two chunks final InputStream in = new CryptoReadFeature(session, new DAVReadFeature(session), cryptomator) .read(test, read, new DisabledConnectionCallback()); new StreamCopier(read, read).withLimit(40000L).transfer(in, buffer); final byte[] reference = new byte[40000]; System.arraycopy(content, 23, reference, 0, reference.length); assertArrayEquals(reference, buffer.toByteArray()); } { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(40000); final TransferStatus read = new TransferStatus(); read.setOffset(65536); // offset at the beginning of a new chunk read.setAppend(true); read.length(40000); // ensure to read at least two chunks final InputStream in = new CryptoReadFeature(session, new DAVReadFeature(session), cryptomator) .read(test, read, new DisabledConnectionCallback()); new StreamCopier(read, read).withLimit(40000L).transfer(in, buffer); final byte[] reference = new byte[40000]; System.arraycopy(content, 65536, reference, 0, reference.length); assertArrayEquals(reference, buffer.toByteArray()); } { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(40000); final TransferStatus read = new TransferStatus(); read.setOffset(65537); // offset at the beginning+1 of a new chunk read.setAppend(true); read.length(40000); // ensure to read at least two chunks final InputStream in = new CryptoReadFeature(session, new DAVReadFeature(session), cryptomator) .read(test, read, new DisabledConnectionCallback()); new StreamCopier(read, read).withLimit(40000L).transfer(in, buffer); final byte[] reference = new byte[40000]; System.arraycopy(content, 65537, reference, 0, reference.length); assertArrayEquals(reference, buffer.toByteArray()); } new CryptoDeleteFeature(session, new DAVDeleteFeature(session), cryptomator) .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:io.servicecomb.config.archaius.sources.TestYAMLConfigurationSource.java
@Test public void testPullFroGivenURL() throws Exception { ClassLoader loader = Thread.currentThread().getContextClassLoader(); URL test1URL = loader.getResource("test1.yaml"); URL test2URL = loader.getResource("test2.yaml"); System.setProperty("cse.configurationSource.additionalUrls", test1URL.toString() + "," + test2URL.toString()); MicroserviceConfigurationSource configSource = yamlConfigSource(); PollResult result = configSource.poll(true, null); Map<String, Object> configMap = result.getComplete(); assertEquals(3, configSource.getConfigModels().size()); assertNotNull(configMap);/*from ww w . j a va2 s. c o m*/ assertEquals(31, configMap.size()); assertNotNull(configMap.get("trace.handler.sampler.percent")); assertEquals(0.5, configMap.get("trace.handler.sampler.percent")); System.getProperties().remove("cse.configurationSource.additionalUrls"); }
From source file:ch.cyberduck.core.cryptomator.SFTPMoveFeatureTest.java
@Test public void testMoveSameFolderCryptomator() throws Exception { final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch", new Credentials(System.getProperties().getProperty("sftp.user"), System.getProperties().getProperty("sftp.password"))); final SFTPSession session = new SFTPSession(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path home = new SFTPHomeDirectoryService(session).find(); final Path vault = new Path(home, UUID.randomUUID().toString(), EnumSet.of(Path.Type.directory)); final Path source = new Path(vault, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final Path target = new Path(vault, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore()); cryptomator.create(session, null, new VaultCredentials("test")); session.withRegistry(// w w w . j av a2 s. com new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); new CryptoTouchFeature<Void>(session, new DefaultTouchFeature<Void>(new DefaultUploadFeature<Void>(new SFTPWriteFeature(session))), new SFTPWriteFeature(session), cryptomator).touch(source, new TransferStatus()); assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source)); new CryptoMoveFeature(session, new SFTPMoveFeature(session), new SFTPDeleteFeature(session), cryptomator) .move(source, target, new TransferStatus(), new Delete.Callback() { @Override public void delete(final Path file) { // } }, new DisabledConnectionCallback()); assertFalse(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source)); assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(target)); new CryptoDeleteFeature(session, new SFTPDeleteFeature(session), cryptomator) .delete(Arrays.asList(target, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:com.heraldapp.share.facebook.Util.java
/** * Connect to an HTTP URL and return the response as a string. * // w w w . j a v a2 s.c om * Note that the HTTP method override is used on non-GET requests. (i.e. * requests are made as "POST" with method specified in the body). * * @param url * - the resource to open: must be a welformed URL * @param method * - the HTTP method to use ("GET", "POST", etc.) * @param params * - the query parameter for the URL (e.g. access_token=foo) * @return the URL contents as a String * @throws MalformedURLException * - if the URL format is invalid * @throws IOException * - if a network problem occurs */ public static String openUrl(String url, String method, Bundle params) throws MalformedURLException, IOException { if (method.equals("GET")) { url = url + "?" + encodeUrl(params); } String response = ""; HttpURLConnection conn = null; try { conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestProperty("User-Agent", System.getProperties().getProperty("http.agent") + " FacebookAndroidSDK"); conn.setReadTimeout(10000); conn.setConnectTimeout(10000); if (!method.equals("GET")) { // use method override params.putString("method", method); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.getOutputStream().write(encodeUrl(params).getBytes("UTF-8")); } response = read(conn.getInputStream()); } catch (FileNotFoundException e) { // Error Stream contains JSON that we can parse to a FB error response = read(conn.getErrorStream()); } catch (SocketTimeoutException e) { return response; } return response; }
From source file:com.weaverplatform.nifi.XmiImporterTest.java
@Before public void init() throws URISyntaxException { // Wipe weaver database first weaver = new Weaver(); weaver.connect(new WeaverSocket(new URI(WEAVER_URL))); weaver.wipe();// w w w . j a v a 2s. c om System.out .println(new File(getClass().getClassLoader().getResource("nifi.properties").getFile()).toString()); Properties props = System.getProperties(); props.setProperty("nifi.properties.file.path", new File(getClass().getClassLoader().getResource("nifi.properties").getFile()).toString()); testRunner = TestRunners.newTestRunner(XmiImporter.class); }
From source file:ch.cyberduck.core.cryptomator.SwiftWriteFeatureTest.java
@Test public void testWrite() throws Exception { final Host host = new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com", new Credentials(System.getProperties().getProperty("rackspace.key"), System.getProperties().getProperty("rackspace.secret"))); final SwiftSession session = new SwiftSession(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final TransferStatus status = new TransferStatus(); final int length = 1048576; final byte[] content = RandomUtils.nextBytes(length); status.setLength(content.length);//from w ww .j av a 2s . co m final Path home = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.volume, Path.Type.directory)); home.attributes().setRegion("DFW"); final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore()); cryptomator.create(session, null, new VaultCredentials("test")); session.withRegistry( new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); final CryptoWriteFeature<StorageObject> writer = new CryptoWriteFeature<StorageObject>(session, new SwiftWriteFeature(session, new SwiftRegionService(session)), cryptomator); final Cryptor cryptor = cryptomator.getCryptor(); final FileHeader header = cryptor.fileHeaderCryptor().create(); status.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header)); status.setNonces(new RotatingNonceGenerator(cryptomator.numberOfChunks(content.length))); status.setChecksum(writer.checksum(test).compute(new ByteArrayInputStream(content), status)); final OutputStream out = writer.write(test, status, new DisabledConnectionCallback()); assertNotNull(out); new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out); out.close(); assertTrue(new CryptoFindFeature(session, new SwiftFindFeature(session), cryptomator).find(test)); assertEquals(content.length, new CryptoListService(session, session, cryptomator) .list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize()); assertEquals(content.length, writer.append(test, status.getLength(), PathCache.empty()).size, 0L); final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length); final InputStream in = new CryptoReadFeature(session, new SwiftReadFeature(session, new SwiftRegionService(session)), cryptomator).read(test, new TransferStatus().length(content.length), new DisabledConnectionCallback()); new StreamCopier(status, status).transfer(in, buffer); assertArrayEquals(content, buffer.toByteArray()); new CryptoDeleteFeature(session, new SwiftDeleteFeature(session), cryptomator) .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:dk.dma.msiproxy.common.settings.Settings.java
/** * Returns the value associated with the setting. * If it does not exist, it is created/* ww w .j av a 2 s . co m*/ * * @param setting the source * @return the associated value */ public String get(Setting setting) { Objects.requireNonNull(setting, "Must specify valid setting"); String result; // If a corresponding system property is set, it takes precedence result = System.getProperty(setting.getSettingName()); // Check if it has been defined in the properties file if (result == null) { result = properties.getProperty(setting.getSettingName(), setting.defaultValue()); } if (result != null && setting.substituteSystemProperties()) { for (Object key : System.getProperties().keySet()) { result = result.replaceAll("\\$\\{" + key + "\\}", Matcher.quoteReplacement(System.getProperty("" + key))); } } return result; }