List of usage examples for java.util Hashtable Hashtable
public Hashtable()
From source file:Main.java
public static void main(String args[]) throws Exception { Hashtable<String, String> env = new Hashtable<String, String>(); env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory"); env.put("java.naming.provider.url", "dns://123.123.123.123/"); String dns_attributes[] = { "MX", "A", "HINFO" }; DirContext ctx = new InitialDirContext(env); Attributes attrsl = ctx.getAttributes("http://www.yourserver.com", dns_attributes); for (int z = 0; z < dns_attributes.length; z++) { Attribute attr = attrsl.get(dns_attributes[z]); if (attr != null) { System.out.print(dns_attributes[z] + ": "); for (Enumeration vals = attr.getAll(); vals.hasMoreElements();) { System.out.println(vals.nextElement()); }//w ww. j a v a2s. c o m } } }
From source file:Main.java
public static void main(String[] args) { HashMap<String, String> hMap = new HashMap<String, String>(); hMap.put("1", "One"); hMap.put("2", "Two"); hMap.put("3", "Three"); Hashtable<String, String> ht = new Hashtable<String, String>(); ht.put("1", "REPLACED !!"); ht.put("4", "Four"); Enumeration e = ht.elements(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); }//from w ww . j ava 2 s . co m ht.putAll(hMap); e = ht.elements(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); } }
From source file:PlanetDiameters.java
public static void main(String args[]) { String names[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto" }; float diameters[] = { 4800f, 12103.6f, 12756.3f, 6794f, 142984f, 120536f, 51118f, 49532f, 2274f }; Hashtable hash = new Hashtable(); for (int i = 0, n = names.length; i < n; i++) { hash.put(names[i], new Float(diameters[i])); }// ww w .ja v a 2 s . c o m Enumeration e = hash.keys(); Object obj; while (e.hasMoreElements()) { obj = e.nextElement(); System.out.println(obj + ": " + hash.get(obj)); } }
From source file:MainClass.java
public static void main(String args[]) throws IOException { Hashtable map = new Hashtable(); FileReader fr = new FileReader(args[0]); BufferedReader br = new BufferedReader(fr); String line;/*from ww w . j av a 2 s.co m*/ while ((line = br.readLine()) != null) { processLine(line, map); } Enumeration e = map.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); System.out.println(key + " : " + map.get(key)); } }
From source file:WordCount.java
public static void main(String args[]) throws IOException { Hashtable map = new Hashtable(); FileReader fr = new FileReader(args[0]); BufferedReader br = new BufferedReader(fr); String line;/*w w w.j av a2 s .c o m*/ while ((line = br.readLine()) != null) { processLine(line, map); } Enumeration e = map.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); System.out.println(key + " : " + map.get(key)); } }
From source file:Rename.java
public static void main(String[] args) throws Exception { String initialContextString = "/"; if (args.length < 2) { System.out.println("Useage: java Rename filename1 filename2"); System.exit(-1);// w w w . j a va2 s .c o m } Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put(Context.PROVIDER_URL, "file:" + initialContextString); Context initCtx = new InitialContext(env); System.out.println("Renaming " + args[0] + " to " + args[1]); initCtx.rename(args[0], args[1]); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String url = "ldap://localhost/o=JNDITutorial"; Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, url); DirContext ctx = new InitialDirContext(env); String[] attrIDs = { "sn", "number", "value", "mail" }; Attributes answer = ctx.getAttributes("cn=yourName, ou=People", attrIDs); NamingEnumeration e = answer.getAll(); while (e.hasMore()) { Attribute attr = (Attribute) e.next(); System.out.println(attr.getID()); }/*from w w w . j a va 2s.com*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "YourURL"); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, "userDN"); env.put(Context.SECURITY_CREDENTIALS, "secret"); EventContext ctx = (EventContext) (new InitialContext(env).lookup("ou=People")); NamingListener listener = new SampleNCListener(); ctx.addNamingListener("cn=John", EventContext.ONELEVEL_SCOPE, listener); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String url = "ldap://localhost/o=JNDITutorial"; Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, url); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, "userDN"); env.put(Context.SECURITY_CREDENTIALS, "secret"); LdapContext ctx = new InitialLdapContext(env, null); NamingEnumeration answer = ctx.search("ou=People", "(cn=*)", null); System.out.println(ctx.getResponseControls()); while (answer.hasMore()) { SearchResult si = (SearchResult) answer.next(); if (si instanceof HasControls) { System.out.println(((HasControls) si).getControls()); }/*from ww w .j ava2s . com*/ } System.out.println(ctx.getResponseControls()); }
From source file:Main.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Wrapper.class); Wrapper wrapper = new Wrapper(); Hashtable<String, String> hashtable = new Hashtable<String, String>(); hashtable.put("foo", "A"); hashtable.put("bar", "B"); wrapper.setHashtable(hashtable);/*from w w w . j av a2s. c om*/ System.out.println(objectToXml(jc, wrapper)); }