Example usage for java.lang System getProperties

List of usage examples for java.lang System getProperties

Introduction

In this page you can find the example usage for java.lang System getProperties.

Prototype

public static Properties getProperties() 

Source Link

Document

Determines the current system properties.

Usage

From source file:com.github.cmisbox.core.Config.java

private Config() {

    String osName = System.getProperty("os.name").toLowerCase();
    if (osName.equals("linux")) {
        this.os = OS.LINUX;
    } else if (osName.startsWith("windows")) {
        this.os = OS.WINDOWS;
    } else if (osName.startsWith("mac os x")) {
        this.os = OS.MACOSX;
    } else {/*ww w  .  java  2s.c  om*/
        throw new RuntimeException(Messages.unsupportedOs + ": " + osName);
    }

    String homePath = System.getProperty("user.home");
    if (this.os == OS.LINUX) {
        homePath += "/.cmisbox";
    } else if (this.os == OS.MACOSX) {
        homePath += "/Library/Application Support/CMISBox";
    } else if (this.os == OS.WINDOWS) {
        homePath = System.getenv("APPDATA") + "/CMISBox";
    }

    this.configHome = new File(homePath);
    if (!this.configHome.exists()) {
        this.configHome.mkdirs();
    }
    File logdir = new File(this.configHome, "logs");
    if (!logdir.exists()) {
        logdir.mkdirs();
    }

    System.getProperties().setProperty("cmisbox.home", this.configHome.getAbsolutePath());

    PropertyConfigurator.configure(this.getClass().getResource("log4j.properties"));
    this.log = LogFactory.getLog(this.getClass());

    this.properties = this.createDefaultProperties();

    try {
        File propertiesFile = new File(this.configHome, Config.PROPERTIES_FILE);
        if (!propertiesFile.exists()) {
            FileOutputStream out = new FileOutputStream(propertiesFile);
            this.properties.store(out, null);
            out.close();
        }

        this.properties.load(new FileInputStream(propertiesFile));

    } catch (IOException e) {

    }

    this.log.info(Messages.cmisBoxConfigHome + ": " + this.configHome);

    String watchParent = this.properties.getProperty(Config.WATCHPARENT);

    UI ui = UI.getInstance();
    while (watchParent == null) {
        if (ui.isAvailable()) {
            File f = ui.getWatchFolder();
            watchParent = f != null ? f.getAbsolutePath() : null;
            if (watchParent != null) {
                this.saveProperties();
                File box = new File(f, "Box");
                box.mkdirs();
                this.setWatchParent(box.getAbsolutePath());
            }
        } else {
            System.err.print(Messages.unableToLocateParent + ", " + Messages.pleaseInsertInProps);
            this.log.error(Messages.unableToLocateParent);
            Main.exit(1);
        }
    }

}

From source file:WebCrawler.java

public static void main(String argv[]) {
    Frame f = new Frame("WebFrame");
    WebCrawler applet = new WebCrawler();
    f.add("Center", applet);

    /*    Behind a firewall set your proxy and port here!
    *//*from  w w w  . ja  va  2s.  c  o m*/
    Properties props = new Properties(System.getProperties());
    props.put("http.proxySet", "true");
    props.put("http.proxyHost", "webcache-cup");
    props.put("http.proxyPort", "8080");

    Properties newprops = new Properties(props);
    System.setProperties(newprops);
    /**/

    applet.init();
    applet.start();
    f.pack();
    f.show();
}

From source file:com.aliyun.odps.mapred.conf.SessionState.java

private SessionState() {
    try {//from  www. j a va 2s.c  om
        aliases = new HashMap<String, String>();
        defaultJob = new JobConf(false);
        String conf = System.getProperties().getProperty(MR_JOB_CONF);
        if (conf != null && !conf.isEmpty()) {
            try {
                defaultJob.addResource(new FileInputStream(new File(conf)));
            } catch (FileNotFoundException e) {
                System.err.print("conf file " + conf + " not found, ignored!");
            }
        }
        parseOldCli(defaultJob); // Try to be compatible with old console
    } catch (AccessControlException e) {
        // just ignore it for it maybe called by user code indirectly through JobConf constructors 
    }
}

From source file:com.kamike.misc.FsUtils.java

public static void createDirectory(String dstPath) {

    Properties props = System.getProperties(); //    
    String osName = props.getProperty("os.name"); //???   
    Path newdir = FileSystems.getDefault().getPath(dstPath);

    boolean pathExists = Files.exists(newdir, new LinkOption[] { LinkOption.NOFOLLOW_LINKS });
    if (!pathExists) {
        Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxrwxrwx");
        FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(perms);
        try {/*ww w. j av a2 s .c  o  m*/
            if (!osName.contains("Windows")) {
                Files.createDirectories(newdir, attr);
            } else {
                Files.createDirectories(newdir);
            }
        } catch (Exception e) {
            System.err.println(e);

        }
    }
}

From source file:com.egt.core.util.Utils.java

public static String getAttachedFileName(URL url) {
    String sep = System.getProperties().getProperty("file.separator");
    String pdq = EA.getString(EAC.CONTENT_ROOT_DIR) + url.getPath();
    Bitacora.trace(pdq);/*from   w  ww .  jav a 2s .  c  o  m*/
    return pdq.replace('\\', '/').replace("/", sep);
}

