Example usage for java.util Properties put

List of usage examples for java.util Properties put

Introduction

In this page you can find the example usage for java.util Properties put.

Prototype

@Override
    public synchronized Object put(Object key, Object value) 

Source Link

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    byte[] b = new byte[1];
    Properties systemSettings = System.getProperties();
    systemSettings.put("http.proxyHost", "proxy.mydomain.local");
    systemSettings.put("http.proxyPort", "80");

    Authenticator.setDefault(new Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("mydomain\\username", "password".toCharArray());
        }//from   ww  w .  ja  v a  2  s . c o  m
    });

    URL u = new URL("http://www.google.com");
    HttpURLConnection con = (HttpURLConnection) u.openConnection();
    DataInputStream di = new DataInputStream(con.getInputStream());
    while (-1 != di.read(b, 0, 1)) {
        System.out.print(new String(b));
    }
}

From source file:Main.java

public static void main(String s[]) throws Exception {
    try {//from   w w  w  . jav  a  2s. co m
        Properties systemSettings = System.getProperties();
        systemSettings.put("proxySet", "true");
        systemSettings.put("http.proxyHost", "proxy.mycompany.local");
        systemSettings.put("http.proxyPort", "80");

        URL u = new URL("http://www.java.com");
        HttpURLConnection con = (HttpURLConnection) u.openConnection();
        sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
        String encodedUserPwd = encoder.encode("domain\\username:password".getBytes());
        con.setRequestProperty("Proxy-Authorization", "Basic " + encodedUserPwd);
        con.setRequestMethod("HEAD");
        System.out.println(con.getResponseCode() + " : " + con.getResponseMessage());
        System.out.println(con.getResponseCode() == HttpURLConnection.HTTP_OK);
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(false);
    }
}

From source file:com.counter.TestServer.java

public static void main(String[] args) throws Exception {
    Server server = new Server(8080);

    Context context = new Context();

    ServletHolder servletHolder = new ServletHolder();

    servletHolder.setInitOrder(1);/*from w  ww.  ja  va2  s .c om*/
    servletHolder.setServlet(new CXFServlet());
    servletHolder.setName("CXFServlet");
    servletHolder.setDisplayName("CXF Servlet");
    context.addServlet(servletHolder, "/*");
    context.addEventListener(new ContextLoaderListener());
    Properties initParams = new Properties();
    initParams.put("contextConfigLocation", "classpath:/beans.xml,classpath:/factorybeans.xml");
    context.setInitParams(initParams);
    server.addHandler(context);
    server.start();
}

From source file:batch.processing.usage.chunk.hibernate.BatchChunkHibernateProcessingUsage.java

/**
 * @param args the command line arguments
 *///from ww  w . j  av a 2  s.c o m
public static void main(String[] args) {
    try {
        Properties jobParameters = new Properties();
        jobParameters.put("nomeArquivo", "OpLm.csv");
        BatchProcess launcher = BatchApplication.createExecutionProcess("chunkHibernateExample", jobParameters);
        BatchExecution execution = launcher.start();
        while (execution.getStatus() != Status.COMPLETED) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException ex) {

            }
        }
        System.out.println(execution.toString());
    } catch (Exception ex) {
        LOG.error(ex);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Properties prop = new Properties();

    prop.setProperty("Chapter Count", "200");
    prop.put("Tutorial Count", "1500");
    prop.put("tutorial", "java2s.com");

    // print the list
    System.out.println(prop);/*from  w ww.j  a  v  a  2 s .  c om*/

    // store the properties list in an output stream
    prop.store(System.out, "Main");

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Properties prop = new Properties();

    prop.setProperty("Chapter Count", "200");
    prop.put("Tutorial Count", "1500");
    prop.put("tutorial", "java2s.com");

    // print the list
    System.out.println(prop);/*from w w  w .  j a  v  a2s. c om*/

    // change the properties
    prop.setProperty("Tutorial Count", "15");
    prop.setProperty("Chapter Count", "500");

    // print the list
    System.out.println(prop);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Properties prop = new Properties();
    PrintWriter writer = new PrintWriter(System.out);

    prop.put("Chapter Count", "200");
    prop.put("Tutorial Count", "150");
    prop.put("tutorial", "java2s.com");
    prop.put("Runnable", "true");

    // print the list with a PrintWriter object
    prop.list(writer);//from w w w  .  j  a v a  2 s .c  o  m

    // flush the stream
    writer.flush();

}

