Example usage for java.lang System setProperty

List of usage examples for java.lang System setProperty

Introduction

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

Prototype

public static String setProperty(String key, String value) 

Source Link

Document

Sets the system property indicated by the specified key.

Usage

From source file:Main.java

public static void main(String[] args) {
    System.setProperty("java.security.policy", "file:/C:/java.policy");

    SecurityManager sm = new Main();

    System.setSecurityManager(sm);

    // check if accepting access for thread group is enabled
    sm.checkAccess(new ThreadGroup("example"));

    System.out.println("Allowed!");
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    System.setProperty("java.net.useSystemProxies", "true");
    List l = ProxySelector.getDefault().select(new URI("http://www.yahoo.com/"));

    for (Iterator iter = l.iterator(); iter.hasNext();) {
        Proxy proxy = (Proxy) iter.next();
        System.out.println("proxy hostname : " + proxy.type());
        InetSocketAddress addr = (InetSocketAddress) proxy.address();
        if (addr == null) {
            System.out.println("No Proxy");
        } else {//from  w w  w.j  a va2  s.c  om
            System.out.println("proxy hostname : " + addr.getHostName());
            System.out.println("proxy port : " + addr.getPort());
        }
    }
}

From source file:Main.java

public static void main(String[] args) {
    System.setProperty("java.security.policy", "file:/C:/java.policy");

    SecurityManager sm = new Main();

    System.setSecurityManager(sm);

    sm.checkPackageDefinition("java2s.com");

    System.out.println("Allowed!");
}

From source file:Main.java

public static void main(String[] args) {
    AccessControlContext con = AccessController.getContext();

    System.setProperty("java.security.policy", "file:/C:/java.policy");

    SecurityManager sm = new Main();

    System.setSecurityManager(sm);

    sm.checkPermission(new FilePermission("test.txt", "read,write"), con);

    System.out.println("Allowed!");
}

From source file:Main.java

public static void main(String[] args) {
    System.setProperty("java.security.policy", "file:/C:/java.policy");

    SecurityManager sm = new Main();

    System.setSecurityManager(sm);

    sm.checkMemberAccess(Main.class, Member.PUBLIC);

    System.out.println("Allowed!");
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {

    System.setProperty("javax.net.ssl.trustStore", "clienttrust");
    SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    Socket s = ssf.createSocket("127.0.0.1", 8888);

    OutputStream outs = s.getOutputStream();
    PrintStream out = new PrintStream(outs);
    InputStream ins = s.getInputStream();
    BufferedReader in = new BufferedReader(new InputStreamReader(ins));

    out.println("Hi,How are u!");
    out.println("");
    String line = null;/*from w w w .j  av  a2s. c o  m*/
    while ((line = in.readLine()) != null) {
        System.out.println(line);
    }

    in.close();
    out.close();
}

From source file:XMLTransform.java

public static void main(String[] args) throws Exception {
    System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
    SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
    XMLReader reader = parser.getXMLReader();
    TransformerFactory factory = TransformerFactory.newInstance();
    System.out.println(factory);// www .  j  a  v  a 2  s. c o  m
    Transformer transformer = factory.newTransformer(new StreamSource("./xsl/books-sql.xsl"));
    transformer.setParameter("user", "root");
    transformer.setParameter("password", "123456");
    transformer.transform(new StreamSource("./xml/books.xml"), new StreamResult(System.out));
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    FileOutputStream fouts = null;
    System.setProperty("javax.net.ssl.trustStore", "clienttrust");
    SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    Socket s = ssf.createSocket("127.0.0.1", 5432);

    OutputStream outs = s.getOutputStream();
    PrintStream out = new PrintStream(outs);
    InputStream ins = s.getInputStream();
    BufferedReader in = new BufferedReader(new InputStreamReader(ins));

    out.println(args[0]);/*from w  ww . ja v a 2s. c o  m*/
    fouts = new FileOutputStream("result.html");
    //  fouts = new FileOutputStream("result.gif");
    int kk;
    while ((kk = ins.read()) != -1) {
        fouts.write(kk);
    }
    in.close();
    fouts.close();
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    System.setProperty("javax.net.ssl.trustStore", "clienttrust");

    SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    Socket s = ssf.createSocket("127.0.0.1", 5432);

    SSLSession session = ((SSLSocket) s).getSession();
    Certificate[] cchain = session.getPeerCertificates();
    System.out.println("The Certificates used by peer");
    for (int i = 0; i < cchain.length; i++) {
        System.out.println(((X509Certificate) cchain[i]).getSubjectDN());
    }/*w  w  w.j a  v  a 2s.co m*/
    System.out.println("Peer host is " + session.getPeerHost());
    System.out.println("Cipher is " + session.getCipherSuite());
    System.out.println("Protocol is " + session.getProtocol());
    System.out.println("ID is " + new BigInteger(session.getId()));
    System.out.println("Session created in " + session.getCreationTime());
    System.out.println("Session accessed in " + session.getLastAccessedTime());

    BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
    String x = in.readLine();
    System.out.println(x);
    in.close();

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    System.setProperty("javax.net.ssl.keyStore", "lfkeystore2");
    System.setProperty("javax.net.ssl.keyStorePassword", "wshr.ut");

    SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    ServerSocket ss = ssf.createServerSocket(5432);
    while (true) {
        Socket s = ss.accept();//from w  w w  .  j  a v  a  2s  .  c om
        SSLSession session = ((SSLSocket) s).getSession();
        Certificate[] cchain2 = session.getLocalCertificates();
        for (int i = 0; i < cchain2.length; i++) {
            System.out.println(((X509Certificate) cchain2[i]).getSubjectDN());
        }
        System.out.println("Peer host is " + session.getPeerHost());
        System.out.println("Cipher is " + session.getCipherSuite());
        System.out.println("Protocol is " + session.getProtocol());
        System.out.println("ID is " + new BigInteger(session.getId()));
        System.out.println("Session created in " + session.getCreationTime());
        System.out.println("Session accessed in " + session.getLastAccessedTime());

        PrintStream out = new PrintStream(s.getOutputStream());
        out.println("Hi");
        out.close();
        s.close();
    }

}