From source file:psiprobe.controllers.system.SysInfoController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    SystemInformation systemInformation = new SystemInformation();
    systemInformation.setAppBase(getContainerWrapper().getTomcatContainer().getAppBase().getAbsolutePath());
    systemInformation.setConfigBase(getContainerWrapper().getTomcatContainer().getConfigBase());

    Map<String, String> sysProps = new HashMap<>();
    for (String propertyName : System.getProperties().stringPropertyNames()) {
        String propertyValue = System.getProperties().getProperty(propertyName);
        sysProps.put(propertyName, propertyValue);
    }/*from   w  ww .j  a  v a 2s  .  c  o  m*/

    if (!SecurityUtils.hasAttributeValueRole(getServletContext(), request)) {
        for (String key : filterOutKeys) {
            sysProps.remove(key);
        }
    }

    systemInformation.setSystemProperties(sysProps);

    ModelAndView mv = new ModelAndView(getViewName());
    mv.addObject("systemInformation", systemInformation);
    mv.addObject("runtime", getRuntimeInfoAccessor().getRuntimeInformation());
    mv.addObject("collectionPeriod", getCollectionPeriod());
    return mv;
}

From source file:io.symcpe.hendrix.api.dao.TestRulesManager.java

@BeforeClass
public static void beforeClass() throws Exception {
    java.util.logging.Logger.getLogger("org.hibernate").setLevel(Level.OFF);
    Properties config = new Properties(System.getProperties());
    File db = new File(TARGET_RULES_DB);
    if (db.exists()) {
        FileUtils.deleteDirectory(db);//from  ww  w.  j av  a2 s  . c  o m
    }
    config.setProperty("javax.persistence.jdbc.url", CONNECTION_STRING);
    try {
        emf = Persistence.createEntityManagerFactory("hendrix", config);
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }

    EntityManager em = emf.createEntityManager();

    Tenant tenant = new Tenant();
    tenant.setTenant_id(TENANT_ID_1);
    tenant.setTenant_name(TEST_TENANT);
    TenantManager.getInstance().createTenant(em, tenant);

    tenant = new Tenant();
    tenant.setTenant_id(TENANT_ID_2);
    tenant.setTenant_name(TEST_TENANT);
    TenantManager.getInstance().createTenant(em, tenant);

    tenant = new Tenant();
    tenant.setTenant_id(TENANT_ID_3);
    tenant.setTenant_name(TEST_TENANT);
    TenantManager.getInstance().createTenant(em, tenant);

    tenant = new Tenant();
    tenant.setTenant_id(TENANT_ID_5);
    tenant.setTenant_name(TEST_TENANT);
    TenantManager.getInstance().createTenant(em, tenant);

    em.close();
}

From source file:com.streamsets.datacollector.execution.dagger.TestPipelineManagerModule.java

@After
public void tearDown() throws Exception {
    File f = new File(System.getProperty(RuntimeModule.SDC_PROPERTY_PREFIX + RuntimeInfo.DATA_DIR));
    FileUtils.deleteDirectory(f);/*  www  .  j a v  a2 s.c o m*/
    System.getProperties().remove(RuntimeModule.SDC_PROPERTY_PREFIX + RuntimeInfo.DATA_DIR);
}

From source file:ch.cyberduck.core.cryptomator.B2LargeUploadServiceTest.java

@Test
public void testWrite() throws Exception {
    // 5L * 1024L * 1024L
    final Host host = new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(), new Credentials(
            System.getProperties().getProperty("b2.user"), System.getProperties().getProperty("b2.key")));
    final B2Session session = new B2Session(host);
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path home = new Path("/test-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
    final CryptoVault cryptomator = new CryptoVault(
            new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)),
            new DisabledPasswordStore());
    final Path vault = cryptomator.create(session, null, new VaultCredentials("test"));
    session.withRegistry(/*from w w w. ja  v  a 2 s .c o  m*/
            new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    final CryptoUploadFeature m = new CryptoUploadFeature<>(session,
            new B2LargeUploadService(session, new B2WriteFeature(session), 5242880L, 5),
            new B2WriteFeature(session), cryptomator);
    final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    final byte[] content = RandomUtils.nextBytes(5242885);
    IOUtils.write(content, local.getOutputStream(false));
    final TransferStatus writeStatus = new TransferStatus();
    final Cryptor cryptor = cryptomator.getCryptor();
    final FileHeader header = cryptor.fileHeaderCryptor().create();
    writeStatus.setHeader(cryptor.fileHeaderCryptor().encryptHeader(header));
    writeStatus.setLength(content.length);
    final Path test = new Path(vault, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.file));
    m.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(),
            writeStatus, null);
    assertEquals((long) content.length, writeStatus.getOffset(), 0L);
    assertTrue(writeStatus.isComplete());
    assertTrue(new CryptoFindFeature(session, new B2FindFeature(session), cryptomator).find(test));
    assertEquals(content.length,
            new CryptoAttributesFeature(session, new B2AttributesFinderFeature(session), cryptomator).find(test)
                    .getSize());
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
    final TransferStatus readStatus = new TransferStatus().length(content.length);
    final InputStream in = new CryptoReadFeature(session, new B2ReadFeature(session), cryptomator).read(test,
            readStatus, new DisabledConnectionCallback());
    new StreamCopier(readStatus, readStatus).transfer(in, buffer);
    assertArrayEquals(content, buffer.toByteArray());
    new CryptoDeleteFeature(session, new B2DeleteFeature(session), cryptomator)
            .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    local.delete();
    session.close();
}

From source file:ntpgraphic.PieChart.java

public static void NTPClient(String[] servers) {

    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 w w .  j  a  v a2s  .  c om*/
    }

    Promedio = 0;
    Cant = 0;
    int j = 1;
    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, j++);
            } 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));
}