From source file:core.Main.java

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

    try {/*from  w  ww  . j  a va2  s  . c o  m*/
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            /*if ("Metal".equals(info.getName())) {
             javax.swing.UIManager.setLookAndFeel(info.getClassName());
             break;
             }*/
            Properties props = new Properties();
            props.put("logoString", "my company");
            HiFiLookAndFeel.setCurrentTheme(props);
            //  UIManager.setLookAndFeel("com.jtattoo.plaf.smart.SmartLookAndFeel");
            //        UIManager.setLookAndFeel("com.jtattoo.plaf.acryl.AcrylLookAndFeel");
            // UIManager.setLookAndFeel("com.jtattoo.plaf.aero.AeroLookAndFeel");
            UIManager.setLookAndFeel("com.jtattoo.plaf.aluminium.AluminiumLookAndFeel");
            //  UIManager.setLookAndFeel("com.jtattoo.plaf.bernstein.BernsteinLookAndFeel");
            //     UIManager.setLookAndFeel("com.jtattoo.plaf.fast.FastLookAndFeel");
            //   UIManager.setLookAndFeel("com.jtattoo.plaf.graphite.GraphiteLookAndFeel");
            //   UIManager.setLookAndFeel("com.jtattoo.plaf.hifi.HiFiLookAndFeel");
            //  UIManager.setLookAndFeel("com.jtattoo.plaf.luna.LunaLookAndFeel");
            // UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");
            //      UIManager.setLookAndFeel("com.jtattoo.plaf.mint.MintLookAndFeel");
            //  UIManager.setLookAndFeel("com.jtattoo.plaf.noire.NoireLookAndFeel");

        }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
            | javax.swing.UnsupportedLookAndFeelException ex) {

    }
    MainFrame frame = new MainFrame();
    frame.setVisible(true);
    frame.setResizable(false);
}

From source file:JdbcConnect.java

public static void main(String[] args) throws Exception {
    Connection conn1 = null;//from   w  w  w.  j  a  va2s  .c  o  m
    Connection conn2 = null;
    Connection conn3 = null;

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    String jdbcUrl = "jdbc:odbc:authors";

    String user = "yourName";
    String pwd = "mypwd";

    conn1 = DriverManager.getConnection(jdbcUrl);
    if (conn1 != null) {
        System.out.println("Connection 1 successful!");
    }
    Properties prop = new Properties();
    prop.put("user", user);
    prop.put("password", pwd);

    conn2 = DriverManager.getConnection(jdbcUrl, prop);
    if (conn2 != null) {
        System.out.println("Connection 2 successful!");
    }
    conn3 = DriverManager.getConnection(jdbcUrl, user, pwd);
    if (conn3 != null) {
        System.out.println("Connection 3 successful!");
    }
    conn1.close();
    conn2.close();
    conn3.close();
    if (conn1.isClosed()) {
        System.out.println("Connection 1 is closed");
    }

    if (conn2.isClosed()) {
        System.out.println("Connection 2 is closed");
    }
    if (conn3.isClosed()) {
        System.out.println("Connection 3 is closed");
    }

    conn1.close();
    conn2.close();
    conn3.close();

}

From source file:MailExample.java

public static void main(String args[]) throws Exception {
    if (args.length != 3) {
        System.err.println("Usage: java MailExample host from to");
        System.exit(-1);/*from w  ww  . j  av  a2s.  c  o  m*/
    }

    String host = args[0];
    String from = args[1];
    String to = args[2];

    // Get system properties
    Properties props = System.getProperties();

    // Setup mail server
    props.put("mail.smtp.host", host);

    // Get session
    Session session = Session.getDefaultInstance(props, null);

    // Define message
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    message.setSubject("The Subject");
    message.setText("The Message");

    // Send message
    Transport.send(message);
}