本文整理了Java中java.util.Hashtable
类的一些代码示例,展示了Hashtable
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hashtable
类的具体详情如下:
包路径:java.util.Hashtable
类名称:Hashtable
[英]A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale_lib.NonBlockingHashMap. The undocumented iteration order is different from Hashtable, as is the undocumented (lack of) synchronization. Programs that rely on this undocumented behavior may break. Otherwise this solution should be completely compatible, including the serialized forms. This version is not synchronized, and correctly operates as a thread-safe Hashtable. It does not provide the same ordering guarantees as calling synchronized methods will. The old Hashtable's methods were synchronized and would provide ordering. This behavior is not part of Hashtable's spec. This version's methods are not synchronized and will not force the same Java Memory Model orderings.
[中]JDK1的插件替代品。5爪哇。util。哈希表。此版本基于org。克利夫。高标度库。非封锁地图。未记录的迭代顺序与哈希表不同,未记录的(缺少)同步也是如此依赖此未记录行为的程序可能会中断。否则,此解决方案应完全兼容,包括序列化表单。此版本未同步,并且作为线程安全哈希表正确运行。它不提供与调用同步方法相同的排序保证。旧哈希表的方法是同步的,可以提供排序。此行为不是Hashtable规范的一部分。此版本的方法不同步,不会强制相同的Java内存模型排序。
代码示例来源:origin: pentaho/pentaho-kettle
public String[] getUsedFields() {
Hashtable<String, String> fields = new Hashtable<String, String>();
getUsedFields( fields );
String[] retval = new String[fields.size()];
Enumeration<String> keys = fields.keys();
int i = 0;
while ( keys.hasMoreElements() ) {
retval[i] = keys.nextElement();
i++;
}
return retval;
}
代码示例来源:origin: stackoverflow.com
this.password = password;
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", mailhost);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.quitwait", "false");
return new PasswordAuthentication(user, password);
MimeMessage message = new MimeMessage(session);
DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));
message.setSender(new InternetAddress(sender));
message.setSubject(subject);
message.setDataHandler(handler);
if (recipients.indexOf(',') > 0)
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
else
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
Transport.send(message);
}catch(Exception e){
代码示例来源:origin: stackoverflow.com
private static String getPostParamString(Hashtable<String, String> params) {
if(params.size() == 0)
return "";
StringBuffer buf = new StringBuffer();
Enumeration<String> keys = params.keys();
while(keys.hasMoreElements()) {
buf.append(buf.length() == 0 ? "" : "&");
String key = keys.nextElement();
buf.append(key).append("=").append(params.get(key));
}
return buf.toString();
}
代码示例来源:origin: redisson/redisson
/**
* Undocumented method. Do not use; internal-use only.
*
* @param name the name of <code>$cflow</code> variable
*/
public Object[] lookupCflow(String name) {
if (cflow == null)
cflow = new Hashtable();
return (Object[])cflow.get(name);
}
代码示例来源:origin: stackoverflow.com
Hashtable<Integer, String> table = ...
Enumeration<Integer> enumKey = table.keys();
while(enumKey.hasMoreElements()) {
Integer key = enumKey.nextElement();
String val = table.get(key);
if(key==0 && val.equals("0"))
table.remove(key);
}
代码示例来源:origin: log4j/log4j
public SortedKeyEnumeration(Hashtable ht) {
Enumeration f = ht.keys();
Vector keys = new Vector(ht.size());
for (int i, last = 0; f.hasMoreElements(); ++last) {
String key = (String) f.nextElement();
for (i = 0; i < last; ++i) {
String s = (String) keys.get(i);
if (key.compareTo(s) <= 0) break;
}
keys.add(i, key);
}
e = keys.elements();
}
代码示例来源:origin: stackoverflow.com
Map<String, String> ldapContent = new HashMap<String, String>();
Properties properties = new Properties();
properties.load(new FileInputStream("data.properties"));
for (String key : properties.stringPropertyNames()) {
ldapContent.put(key, properties.get(key).toString());
}
代码示例来源:origin: stackoverflow.com
public static void loadPropertiesAndParse() {
Properties props = new Properties();
String propsFilename = "path_to_props_file";
FileInputStream in = new FileInputStream(propsFilename);
props.load(in);
Enumeration en = props.keys();
while (en.hasMoreElements()) {
String tmpValue = (String) en.nextElement();
String path = tmpValue.substring(0, tmpValue.lastIndexOf(File.separator)); // Get the path
String filename = tmpValue.substring(tmpValue.lastIndexOf(File.separator) + 1, tmpValue.length()); // Get the filename
}
}
代码示例来源:origin: pentaho/pentaho-kettle
Properties properties = new Properties();
properties.load( new FileInputStream( entry ) );
files.put( filename, properties );
directories = new Hashtable<String, Integer>( files.size() );
locales = new Hashtable<String, Boolean>( 10 );
for ( String filename : files.keySet() ) {
String path = getPath( filename );
Integer num = directories.get( path );
if ( num != null ) {
num = Integer.valueOf( num.intValue() + 1 );
num = Integer.valueOf( 1 );
directories.put( path, num );
locales.put( locale, Boolean.TRUE );
代码示例来源:origin: log4j/log4j
Hashtable filters = new Hashtable();
Enumeration e = props.keys();
String name = "";
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
if (key.startsWith(filterPrefix)) {
int dotIdx = key.indexOf('.', fIdx);
name = key.substring(dotIdx+1);
Vector filterOpts = (Vector) filters.get(filterKey);
if (filterOpts == null) {
filterOpts = new Vector();
filters.put(filterKey, filterOpts);
while (g.hasMoreElements()) {
String key = (String) g.nextElement();
String clazz = props.getProperty(key);
if (clazz != null) {
LogLog.debug("Filter key: ["+key+"] class: ["+props.getProperty(key) +"] props: "+filters.get(key));
Filter filter = (Filter) OptionConverter.instantiateByClassName(clazz, Filter.class, null);
if (filter != null) {
PropertySetter propSetter = new PropertySetter(filter);
Vector v = (Vector)filters.get(key);
Enumeration filterProps = v.elements();
while (filterProps.hasMoreElements()) {
NameValue kv = (NameValue)filterProps.nextElement();
代码示例来源:origin: wildfly/wildfly
orbProp = new Properties();
final Enumeration envProp = env.keys();
while (envProp.hasMoreElements()) {
String key = (String) envProp.nextElement();
Object val = env.get(key);
if (val instanceof String) {
orbProp.put(key, val);
final Enumeration mainProps = orbProperties.keys();
while (mainProps.hasMoreElements()) {
String key = (String) mainProps.nextElement();
Object val = orbProperties.get(key);
Object applet = env.get(Context.APPLET);
if (applet != null) {
代码示例来源:origin: h2oai/h2o-2
int dot = f.getCanonicalPath().lastIndexOf( '.' );
if ( dot >= 0 )
mime = (String)theMimeTypes.get( f.getCanonicalPath().substring( dot + 1 ).toLowerCase());
if ( mime == null )
mime = MIME_DEFAULT_BINARY;
String range = header.getProperty( "range" );
if ( range != null )
FileInputStream fis = new FileInputStream( f ) {
public int available() throws IOException { return (int)dataLen; }
};
try {
fis.skip( startFrom );
res.addHeader( "Content-Range", "bytes " + startFrom + "-" + endAt + "/" + fileLen);
res.addHeader( "ETag", etag);
} finally { fis.close(); }
if (etag.equals(header.getProperty("if-none-match")))
res = new Response( HTTP_NOTMODIFIED, mime, "");
else
代码示例来源:origin: apache/shiro
/**
* Create a new JNDI initial context. Invoked by {@link #execute}.
* <p>The default implementation use this template's environment settings.
* Can be subclassed for custom contexts, e.g. for testing.
*
* @return the initial Context instance
* @throws NamingException in case of initialization errors
*/
@SuppressWarnings({"unchecked"})
protected Context createInitialContext() throws NamingException {
Properties env = getEnvironment();
Hashtable icEnv = null;
if (env != null) {
icEnv = new Hashtable(env.size());
for (Enumeration en = env.propertyNames(); en.hasMoreElements();) {
String key = (String) en.nextElement();
icEnv.put(key, env.getProperty(key));
}
}
return new InitialContext(icEnv);
}
代码示例来源:origin: pentaho/pentaho-kettle
/**
* @return all the extra options that are set to be used for the database URL
*/
@Override
public Map<String, String> getExtraOptions() {
Map<String, String> map = new Hashtable<String, String>();
for ( Enumeration<Object> keys = attributes.keys(); keys.hasMoreElements(); ) {
String attribute = (String) keys.nextElement();
if ( attribute.startsWith( ATTRIBUTE_PREFIX_EXTRA_OPTION ) ) {
String value = attributes.getProperty( attribute, "" );
// Add to the map...
map.put( attribute.substring( ATTRIBUTE_PREFIX_EXTRA_OPTION.length() ), value );
}
}
return map;
}
代码示例来源:origin: robovm/robovm
/**
* Reset configuration.
*
* <p>All handlers are closed and removed from any named loggers. All loggers'
* level is set to null, except the root logger's level is set to
* {@code Level.INFO}.
*/
public synchronized void reset() {
checkAccess();
props = new Properties();
Enumeration<String> names = getLoggerNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
Logger logger = getLogger(name);
if (logger != null) {
logger.reset();
}
}
Logger root = loggers.get("");
if (root != null) {
root.setLevel(Level.INFO);
}
}
代码示例来源:origin: robovm/robovm
if ((null == v) || (v.size() < 1))
return false;
for (int i = 0; i < v.size(); i++)
Hashtable subhash = (Hashtable) v.elementAt(i);
for (Enumeration keys = subhash.keys();
keys.hasMoreElements();
Object key = keys.nextElement();
try
node.setAttribute("name", keyStr.substring(0, keyStr.indexOf("-")));
node.setAttribute("desc", keyStr.substring(keyStr.indexOf("-") + 1));
node.appendChild(factory.createTextNode((String)subhash.get(keyStr)));
container.appendChild(node);
代码示例来源:origin: log4j/log4j
v = new Vector();
Enumeration enumeration = ht.keys();
while(enumeration.hasMoreElements() && (misses <= 4)) {
Thread t = (Thread) enumeration.nextElement();
if(t.isAlive()) {
misses++;
} else {
misses = 0;
v.addElement(t);
int size = v.size();
for(int i = 0; i < size; i++) {
Thread t = (Thread) v.elementAt(i);
LogLog.debug("Lazy NDC removal for thread [" + t.getName() + "] ("+
ht.size() + ").");
ht.remove(t);
代码示例来源:origin: stackoverflow.com
Properties prop = new Properties();
InputStream input = SentmailAttachFile.class.getResourceAsStream("/Sendmail.properties");
prop.load(input);
String receiver = prop.getProperty("MAILADDRESS");
String mailCC = prop.getProperty("MAILCC");
Properties props = new Properties();
props.put("mail.smtp.host" , host);
props.put("mail.smtp.auth" , "true" );
props.put("mail.transport.protocol", "smtp");
Session ss = Session.getInstance(props,null);
MimeMessage ms = new MimeMessage(ss);
ms.addRecipient(Message.RecipientType.TO,new InternetAddress(receiver));
ms.addRecipient(Message.RecipientType.CC, new InternetAddress(mailCC));
代码示例来源:origin: stackoverflow.com
session = jsch.getSession(SFTPUSER, SFTPHOST, SFTPPORT);
session.setPassword(SFTPPASS);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
channelSftp.cd(SFTPWORKINGDIR);
File f = new File(fileName);
channelSftp.put(new FileInputStream(f), f.getName());
log.info("File transfered successfully to host.");
} catch (Exception ex) {
代码示例来源:origin: robovm/robovm
/**
* Return an array containing the names of all currently defined
* configuration attributes. If there are no such attributes, a zero
* length array is returned.
*/
public String[] getAttributeNames() {
Vector names = new Vector();
Enumeration keys = attributes.keys();
while (keys.hasMoreElements()) {
names.addElement((String) keys.nextElement());
}
String results[] = new String[names.size()];
for (int i = 0; i < results.length; i++) {
results[i] = (String) names.elementAt(i);
}
return (results);
}
内容来源于网络,如有侵权,请联系作者删除!